Created
May 29, 2010 12:09
-
-
Save indrekj/418247 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From ce2b0ced47465c954fe0d53c2ad79e79bba224c4 Mon Sep 17 00:00:00 2001 | |
From: Indrek Juhkam <[email protected]> | |
Date: Sat, 29 May 2010 15:02:33 +0300 | |
Subject: [PATCH] do not show input size attribute when set to nil | |
--- | |
lib/formtastic.rb | 3 +- | |
spec/inputs/string_input_spec.rb | 57 ++++++++++++++++++++++++-------------- | |
2 files changed, 38 insertions(+), 22 deletions(-) | |
diff --git a/lib/formtastic.rb b/lib/formtastic.rb | |
index cffbfc6..9dd6260 100644 | |
--- a/lib/formtastic.rb | |
+++ b/lib/formtastic.rb | |
@@ -1531,7 +1531,8 @@ module Formtastic #:nodoc: | |
elsif type == :numeric || column.nil? || column.limit.nil? | |
{ :size => @@default_text_field_size } | |
else | |
- { :maxlength => column.limit, :size => [column.limit, @@default_text_field_size].min } | |
+ { :maxlength => column.limit, | |
+ :size => @@default_text_field_size && [column.limit, @@default_text_field_size].min } | |
end | |
end | |
diff --git a/spec/inputs/string_input_spec.rb b/spec/inputs/string_input_spec.rb | |
index 5175e8e..609da62 100644 | |
--- a/spec/inputs/string_input_spec.rb | |
+++ b/spec/inputs/string_input_spec.rb | |
@@ -2,32 +2,35 @@ | |
require File.dirname(__FILE__) + '/../spec_helper' | |
describe 'string input' do | |
- | |
include FormtasticSpecHelper | |
- | |
+ | |
before do | |
@output_buffer = '' | |
mock_everything | |
- | |
- semantic_form_for(@new_post) do |builder| | |
- concat(builder.input(:title, :as => :string)) | |
- end | |
end | |
- it_should_have_input_wrapper_with_class(:string) | |
- it_should_have_input_wrapper_with_id("post_title_input") | |
- it_should_have_label_with_text(/Title/) | |
- it_should_have_label_for("post_title") | |
- 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_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_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) | |
+ describe 'when object is provided' do | |
+ before do | |
+ semantic_form_for(@new_post) do |builder| | |
+ concat(builder.input(:title, :as => :string)) | |
+ end | |
+ end | |
+ | |
+ it_should_have_input_wrapper_with_class(:string) | |
+ it_should_have_input_wrapper_with_id("post_title_input") | |
+ it_should_have_label_with_text(/Title/) | |
+ it_should_have_label_for("post_title") | |
+ 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_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_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) | |
+ end | |
describe "when no object is provided" do | |
before do | |
@@ -42,6 +45,18 @@ describe 'string input' do | |
it_should_have_input_with_type(:text) | |
it_should_have_input_with_name("project[title]") | |
end | |
- | |
+ | |
+ describe "when size is nil" do | |
+ before do | |
+ semantic_form_for(:project, :url => 'http://test.host/') do |builder| | |
+ concat(builder.input(:title, :as => :string, :input_html => {:size => nil})) | |
+ end | |
+ end | |
+ | |
+ it "should have no size attribute" do | |
+ puts output_buffer.inspect | |
+ output_buffer.should_not include("size=") | |
+ end | |
+ end | |
end | |
-- | |
1.7.0.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment