Allow to create association from build_xyz method on an object
This commit is contained in:
parent
3f59065366
commit
80f949d15a
@ -102,6 +102,8 @@ module Cocoon
|
|||||||
private
|
private
|
||||||
|
|
||||||
def create_object_on_non_association(f, association)
|
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}"
|
raise "Association #{association} doesn't exist on #{f.object.class}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -193,14 +193,13 @@ describe Cocoon do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should raise error if cannot reflect on association" do
|
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
|
end
|
||||||
|
|
||||||
it "should create an association if object responds to 'build_association' as singular" do
|
it "should create an association if object responds to 'build_association' as singular" do
|
||||||
pending 'WIP'
|
|
||||||
object = Comment.new
|
object = Comment.new
|
||||||
object.should_receive(:build_custom_item).and_return 'custom'
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user