Merge pull request #53 from CuriousCurmudgeon/master

Options not passed to link_to_add_association when using a block
This commit is contained in:
Nathan Van der Auwera 2012-04-07 14:23:28 -07:00
commit c8bf134032
2 changed files with 10 additions and 2 deletions

View File

@ -33,7 +33,7 @@ module Cocoon
# :nodoc: # :nodoc:
def render_association(association, f, new_object, render_options={}, custom_partial=nil) def render_association(association, f, new_object, render_options={}, custom_partial=nil)
partial = setup_partial(custom_partial, association) partial = setup_partial(custom_partial, association)
locals = render_options.delete(:locals) locals = render_options.delete(:locals) || {}
method_name = f.respond_to?(:semantic_fields_for) ? :semantic_fields_for : (f.respond_to?(:simple_fields_for) ? :simple_fields_for : :fields_for) method_name = f.respond_to?(:semantic_fields_for) ? :semantic_fields_for : (f.respond_to?(:simple_fields_for) ? :simple_fields_for : :fields_for)
f.send(method_name, association, new_object, {:child_index => "new_#{association}"}.merge(render_options)) do |builder| f.send(method_name, association, new_object, {:child_index => "new_#{association}"}.merge(render_options)) do |builder|
partial_options = {:f => builder, :dynamic => true}.merge(locals) partial_options = {:f => builder, :dynamic => true}.merge(locals)
@ -58,7 +58,7 @@ module Cocoon
association = args[1] association = args[1]
html_options = args[2] || {} html_options = args[2] || {}
options = args[3] || {} options = args[3] || {}
link_to_add_association(capture(&block), f, association, html_options) link_to_add_association(capture(&block), f, association, html_options, options)
else else
name = args[0] name = args[0]
f = args[1] f = args[1]

View File

@ -45,6 +45,14 @@ describe Cocoon do
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">some long name</a>' result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">some long name</a>'
end end
it "accepts options and passes them to link_to" do
@tester.unstub(:render_association)
@tester.should_receive(:render_association).with(anything(), anything(), anything(), anything(), "shared/partial").and_return('partiallll')
result = @tester.link_to_add_association( @form_obj, :comments, {:class => 'floppy disk'}, {:partial => "shared/partial"}) do
"some long name"
end
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-associations="comments" data-template="partiallll">some long name</a>'
end
end end
context "with an irregular plural" do context "with an irregular plural" do