Skip to content

Commit

Permalink
Adding in passing spec for #1254.
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Sep 17, 2011
1 parent 30cb673 commit 6647743
Showing 1 changed file with 64 additions and 20 deletions.
84 changes: 64 additions & 20 deletions spec/functional/mongoid/relations/referenced/many_to_many_spec.rb
Expand Up @@ -20,6 +20,7 @@

context "when the relations are not polymorphic" do


context "when the inverse relation is not defined" do

let(:person) do
Expand All @@ -46,35 +47,78 @@
context "when the parent is a new record" do

let(:person) do
Person.new
Person.new(:ssn => "423-12-0789")
end

let(:preference) do
Preference.new
end
context "when the child is new" do

before do
person.preferences.send(method, preference)
end
let(:preference) do
Preference.new
end

it "adds the documents to the relation" do
person.preferences.should == [ preference ]
end
before do
person.preferences.send(method, preference)
end

it "sets the foreign key on the relation" do
person.preference_ids.should == [ preference.id ]
end
it "adds the documents to the relation" do
person.preferences.should == [ preference ]
end

it "sets the foreign key on the inverse relation" do
preference.person_ids.should == [ person.id ]
end
it "sets the foreign key on the relation" do
person.preference_ids.should == [ preference.id ]
end

it "does not save the target" do
preference.should be_new
it "sets the foreign key on the inverse relation" do
preference.person_ids.should == [ person.id ]
end

it "does not save the target" do
preference.should be_new
end

it "adds the correct number of documents" do
person.preferences.size.should == 1
end
end

it "adds the correct number of documents" do
person.preferences.size.should == 1
context "when the child is already persisted" do

let!(:persisted) do
Preference.create(:name => "testy")
end

let(:preference) do
Preference.first
end

before do
person.preferences.send(method, preference)
person.save
end

it "adds the documents to the relation" do
person.preferences.should == [ preference ]
end

it "sets the foreign key on the relation" do
person.preference_ids.should == [ preference.id ]
end

it "sets the foreign key on the inverse relation" do
preference.person_ids.should == [ person.id ]
end

it "saves the target" do
preference.should be_persisted
end

it "adds the correct number of documents" do
person.preferences.size.should == 1
end

it "persists the link" do
person.reload.preferences.should eq([ preference ])
end
end
end

Expand Down

0 comments on commit 6647743

Please sign in to comment.