Do not map Integer, Float and Decimal to Numeric.
This commit is contained in:
parent
7743a0f749
commit
001204f599
|
@ -14,9 +14,11 @@ module SimpleForm
|
|||
map_type :hidden, :to => :hidden_field
|
||||
map_type :select, :to => :collection_select, :options => true, :collection => true
|
||||
map_type :radio, :to => :collection_radio, :collection => true
|
||||
map_type :numeric, :to => :text_field
|
||||
map_type :string, :to => :text_field
|
||||
|
||||
# Numeric types
|
||||
map_type :integer, :float, :decimal, :to => :text_field
|
||||
|
||||
def self.boolean_collection
|
||||
i18n_cache :boolean_collection do
|
||||
[ [I18n.t(:"simple_form.true", :default => 'Yes'), true],
|
||||
|
@ -54,7 +56,7 @@ module SimpleForm
|
|||
when String
|
||||
options[:label_method] ||= :to_s
|
||||
options[:value_method] ||= :to_s
|
||||
when Numeric
|
||||
when Integer
|
||||
options[:label_method] ||= :to_s
|
||||
options[:value_method] ||= :to_i
|
||||
else
|
||||
|
|
|
@ -27,12 +27,14 @@ module SimpleForm
|
|||
def default_input_type(attribute)
|
||||
column = @object.column_for_attribute(attribute)
|
||||
input_type = column.type
|
||||
|
||||
case input_type
|
||||
when :decimal, :integer then :numeric
|
||||
when :timestamp then :datetime
|
||||
when nil, :string then
|
||||
when :timestamp
|
||||
:datetime
|
||||
when :string, nil
|
||||
attribute.to_s =~ /password/ ? :password : :string
|
||||
else input_type
|
||||
else
|
||||
input_type
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,9 +6,11 @@ module SimpleForm
|
|||
@mappings ||= {}
|
||||
end
|
||||
|
||||
def map_type(type, options)
|
||||
def map_type(*types)
|
||||
options = types.extract_options!
|
||||
raise ArgumentError, "You need to give :to as option to map_type" unless options[:to]
|
||||
mappings[type] = Mapping.new(options[:to], options[:collection] || false, options[:options] || false)
|
||||
mapping = Mapping.new(options[:to], options[:collection] || false, options[:options] || false)
|
||||
types.each { |t| mappings[t] = mapping }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -24,8 +24,8 @@ class InputTest < ActionView::TestCase
|
|||
assert_select 'input.string'
|
||||
with_input_for(:description, :text)
|
||||
assert_select 'textarea.text'
|
||||
with_input_for(:age, :numeric)
|
||||
assert_select 'input.numeric'
|
||||
with_input_for(:age, :integer)
|
||||
assert_select 'input.integer'
|
||||
with_input_for(:born_at, :date)
|
||||
assert_select 'select.date'
|
||||
with_input_for(:created_at, :datetime)
|
||||
|
@ -42,9 +42,19 @@ class InputTest < ActionView::TestCase
|
|||
assert_select 'textarea.text#user_description'
|
||||
end
|
||||
|
||||
test 'input should generate a numeric text field for numeric attributes ' do
|
||||
with_input_for :age, :numeric
|
||||
assert_select 'input.numeric#user_age'
|
||||
test 'input should generate an integer text field for integer attributes ' do
|
||||
with_input_for :age, :integer
|
||||
assert_select 'input.integer#user_age'
|
||||
end
|
||||
|
||||
test 'input should generate a float text field for float attributes ' do
|
||||
with_input_for :age, :float
|
||||
assert_select 'input.float#user_age'
|
||||
end
|
||||
|
||||
test 'input should generate a decimal text field for decimal attributes ' do
|
||||
with_input_for :age, :decimal
|
||||
assert_select 'input.decimal#user_age'
|
||||
end
|
||||
|
||||
test 'input should generate a checkbox by default for boolean attributes' do
|
||||
|
|
|
@ -23,14 +23,14 @@ class FormBuilderTest < ActionView::TestCase
|
|||
assert_select 'form input[type=checkbox]#user_active.boolean'
|
||||
end
|
||||
|
||||
test 'builder should use numeric text field for integer columns' do
|
||||
test 'builder should use integer text field for integer columns' do
|
||||
with_form_for :age
|
||||
assert_select 'form input#user_age.numeric'
|
||||
assert_select 'form input#user_age.integer'
|
||||
end
|
||||
|
||||
test 'builder should generate numeric text field for numeric columns' do
|
||||
test 'builder should generate decimal text field for decimal columns' do
|
||||
with_form_for :credit_limit
|
||||
assert_select 'form input#user_credit_limit.numeric'
|
||||
assert_select 'form input#user_credit_limit.decimal'
|
||||
end
|
||||
|
||||
test 'builder should generate password fields for columns that match password' do
|
||||
|
|
Loading…
Reference in New Issue