Skip to content

Commit

Permalink
renamed NumericInput (:as => :numeric) to NumberInput (:as => :number)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfrench committed Apr 5, 2011
1 parent d6e6265 commit a33f4d0
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ The Formtastic input types:
* @:time@ - a time select. Default for column types: @:time@.
* @:boolean@ - a checkbox. Default for column types: @:boolean@.
* @:string@ - a text field. Default for column types: @:string@.
* @:numeric@ - a text field (just like string). Default for column types: @:integer@, @:float@, and @:decimal@.
* @:number@ - a text field (just like string). Default for column types: @:integer@, @:float@, and @:decimal@.
* @:file@ - a file field. Default for file-attachment attributes matching: "paperclip":http://github.com/thoughtbot/paperclip or "attachment_fu":http://github.com/technoweenie/attachment_fu.
* @:country@ - a select menu of country names. Default for column types: :string with name @"country"@ - requires a *country_select* plugin to be installed.
* @:email@ - a text field (just like string). Default for columns with name matching @"email"@. New in HTML5. Works on some mobile browsers already.
Expand Down
8 changes: 4 additions & 4 deletions lib/formtastic/helpers/inputs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module InputsHelper
# * `:email` (see {Inputs::EmailInput})
# * `:file` (see {Inputs::FileInput})
# * `:hidden` (see {Inputs::HiddenInput})
# * `:numeric` (see {Inputs::NumericInput})
# * `:number` (see {Inputs::NumberInput})
# * `:password` (see {Inputs::PasswordInput})
# * `:phone` (see {Inputs::PhoneInput})
# * `:radio` (see {Inputs::RadioInput})
Expand Down Expand Up @@ -615,7 +615,7 @@ def inputs_for_nested_attributes(*args, &block) #:nodoc:

# For methods that have a database column, take a best guess as to what the input method
# should be. In most cases, it will just return the column type (eg :string), but for special
# cases it will simplify (like the case of :integer, :float & :decimal to :numeric), or do
# cases it will simplify (like the case of :integer, :float & :decimal to :number), or do
# something different (like :password and :select).
#
# If there is no column for the method (eg "virtual columns" with an attr_accessor), the
Expand All @@ -634,9 +634,9 @@ def default_input_type(method, options = {}) #:nodoc:
return :search if method.to_s =~ /^search$/
when :integer
return :select if reflection_for(method)
return :numeric
return :number
when :float, :decimal
return :numeric
return :number
when :timestamp
return :datetime
end
Expand Down
2 changes: 1 addition & 1 deletion lib/formtastic/inputs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Inputs
autoload :EmailInput
autoload :FileInput
autoload :HiddenInput
autoload :NumericInput
autoload :NumberInput
autoload :PasswordInput
autoload :PhoneInput
autoload :RadioInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module Inputs
# Outputs a simple `<label>` with a HTML5 `<input type="number">` wrapped in the standard
# `<li>` wrapper. This is the default input choice for all database columns of the type `:float`
# and `:decimal`, as well as `:integer` columns that aren't used for `belongs_to` associations`,
# but can be applied to any text-like input with `:as => :numeric`.
# but can be applied to any text-like input with `:as => :number`.
#
# @example Full form context and output
#
# <%= semantic_form_for(@user) do |f| %>
# <%= f.inputs do %>
# <%= f.input :shoe_size, :as => :numeric %>
# <%= f.input :shoe_size, :as => :number %>
# <% end %>
# <% end %>
#
Expand All @@ -34,21 +34,21 @@ module Inputs
# :only_integer => true
# end
#
# <%= f.input :age, :as => :numeric %>
# <%= f.input :age, :as => :number %>
#
# <li class="numeric">
# <label for="persom_age">Age</label>
# <input type="number" id="person_age" name="person[age]" min="18" max="99" step="1">
# </li>
#
# @example Pass attributes down to the `<input>` tag
# <%= f.input :shoe_size, :as => :numeric, :input_html => { :min => 3, :max => 15, :step => 1, :class => "special" } %>
# <%= f.input :shoe_size, :as => :number, :input_html => { :min => 3, :max => 15, :step => 1, :class => "special" } %>
#
# @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documetation of all possible options.
# @see http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_numericality_of Rails' Numericality validation documentation
#
# @todo Rename/Alias to NumberInput
class NumericInput
class NumberInput
include Base
include Base::Stringish

Expand Down
2 changes: 1 addition & 1 deletion lib/formtastic/inputs/radio_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Inputs
# * a `:string` input (where you want to force the user to choose from a few specific strings rather than entering anything)
# * a `:boolean` checkbox input (where the user could choose yes or no, rather than checking a box)
# * a `:date`, `:time` or `:datetime` input (where the user could choose from a small set of pre-determined dates)
# * a `:numeric` input (where the user could choose from a small set of pre-defined numbers)
# * a `:number` input (where the user could choose from a small set of pre-defined numbers)
# * a `:time_zone` input (where you want to provide your own small set of choices instead of relying on Rails)
# * a `:country` input (where you want to provide a small set of choices, no need for a plugin really)
#
Expand Down
2 changes: 1 addition & 1 deletion lib/formtastic/inputs/select_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Inputs
# * a `:string` input (where you want to force the user to choose from a few specific strings rather than entering anything)
# * a `:boolean` checkbox input (where the user could choose yes or no, rather than checking a box)
# * a `:date`, `:time` or `:datetime` input (where the user could choose from pre-selected dates)
# * a `:numeric` input (where the user could choose from a set of pre-defined numbers)
# * a `:number` input (where the user could choose from a set of pre-defined numbers)
# * a `:time_zone` input (where you want to provide your own set of choices instead of relying on Rails)
# * a `:country` input (no need for a plugin really)
#
Expand Down
14 changes: 7 additions & 7 deletions spec/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ def should_be_required(options)
default_input_type(nil, :password_method_without_a_database_column).should == :password
end

it 'should default to :numeric for "integer" column with name ending in "_id"' do
it 'should default to :number for "integer" column with name ending in "_id"' do
@new_post.stub!(:aws_instance_id)
@new_post.stub!(:column_for_attribute).with(:aws_instance_id).and_return(mock('column', :type => :integer))
default_input_type(:integer, :aws_instance_id).should == :numeric
default_input_type(:integer, :aws_instance_id).should == :number
end

it 'should default to :select for associations' do
Expand Down Expand Up @@ -332,10 +332,10 @@ def should_be_required(options)
default_input_type(:string).should == :string
end

it 'should default to :numeric for :integer, :float and :decimal column types' do
default_input_type(:integer).should == :numeric
default_input_type(:float).should == :numeric
default_input_type(:decimal).should == :numeric
it 'should default to :number for :integer, :float and :decimal column types' do
default_input_type(:integer).should == :number
default_input_type(:float).should == :number
default_input_type(:decimal).should == :number
end

it 'should default to :country for :string columns named country' do
Expand Down Expand Up @@ -387,7 +387,7 @@ def should_be_required(options)
end

it 'should call the corresponding input class with .to_html' do
[:select, :time_zone, :radio, :date, :datetime, :time, :boolean, :check_boxes, :hidden, :string, :password, :numeric, :text, :file].each do |input_style|
[:select, :time_zone, :radio, :date, :datetime, :time, :boolean, :check_boxes, :hidden, :string, :password, :number, :text, :file].each do |input_style|
@new_post.stub!(:generic_column_name)
@new_post.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
semantic_form_for(@new_post) do |builder|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8
require 'spec_helper'

describe 'numeric input' do
describe 'number input' do

include FormtasticSpecHelper

Expand All @@ -10,11 +10,11 @@
mock_everything

concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :numeric))
concat(builder.input(:title, :as => :number))
end)
end

it_should_have_input_wrapper_with_class(:numeric)
it_should_have_input_wrapper_with_class(:number)
it_should_have_input_wrapper_with_id("post_title_input")
it_should_have_label_with_text(/Title/)
it_should_have_label_for("post_title")
Expand All @@ -25,12 +25,12 @@
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)
it_should_apply_error_logic_for_input_type(:number)

describe "when no object is provided" do
before do
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
concat(builder.input(:title, :as => :numeric))
concat(builder.input(:title, :as => :number))
end)
end

Expand All @@ -44,7 +44,7 @@
describe "when namespace provided" do
before do
concat(semantic_form_for(@new_post, :namespace => :context2) do |builder|
concat(builder.input(:title, :as => :numeric))
concat(builder.input(:title, :as => :number))
end)
end

Expand All @@ -55,7 +55,7 @@
describe "when required" do
it "should add the required attribute to the input's html options" do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :as => :numeric, :required => true))
concat(builder.input(:title, :as => :number, :required => true))
end)
output_buffer.should have_tag("input[@required]")
end
Expand All @@ -70,14 +70,14 @@

it "should add a max attribute to the input one greater than the validation" do
concat(semantic_form_for(@new_post) do |builder|
builder.input(:title, :as => :numeric)
builder.input(:title, :as => :number)
end)
output_buffer.should have_tag('input[@min="3"]')
end

it "should allow :input_html to override :min" do
concat(semantic_form_for(@new_post) do |builder|
builder.input(:title, :as => :numeric, :input_html => { :min => 102 })
builder.input(:title, :as => :number, :input_html => { :min => 102 })
end)
output_buffer.should have_tag('input[@min="102"]')
end
Expand All @@ -92,7 +92,7 @@

it "should add a max attribute to the input equal to the validation" do
concat(semantic_form_for(@new_post) do |builder|
builder.input(:title, :as => :numeric)
builder.input(:title, :as => :number)
end)
output_buffer.should have_tag('input[@min="2"]')
end
Expand All @@ -107,14 +107,14 @@

it "should add a min attribute to the input one less than the validation" do
concat(semantic_form_for(@new_post) do |builder|
builder.input(:title, :as => :numeric)
builder.input(:title, :as => :number)
end)
output_buffer.should have_tag('input[@max="19"]')
end

it "should allow :input_html to override :min" do
concat(semantic_form_for(@new_post) do |builder|
builder.input(:title, :as => :numeric, :input_html => { :max => 48 })
builder.input(:title, :as => :number, :input_html => { :max => 48 })
end)
output_buffer.should have_tag('input[@max="48"]')
end
Expand All @@ -129,7 +129,7 @@

it "should add a min attribute to the input one less than the validation" do
concat(semantic_form_for(@new_post) do |builder|
builder.input(:title, :as => :numeric)
builder.input(:title, :as => :number)
end)
output_buffer.should have_tag('input[@max="20"]')
end
Expand All @@ -144,7 +144,7 @@

it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
concat(semantic_form_for(@new_post) do |builder|
builder.input(:title, :as => :numeric)
builder.input(:title, :as => :number)
end)
output_buffer.should have_tag('input[@min="2"]')
end
Expand All @@ -159,7 +159,7 @@

it "should add a max attribute to the input equal to the :greater_than_or_equal_to validation" do
concat(semantic_form_for(@new_post) do |builder|
builder.input(:title, :as => :numeric)
builder.input(:title, :as => :number)
end)
output_buffer.should have_tag('input[@max="2"]')
end
Expand All @@ -175,14 +175,14 @@

it "should add a step=1 attribute to the input to signify that only whole numbers are allowed" do
concat(semantic_form_for(@new_post) do |builder|
builder.input(:title, :as => :numeric)
builder.input(:title, :as => :number)
end)
output_buffer.should have_tag('input[@step="1"]')
end

it "should let input_html override :step" do
concat(semantic_form_for(@new_post) do |builder|
builder.input(:title, :as => :numeric, :input_html => { :step => 3 })
builder.input(:title, :as => :number, :input_html => { :step => 3 })
end)
output_buffer.should have_tag('input[@step="3"]')
end
Expand Down

0 comments on commit a33f4d0

Please sign in to comment.