Navigation Menu

Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
don't generate div.fields only if wrapper option is false
Browse files Browse the repository at this point in the history
  • Loading branch information
lest committed Nov 5, 2012
1 parent c952015 commit ca7e235
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/nested_form/builder_mixin.rb
Expand Up @@ -90,7 +90,7 @@ def fields_for_nested_model(name, object, options, block)
classes = 'fields'
classes << ' marked_for_destruction' if object.respond_to?(:marked_for_destruction?) && object.marked_for_destruction?

if options.fetch(:wrapper, true)
if options[:wrapper] != false # wrap even if nil
@template.content_tag(:div, super, :class => classes)
else
super
Expand Down
13 changes: 9 additions & 4 deletions spec/nested_form/builder_spec.rb
Expand Up @@ -36,7 +36,7 @@
}.to raise_error(ArgumentError)
end
end

describe '#link_to_remove' do
it "behaves similar to a Rails link_to" do
subject.link_to_remove("Remove").should == '<input id="item__destroy" name="item[_destroy]" type="hidden" value="false" /><a href="javascript:void(0)" class="remove_nested_fields">Remove</a>'
Expand Down Expand Up @@ -76,9 +76,14 @@
describe '#fields_for' do
it "wraps nested fields each in a div with class" do
2.times { project.tasks.build }
subject.fields_for(:tasks) do
"Task"
end.should == '<div class="fields">Task</div><div class="fields">Task</div>'

fields = if subject.is_a?(NestedForm::SimpleBuilder)
subject.simple_fields_for(:tasks) { "Task" }
else
subject.fields_for(:tasks) { "Task" }
end

fields.should == '<div class="fields">Task</div><div class="fields">Task</div>'
end
end

Expand Down

0 comments on commit ca7e235

Please sign in to comment.