Created
September 4, 2011 17:40
-
-
Save rainkinz/1193197 to your computer and use it in GitHub Desktop.
Mongoid failing many to many spec
This file contains 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
require 'spec_helper' | |
describe Mongoid::Relations::Referenced::ManyToMany do | |
before(:all) do | |
Mongoid.raise_not_found_error = true | |
end | |
before do | |
[ | |
Person, Preference, Event, Tag, | |
UserAccount, Agent, Account, Business, User, | |
Artwork, Exhibition, Exhibitor | |
].map(&:delete_all) | |
end | |
let(:person) do | |
Person.create | |
end | |
let(:preference) do | |
Preference.new(:name => 'foo', :value => 'bar') | |
end | |
describe "#<<" do | |
it "appends a new document to the relation" do | |
person.preferences.should == [] | |
person.preferences << Preference.new(:name => 'db', :value => 'mongo') | |
person.preferences.size.should == 1 | |
person.preferences.map(&:name).should == ['foo'] | |
end | |
it "appends the existing document to the relation" do | |
person.preferences.should == [] | |
person.preferences << preference | |
person.preferences.size.should == 1 | |
person.preferences.map(&:name).should == ['foo'] | |
end | |
it "appends the document to the relation when ids are used" do | |
person.preference_ids.should == [] | |
person.preference_ids << preference.id | |
person.preference_ids.size.should == 1 | |
person.preference_ids.should == [preference.id] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output running on mongoid master:
Failures:
Mongoid::Relations::Referenced::ManyToMany#<< appends a new document to the relation
Failure/Error: person.preferences.size.should == 1
expected: 1
got: 0 (using ==)
./spec/functional/mongoid/relations/referenced/many_to_many_failing_spec.rb:33:in `block (3 levels) in <top (required)>'
Mongoid::Relations::Referenced::ManyToMany#<< appends the existing document to the relation
Failure/Error: person.preferences.size.should == 1
expected: 1
got: 0 (using ==)
./spec/functional/mongoid/relations/referenced/many_to_many_failing_spec.rb:43:in `block (3 levels) in <top (required)>'
Finished in 0.15422 seconds
3 examples, 2 failures
Failed examples:
rspec ./spec/functional/mongoid/relations/referenced/many_to_many_failing_spec.rb:27 # Mongoid::Relations::Referenced::ManyToMany#<< appends a new document to the relation
rspec ./spec/functional/mongoid/relations/referenced/many_to_many_failing_spec.rb:37 # Mongoid::Relations::Referenced::ManyToMany#<< appends the existing document to the relation