From 1d22eba498f14f6e62360884da15c59deb1ff551 Mon Sep 17 00:00:00 2001 From: Brian Meeker Date: Sat, 7 Apr 2012 11:34:10 -0400 Subject: [PATCH 1/3] Added a new example that passes options to link_to_add_association with a block for the name. The test fails. --- spec/cocoon_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) 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 From 5fa318a7f60736b4db0b440e0c30236cd23f32d9 Mon Sep 17 00:00:00 2001 From: Brian Meeker Date: Sat, 7 Apr 2012 11:34:57 -0400 Subject: [PATCH 2/3] Pass options through to link_to_add_association when calling with block for link text. --- lib/cocoon/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cocoon/view_helpers.rb b/lib/cocoon/view_helpers.rb index 9dff70e..ed832a6 100644 --- a/lib/cocoon/view_helpers.rb +++ b/lib/cocoon/view_helpers.rb @@ -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] From e43a03919c54014574956882de5a3624e748e24b Mon Sep 17 00:00:00 2001 From: Brian Meeker Date: Sat, 7 Apr 2012 16:59:43 -0400 Subject: [PATCH 3/3] Make sure that locals is always initialized in render_association. If it is not, the call to Hash#merge will fail. --- lib/cocoon/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cocoon/view_helpers.rb b/lib/cocoon/view_helpers.rb index ed832a6..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)