diff --git a/lib/cocoon/view_helpers.rb b/lib/cocoon/view_helpers.rb index 59e080b..ceff81b 100644 --- a/lib/cocoon/view_helpers.rb +++ b/lib/cocoon/view_helpers.rb @@ -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 diff --git a/spec/cocoon_spec.rb b/spec/cocoon_spec.rb index 57522aa..192a485 100644 --- a/spec/cocoon_spec.rb +++ b/spec/cocoon_spec.rb @@ -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