Permalink
Browse files

dup the html_options before deleting stuff from it, resolves GH-480

  • Loading branch information...
justinfrench committed Jan 13, 2011
1 parent 2d8a53e commit 44a9cc3cf19a268420c04f170bc94f1077bd3dba
Showing with 6 additions and 5 deletions.
  1. +2 −3 lib/formtastic.rb
  2. +4 −2 spec/inputs_spec.rb
View
@@ -286,7 +286,7 @@ def inputs(*args, &block)
html_options = args.extract_options!
html_options[:class] ||= "inputs"
html_options[:name] = title
-
+
if html_options[:for] # Nested form
inputs_for_nested_attributes(*(args << html_options), &block)
elsif block_given?
@@ -569,7 +569,6 @@ def inputs_for_nested_attributes(*args, &block) #:nodoc:
fields_for_block = if block_given?
raise ArgumentError, 'You gave :for option with a block to inputs method, ' <<
'but the block does not accept any argument.' if block.arity <= 0
-
lambda do |f|
contents = f.inputs(*args){ block.call(f) }
template.concat(contents) if ::Formtastic::Util.rails3?
@@ -1356,7 +1355,7 @@ def field_set_and_list_wrapping(*args, &block) #:nodoc:
contents = args.last.is_a?(::Hash) ? '' : args.pop.flatten
html_options = args.extract_options!
- legend = html_options.delete(:name).to_s
+ legend = html_options.dup.delete(:name).to_s
legend %= parent_child_index(html_options[:parent]) if html_options[:parent]
legend = template.content_tag(:legend, template.content_tag(:span, Formtastic::Util.html_safe(legend))) unless legend.blank?
View
@@ -120,14 +120,16 @@
@new_post.stub!(:authors_attributes=)
end
- it 'should nest the inputs with a name input for each item' do
+ it 'should nest the inputs with a fieldset, legend and :name input for each item' do
form = semantic_form_for(@new_post) do |post|
- post.inputs :for => :authors do |author|
+ post.inputs :for => :authors, :name => '%i' do |author|
concat(author.input(:login))
end
end
output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form fieldset.inputs", :count => 2)
+ output_buffer.should have_tag("form fieldset.inputs legend", :count => 2)
output_buffer.should have_tag("form input[@name='post[authors_attributes][0][login]']")
output_buffer.should have_tag("form input[@name='post[authors_attributes][1][login]']")
end

0 comments on commit 44a9cc3

Please sign in to comment.