Permalink
Browse files

string|numeric|password and other basic inputs no longer add a size a…

…ttribute based of the column data -- the default config is applied, unless it's nil
  • Loading branch information...
1 parent 9c0fd73 commit b766ddc38ea79ca15e447df84e332e9efbb4e473 @justinfrench committed Sep 17, 2010
View
@@ -1694,7 +1694,7 @@ def get_maxlength_for(method)
:size => self.class.default_text_field_size }
else
{ :maxlength => validation_max_limit || column.limit,
- :size => self.class.default_text_field_size && [column.limit, self.class.default_text_field_size].min }
+ :size => self.class.default_text_field_size }
end
end
@@ -21,7 +21,8 @@
it_should_have_input_with_id("post_title")
it_should_have_input_with_type(:text)
it_should_have_input_with_name("post[title]")
- it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
+ it_should_use_default_text_field_size_when_not_nil(:string)
+ it_should_not_use_default_text_field_size_when_nil(:string)
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
it_should_apply_error_logic_for_input_type(:numeric)
@@ -22,9 +22,8 @@
it_should_have_input_with_type(:password)
it_should_have_input_with_name("post[title]")
it_should_have_maxlength_matching_column_limit
- it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(:string)
- it_should_use_column_size_for_columns_shorter_than_default_text_field_size(:string)
- it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
+ it_should_use_default_text_field_size_when_not_nil(:string)
+ it_should_not_use_default_text_field_size_when_nil(:string)
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
it_should_apply_error_logic_for_input_type(:password)
@@ -25,9 +25,8 @@
it_should_have_input_with_type(:text)
it_should_have_input_with_name("post[title]")
it_should_have_maxlength_matching_column_limit
- it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(:string)
- it_should_use_column_size_for_columns_shorter_than_default_text_field_size(:string)
- it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
+ it_should_use_default_text_field_size_when_not_nil(:string)
+ it_should_not_use_default_text_field_size_when_nil(:string)
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
it_should_apply_error_logic_for_input_type(:string)
@@ -84,16 +84,29 @@ def it_should_have_textarea_with_id(element_id)
output_buffer.should have_tag("form li textarea##{element_id}")
end
end
-
- def it_should_use_default_text_field_size_when_method_has_no_database_column(as)
- it 'should use default_text_field_size when method has no database column' do
- @new_post.stub!(:column_for_attribute).and_return(nil) # Return a nil column
-
- form = semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :as => as))
+
+ def it_should_use_default_text_field_size_when_not_nil(as)
+ it 'should use default_text_field_size when not nil' do
+ with_config :default_text_field_size, 30 do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :as => as))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form li input[@size='#{Formtastic::SemanticFormBuilder.default_text_field_size}']")
+ end
+ end
+ end
+
+ def it_should_not_use_default_text_field_size_when_nil(as)
+ it 'should not use default_text_field_size when nil' do
+ with_config :default_text_field_size, nil do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:title, :as => as))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form li input")
+ output_buffer.should_not have_tag("form li input[@size]")
end
- output_buffer.concat(form) if Formtastic::Util.rails3?
- output_buffer.should have_tag("form li input[@size='#{Formtastic::SemanticFormBuilder.default_text_field_size}']")
end
end
@@ -125,20 +138,6 @@ def it_should_have_maxlength_matching_column_limit
end
end
- def it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(as)
- it 'should use default_text_field_size for columns longer than default_text_field_size' do
- default_size = Formtastic::SemanticFormBuilder.default_text_field_size
- @new_post.stub!(:column_for_attribute).and_return(mock('column', :type => as, :limit => default_size * 2))
-
- form = semantic_form_for(@new_post) do |builder|
- concat(builder.input(:title, :as => as))
- end
-
- output_buffer.concat(@form) if Formtastic::Util.rails3?
- output_buffer.should have_tag("form li input[@size='#{default_size}']")
- end
- end
-
def it_should_use_column_size_for_columns_shorter_than_default_text_field_size(as)
it 'should use the column size for columns shorter than default_text_field_size' do
column_limit_shorted_than_default = 1

0 comments on commit b766ddc

Please sign in to comment.