Allow to create association from build_xyz method on an object

This commit is contained in:
Dmytrii Nagirniak 2012-09-24 18:15:25 +10:00
parent 3f59065366
commit 80f949d15a
2 changed files with 4 additions and 3 deletions

View File

@ -102,6 +102,8 @@ module Cocoon
private
def create_object_on_non_association(f, association)
builder_method = "build_#{association}"
return f.object.send(builder_method) if f.object.respond_to?(builder_method)
raise "Association #{association} doesn't exist on #{f.object.class}"
end

View File

@ -193,14 +193,13 @@ describe Cocoon do
end
it "should raise error if cannot reflect on association" do
expect { @tester.create_object(stub(:object => Comment.new), :not_existing) }.to raise_error /exist/
expect { @tester.create_object(stub(:object => Comment.new), :not_existing) }.to raise_error /association/i
end
it "should create an association if object responds to 'build_association' as singular" do
pending 'WIP'
object = Comment.new
object.should_receive(:build_custom_item).and_return 'custom'
@tester.create_object(stub(:object => Comment.new), :custom_item).should == 'custom'
@tester.create_object(stub(:object => object), :custom_item).should == 'custom'
end
end