Created
October 26, 2013 11:58
-
-
Save jjw/7168671 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#encoding utf-8 | |
require 'rubygems' | |
# this searches up the directory path to find Gemfile: | |
#source 'https://rubygems.org' | |
#gem 'mongo_mapper', :git => "git://github.com/mongomapper/mongomapper.git", :tag => "v0.13.0.beta2" | |
#gem 'bson_ext' | |
#gem 'minitest' | |
# and hacks the ruby loadpath to make gems available. | |
require 'bundler/setup' | |
gem 'minitest' | |
require 'minitest/autorun' | |
require 'mongo_mapper' | |
MongoMapper.connection = Mongo::Connection.new('localhost', 27017) | |
MongoMapper.database = "e360-test" | |
# Monkey Patch to solve issue https://github.com/jnunemaker/mongomapper/issues/507 | |
# this patch is required to trigger the bug in 550. | |
module MongoMapper | |
module Plugins | |
module Querying | |
private | |
def save_to_collection(options={}) | |
@_new = false | |
collection.save(to_mongo, :w => options[:safe] ? 1 : 0) | |
end | |
end | |
end | |
end | |
require 'yaml'; Fixtures = YAML::load(<<EOS) | |
--- | |
feedback: | |
- | |
feedback: [1,1,2,3,5,8,11] | |
- | |
feedback: [3, 4, 2, 3, 0, 3, 0] | |
- | |
feedback: [1, 3, 3, 1, 1, 3, 3] | |
- | |
feedback: [2, 4, 4, 2, 5, 4, 5] | |
- | |
feedback: [1, 5, 3, 4, 4, 3, 5] | |
EOS | |
class Feedback | |
include MongoMapper::EmbeddedDocument | |
key :feedback, Array | |
end | |
class Opinion | |
include MongoMapper::Document | |
many :feedback | |
belongs_to :report | |
def complete?() true; end | |
end | |
class Report | |
include MongoMapper::Document | |
many :opinions | |
# you have to call complete? to trigger the bug | |
def complete?() | |
self.opinions.all?(&:complete?).tap{|x| STDERR.puts "WTF: #{x.inspect}"; } | |
end | |
end | |
describe Report do | |
it 'triggers a bug' do | |
Opinion.destroy_all; Report.destroy_all | |
@feedback = Fixtures['feedback'].collect{|f| Feedback.new(f);} | |
@opinions = (1..3).collect { |i| Opinion.create(feedback:@feedback[i-1..i+1])} | |
@report = Report.new(opinions: @opinions) | |
assert @report.save # works fine | |
# trigger bug | |
@report.save if @report.complete? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment