Allow to build plural transient associations
This commit is contained in:
parent
80f949d15a
commit
bee1a8ba0b
|
@ -102,8 +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)
|
||||
builder_method = %W{build_#{association} build_#{association.to_s.singularize}}.select { |m| f.object.respond_to?(m) }.first
|
||||
return f.object.send(builder_method) if builder_method
|
||||
raise "Association #{association} doesn't exist on #{f.object.class}"
|
||||
end
|
||||
|
||||
|
|
|
@ -201,6 +201,12 @@ describe Cocoon do
|
|||
object.should_receive(:build_custom_item).and_return 'custom'
|
||||
@tester.create_object(stub(:object => object), :custom_item).should == 'custom'
|
||||
end
|
||||
|
||||
it "should create an association if object responds to 'build_association' as plural" do
|
||||
object = Comment.new
|
||||
object.should_receive(:build_custom_item).and_return 'custom'
|
||||
@tester.create_object(stub(:object => object), :custom_items).should == 'custom'
|
||||
end
|
||||
end
|
||||
|
||||
context "get_partial_path" do
|
||||
|
|
Loading…
Reference in New Issue