Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove the extra options-hash for the partial, instead use the same h…

…tml_options hash. Is less confusing, and matches the documentation (I was under the impression it was already like that --ooops).
  • Loading branch information...
commit 0225126532bee45976ac16ac8c96116c7d50f053 1 parent a0c2d6d
@nathanvda authored
Showing with 18 additions and 16 deletions.
  1. +6 −11 lib/cocoon/view_helpers.rb
  2. +12 −5 spec/cocoon_spec.rb
View
17 lib/cocoon/view_helpers.rb
@@ -32,7 +32,7 @@ def link_to_remove_association(*args, &block)
# :nodoc:
def render_association(association, f, new_object, render_options={}, custom_partial=nil)
- partial = setup_partial(custom_partial, association)
+ partial = get_partial_path(custom_partial, association)
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|
@@ -57,24 +57,23 @@ def link_to_add_association(*args, &block)
f = args[0]
association = args[1]
html_options = args[2] || {}
- options = args[3] || {}
- link_to_add_association(capture(&block), f, association, html_options, options)
+ link_to_add_association(capture(&block), f, association, html_options)
else
name = args[0]
f = args[1]
association = args[2]
html_options = args[3] || {}
- options = args[4] || {}
render_options = html_options.delete(:render_options)
render_options ||= {}
+ override_partial = html_options.delete(:partial)
html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
html_options[:'data-association'] = association.to_s.singularize
html_options[:'data-associations'] = association.to_s.pluralize
new_object = create_object(f, association)
- html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object, render_options, options[:partial])).html_safe
+ html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object, render_options, override_partial)).html_safe
link_to(name, '#', html_options )
end
@@ -90,12 +89,8 @@ def create_object(f, association)
new_object = assoc.klass.new(*conditions)
end
- def setup_partial(partial, association)
- if partial
- partial
- else
- association.to_s.singularize + "_fields"
- end
+ def get_partial_path(partial, association)
+ partial ? partial : association.to_s.singularize + "_fields"
end
end
View
17 spec/cocoon_spec.rb
@@ -28,6 +28,13 @@ class TestClass < ActionView::Base
result = @tester.link_to_add_association('add something', @form_obj, :comments, {:class => 'something silly'})
result.to_s.should == '<a href="#" class="something silly add_fields" data-association="comment" data-associations="comments" data-template="form&lt;tag&gt;">add something</a>'
end
+
+ it "allows to explicitly hand the wanted partial" 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('add something', @form_obj, :comments, :partial => "shared/partial")
+ result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-associations="comments" data-template="partiallll">add something</a>'
+ end
end
context "with a block" do
@@ -45,10 +52,10 @@ class TestClass < ActionView::Base
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
- it "accepts options and passes them to link_to" do
+ it "allows to explicitly hand the wanted partial" 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
+ 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>'
@@ -175,13 +182,13 @@ class TestClass < ActionView::Base
end
end
- context "setup_partial" do
+ context "get_partial_path" do
it "generates the default partial name if no partial given" do
- result = @tester.setup_partial(nil, :admin_comments)
+ result = @tester.get_partial_path(nil, :admin_comments)
result.should == "admin_comment_fields"
end
it "uses the given partial name" do
- result = @tester.setup_partial("comment_fields", :admin_comments)
+ result = @tester.get_partial_path("comment_fields", :admin_comments)
result.should == "comment_fields"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.