diff --git a/lib/cocoon/view_helpers.rb b/lib/cocoon/view_helpers.rb index 9dff70e..6d3da1c 100644 --- a/lib/cocoon/view_helpers.rb +++ b/lib/cocoon/view_helpers.rb @@ -33,7 +33,7 @@ module Cocoon # :nodoc: def render_association(association, f, new_object, render_options={}, custom_partial=nil) 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) f.send(method_name, association, new_object, {:child_index => "new_#{association}"}.merge(render_options)) do |builder| partial_options = {:f => builder, :dynamic => true}.merge(locals) @@ -58,7 +58,7 @@ module Cocoon association = args[1] html_options = args[2] || {} 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 name = args[0] f = args[1] diff --git a/spec/cocoon_spec.rb b/spec/cocoon_spec.rb index e20cf14..dc36ec2 100644 --- a/spec/cocoon_spec.rb +++ b/spec/cocoon_spec.rb @@ -45,6 +45,14 @@ describe Cocoon do result.to_s.should == 'some long name' 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 == 'some long name' + end end context "with an irregular plural" do