Added failing minlength tests to string and text input tests, and to ValidatingUser

This commit is contained in:
Seth Veale 2016-08-22 14:36:45 +12:00
parent 6345ac0f9d
commit bf2cca100c
5 changed files with 30 additions and 2 deletions

View File

@ -105,6 +105,12 @@ class InputFieldTest < ActionView::TestCase
assert_select 'input.string[maxlength="25"]'
end
test 'builder input_field uses minlength component' do
with_input_field_for @validating_user, :name, as: :string
assert_select 'input.string[minlength="5"]'
end
test 'builder collection input_field generates input tag with a clean HTML' do
with_input_field_for @user, :status, collection: ['Open', 'Closed'],
class: 'status', label_method: :to_s, value_method: :to_s

View File

@ -32,11 +32,21 @@ class StringInputTest < ActionView::TestCase
assert_select 'input.string[maxlength="25"]'
end
test 'input infers minlength column definition from validation when present' do
with_input_for @validating_user, :name, :string
assert_select 'input.string[minlength="5"]'
end
if ActionPack::VERSION::STRING < '5'
test 'input does 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 does not get minlength from validation when tokenizer present' do
with_input_for @validating_user, :action, :string
assert_no_select 'input.string[minlength]'
end
end
test 'input gets maxlength from validation when :is option present' do
@ -44,6 +54,11 @@ class StringInputTest < ActionView::TestCase
assert_select 'input.string[maxlength="12"]'
end
test 'input gets minlength from validation when :is option present' do
with_input_for @validating_user, :home_picture, :string
assert_select 'input.string[minlength="12"]'
end
test 'input maxlength is the column limit plus one to make room for decimal point' do
with_input_for @user, :credit_limit, :string

View File

@ -28,4 +28,9 @@ class TextInputTest < ActionView::TestCase
with_input_for @validating_user, :description, :text
assert_select 'textarea.text[maxlength="50"]'
end
test 'input infers minlength column definition from validation when present for text attributes' do
with_input_for @validating_user, :description, :text
assert_select 'textarea.text[minlength="15"]'
end
end

View File

@ -213,8 +213,8 @@ class ValidatingUser < User
greater_than_or_equal_to: :min_attempts,
less_than_or_equal_to: :max_attempts,
only_integer: true
validates_length_of :name, maximum: 25
validates_length_of :description, maximum: 50
validates_length_of :name, maximum: 25, minimum: 5
validates_length_of :description, in: 15..50
if ActionPack::VERSION::STRING < '5'
validates_length_of :action, maximum: 10, tokenizer: lambda { |str| str.scan(/\w+/) }
end

View File

@ -55,6 +55,8 @@ class ActionView::TestCase
@user = User.build(extra_attributes)
@validating_user = ValidatingUser.build({
name: 'Tester McTesterson',
description: 'A test user of the most distinguised caliber',
home_picture: 'Home picture',
age: 19,
amount: 15,