From b329665a73d0e3fb7a78b80f5e44bd432ec2aed2 Mon Sep 17 00:00:00 2001 From: jwollert Date: Fri, 18 Oct 2013 15:33:54 +0200 Subject: [PATCH] basic specs for copying associations --- spec/lib/copy_model/copy_model_spec.rb | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/spec/lib/copy_model/copy_model_spec.rb b/spec/lib/copy_model/copy_model_spec.rb index f9eefcf122..030e2f7825 100644 --- a/spec/lib/copy_model/copy_model_spec.rb +++ b/spec/lib/copy_model/copy_model_spec.rb @@ -66,10 +66,9 @@ class Relation3 < Tableless end describe "Copying Models" do + let(:dummy) { CopyDummy.new } describe "copying attributes" do - let(:dummy) { CopyDummy.new } - it "should copy safe attributes" do dummy.safe_attribute1 = "foo" dummy.safe_attribute2 = "bar" @@ -90,4 +89,30 @@ describe "Copying Models" do dummy.unsafe_attribute.should_not == copy.unsafe_attribute end end + + describe "copying associations" do + it "should copy associations, for which there are methods in our model" do + dummy.relation1 = Relation1.new + dummy.relation2 = Relation2.new + + copy = CopyDummy.copy(dummy) + + copy.relation1.should == dummy.relation1 + copy.relation1.should_not == nil + copy.relation2.should == dummy.relation2 + copy.relation2.should_not == nil + end + + it "should not copy associations, for which there are no methods in our model" do + dummy.relation1 = Relation1.new + dummy.relation3 = Relation3.new + + copy = CopyDummy.copy(dummy) + + copy.relation1.should == dummy.relation1 + copy.relation1.should_not == nil + copy.relation3.should_not == dummy.relation3 + copy.relation3.should == nil + end + end end