Permalink
Browse files

don't get maxlength from validation when tokenizer present

  • Loading branch information...
1 parent 81ac8fa commit e50011eadfcf9ffb8ac9868d7a24b9e6e0cba15d @nashby committed Jan 2, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 lib/simple_form/components/maxlength.rb
  2. +5 −0 test/inputs/string_input_test.rb
  3. +1 −0 test/support/models.rb
@@ -11,7 +11,7 @@ def maxlength
def maximum_length_from_validation
if options[:maxlength] == true
- if length_validator = find_length_validator
+ if (length_validator = find_length_validator) && !length_validator.options[:tokenizer]
length_validator.options[:maximum]
end
else
@@ -47,6 +47,11 @@ class StringInputTest < ActionView::TestCase
assert_select 'input.string[maxlength=25]'
end
+ test 'input should not get maxlength from validation when tokenizer present' do
+ with_input_for @validating_user, :action, :string
+ assert_no_select 'input.string[maxlength]'
+ end
+
test 'input should not generate placeholder by default' do
with_input_for @user, :name, :string
assert_no_select 'input[placeholder]'
@@ -155,6 +155,7 @@ class ValidatingUser < User
:only_integer => true
validates_length_of :name, :maximum => 25
validates_length_of :description, :maximum => 50
+ validates_length_of :action, :maximum => 10, :tokenizer => lambda { |str| str.scan(/\w+/) }
def min_amount
10

0 comments on commit e50011e

Please sign in to comment.