1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

handle validates_length_of :is option

This commit is contained in:
Vasiliy Ermolovich 2012-01-03 21:10:50 +03:00
parent 45c3dfc04d
commit e39e0e54cb
5 changed files with 9 additions and 1 deletions

View file

@ -12,7 +12,7 @@ module SimpleForm
def maximum_length_from_validation
if options[:maxlength] == true
if (length_validator = find_length_validator) && !length_validator.options[:tokenizer]
length_validator.options[:maximum]
length_validator.options[:is] || length_validator.options[:maximum]
end
else
options[:maxlength]

View file

@ -11,6 +11,7 @@ class ErrorNotificationTest < ActionView::TestCase
test 'error notification is not generated when the object has no error' do
assert @validating_user.valid?
with_error_notification_for @validating_user
assert_no_select 'p.error_notification'
end

View file

@ -52,6 +52,11 @@ class StringInputTest < ActionView::TestCase
assert_no_select 'input.string[maxlength]'
end
test 'input should get maxlength from validation when :is option present' do
with_input_for @validating_user, :home_picture, :string
assert_select 'input.string[maxlength=12]'
end
test 'input should not generate placeholder by default' do
with_input_for @user, :name, :string
assert_no_select 'input[placeholder]'

View file

@ -156,6 +156,7 @@ class ValidatingUser < User
validates_length_of :name, :maximum => 25
validates_length_of :description, :maximum => 50
validates_length_of :action, :maximum => 10, :tokenizer => lambda { |str| str.scan(/\w+/) }
validates_length_of :home_picture, :is => 12
def min_amount
10

View file

@ -62,6 +62,7 @@ class ActionView::TestCase
:id => 1,
:name => 'New in Simple Form!',
:description => 'Hello!',
:home_picture => 'Home picture',
:created_at => Time.now,
:age => 19,
:amount => 15,