Skip to content

Instantly share code, notes, and snippets.

@rainkinz
Created September 4, 2011 17:40
Show Gist options
  • Save rainkinz/1193197 to your computer and use it in GitHub Desktop.
Save rainkinz/1193197 to your computer and use it in GitHub Desktop.
Mongoid failing many to many spec
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
@rainkinz
Copy link
Author

rainkinz commented Sep 4, 2011

Output running on mongoid master:

Failures:

  1. 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)>'

  2. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment