Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

handle validates_length_of :is option

  • Loading branch information...
commit e39e0e54cbea9e3da1b0c24765fe72f1207670a2 1 parent 45c3dfc
@nashby authored
View
2  lib/simple_form/components/maxlength.rb
@@ -12,7 +12,7 @@ def maxlength
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
1  test/form_builder/error_notification_test.rb
@@ -11,6 +11,7 @@ def with_error_notification_for(object, options={}, &block)
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
5 test/inputs/string_input_test.rb
@@ -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
1  test/support/models.rb
@@ -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
1  test/test_helper.rb
@@ -62,6 +62,7 @@ def setup_new_user(options={})
:id => 1,
:name => 'New in Simple Form!',
:description => 'Hello!',
+ :home_picture => 'Home picture',
:created_at => Time.now,
:age => 19,
:amount => 15,

0 comments on commit e39e0e5

Please sign in to comment.
Something went wrong with that request. Please try again.