spec/lib/associations_spec.rb in api_resource-0.6.1 vs spec/lib/associations_spec.rb in api_resource-0.6.2

- old
+ new

@@ -258,10 +258,25 @@ ) ap.scope?("test").should be_false ap.test.should eql("testval") end + + it "should include the foreign_key_id when saving" do + tr = TestResource.new + tr.belongs_to_object_id = 4 + hsh = tr.serializable_hash + hsh[:belongs_to_object_id].should eql(4) + end + + it "should serialize the foreign_key_id when saving if it is updated" do + TestResource.connection + tr = TestResource.find(1) + tr.belongs_to_object_id = 5 + hsh = tr.serializable_hash + hsh[:belongs_to_object_id].should eql(5) + end end describe "Multi Object Associations" do before(:all) do @@ -340,9 +355,30 @@ "TestResource", BelongsToObject, {:the_element => "/route"} ) ap.remote_path.should eql("/route") + end + + it "should include the foreign_key_id when saving" do + tr = TestResource.new + tr.has_many_object_ids = [4] + hsh = tr.serializable_hash + hsh[:has_many_object_ids].should eql([4]) + end + + it "should serialize the foreign_key_id when saving if it is updated" do + tr = TestResource.find(1) + tr.has_many_object_ids = [5] + hsh = tr.serializable_hash + hsh[:has_many_object_ids].should eql([5]) + end + + it "should not try to load if the foreign key is nil" do + TestResource.connection.expects(:get).returns(:id => 1, :belongs_to_object_id => nil) + tr = TestResource.find(1) + tr.id.should eql(1) + tr.belongs_to_object_id.should be_nil end end end