Permalink
Browse files

An input without an :as option will only route to country_input if th…

…e method name is /country$/ not /country/ (which is too greedy). Resolves #260
  • Loading branch information...
1 parent 7aecbbd commit 3ae6b20655b06f301f7537c5b376d4253f206a9e @justinfrench committed May 3, 2010
Showing with 42 additions and 2 deletions.
  1. +1 −1 lib/formtastic.rb
  2. +35 −1 spec/inputs/country_input_spec.rb
  3. +6 −0 spec/spec_helper.rb
View
@@ -1341,7 +1341,7 @@ def default_input_type(method, options = {}) #:nodoc:
case column.type
when :string
return :password if method.to_s =~ /password/
- return :country if method.to_s =~ /country/
+ return :country if method.to_s =~ /country$/
return :time_zone if method.to_s =~ /time_zone/
when :integer
return :select if method.to_s =~ /_id$/
@@ -75,6 +75,40 @@
end
end
-
+
+ describe "matching" do
+
+ describe "when the attribute is 'country'" do
+
+ before do
+ semantic_form_for(@new_post) do |builder|
+ builder.stub!(:country_select).and_return("<select><option>...</option></select>")
+ concat(builder.input(:country))
+ end
+ end
+
+ it "should render a country input" do
+ output_buffer.should have_tag "form li.country"
+ end
+ end
+
+ describe "whent the attribute is 'country_something'" do
+
+ before do
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:country_subdivision))
+ concat(builder.input(:country_code))
+ end
+ end
+
+ it "should render a country input" do
+ output_buffer.should_not have_tag "form li.country"
+ output_buffer.should have_tag "form li.string", :count => 2
+ end
+
+ end
+
+ end
+
end
View
@@ -179,6 +179,9 @@ def new_author_path; "/authors/new"; end
@new_post.stub!(:time_zone)
@new_post.stub!(:category_name)
@new_post.stub!(:allow_comments)
+ @new_post.stub!(:country)
+ @new_post.stub!(:country_subdivision)
+ @new_post.stub!(:country_code)
@new_post.stub!(:column_for_attribute).with(:meta_description).and_return(mock('column', :type => :string, :limit => 255))
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 50))
@new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
@@ -187,6 +190,9 @@ def new_author_path; "/authors/new"; end
@new_post.stub!(:column_for_attribute).with(:time_zone).and_return(mock('column', :type => :string))
@new_post.stub!(:column_for_attribute).with(:allow_comments).and_return(mock('column', :type => :boolean))
@new_post.stub!(:column_for_attribute).with(:author).and_return(mock('column', :type => :integer))
+ @new_post.stub!(:column_for_attribute).with(:country).and_return(mock('column', :type => :string, :limit => 255))
+ @new_post.stub!(:column_for_attribute).with(:country_subdivision).and_return(mock('column', :type => :string, :limit => 255))
+ @new_post.stub!(:column_for_attribute).with(:country_code).and_return(mock('column', :type => :string, :limit => 255))
@new_post.stub!(:author).and_return(@bob)
@new_post.stub!(:author_id).and_return(@bob.id)

0 comments on commit 3ae6b20

Please sign in to comment.