diff --git a/lib/simple_form/inputs/numeric_input.rb b/lib/simple_form/inputs/numeric_input.rb index 28a5a5fa..30aca013 100644 --- a/lib/simple_form/inputs/numeric_input.rb +++ b/lib/simple_form/inputs/numeric_input.rb @@ -33,8 +33,9 @@ module SimpleForm options = num_validator.__send__(:options) - input_options[:min] ||= options[:greater_than_or_equal_to] - input_options[:max] ||= options[:less_than_or_equal_to] + input_options[:min] ||= options[:greater_than_or_equal_to] + input_options[:max] ||= options[:less_than_or_equal_to] + input_options[:step] ||= options[:only_integer] && 1 end end end diff --git a/test/inputs_test.rb b/test/inputs_test.rb index c1d1c1ad..30d4d2b0 100644 --- a/test/inputs_test.rb +++ b/test/inputs_test.rb @@ -64,6 +64,11 @@ class InputTest < ActionView::TestCase assert_select 'input[max=99]' end + test 'input should get the step attr from a numericality validation' do + with_input_for @validating_user, :age, :integer + assert_select 'input[step=1]' + end + test 'input should generate a float text field for float attributes ' do with_input_for @user, :age, :float assert_select 'input[type=number].float#user_age' diff --git a/test/support/models.rb b/test/support/models.rb index 1e92b8f3..d7d1679b 100644 --- a/test/support/models.rb +++ b/test/support/models.rb @@ -118,5 +118,8 @@ class ValidatingUser < User include ActiveModel::Validations validates :name, :presence => true validates :company, :presence => true - validates_numericality_of :age, :greater_than_or_equal_to => 18, :less_than_or_equal_to => 99 + validates_numericality_of :age, + :greater_than_or_equal_to => 18, + :less_than_or_equal_to => 99, + :only_integer => true end