Skip to content
Browse files

.dup options hash before we fiddle with it so that the same hash can …

…be re-used in views between inputs (GH-474)
  • Loading branch information...
1 parent 3b4080f commit d7b9390f044811bc559985fc652007e6c8f8fa15 @justinfrench committed Dec 20, 2010
Showing with 22 additions and 2 deletions.
  1. +3 −1 lib/formtastic.rb
  2. +19 −1 spec/input_spec.rb
View
4 lib/formtastic.rb
@@ -99,6 +99,8 @@ class SemanticFormBuilder < ActionView::Helpers::FormBuilder
# <% end %>
#
def input(method, options = {})
+ options = options.dup # Allow options to be shared without being tainted by Formtastic
+
options[:required] = method_required?(method) unless options.key?(:required)
options[:as] ||= default_input_type(method, options)
@@ -1682,7 +1684,7 @@ def get_maxlength_for(method)
if type == :text
{ :rows => self.class.default_text_area_height, :cols => self.class.default_text_area_width }
- elsif type == :numeric || column.nil? || column.limit.nil?
+ elsif (type == :numeric) || !column.respond_to?(:limit) || column.nil? || column.limit.nil?
{ :maxlength => validation_max_limit,
:size => self.class.default_text_field_size }
else
View
20 spec/input_spec.rb
@@ -896,6 +896,24 @@ def should_be_required(options)
end
end
-
+
+ describe 'options re-use' do
+
+ it 'should retain :as option when re-using the same options hash' do
+ my_options = { :as => :string }
+ output = ''
+
+ @form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, my_options))
+ concat(builder.input(:publish_at, my_options))
+ end
+ output_buffer.concat(@form) if Formtastic::Util.rails3?
+
+ output_buffer.should have_tag 'li.string', :count => 2
+ end
+
+
+ end
+
end

0 comments on commit d7b9390

Please sign in to comment.
Something went wrong with that request. Please try again.