Fix tests for all supported Rails versions

This commit is contained in:
Rafael Mendonça França 2014-11-25 15:52:47 -02:00
parent 7d0ba39309
commit 542bc0d6ef
4 changed files with 14 additions and 14 deletions

View File

@ -32,7 +32,7 @@ class ErrorTest < ActionView::TestCase
test 'error generates messages for attribute with single error' do test 'error generates messages for attribute with single error' do
with_error_for @user, :name with_error_for @user, :name
assert_select 'span.error', "can't be blank" assert_select 'span.error', "cannot be blank"
end end
test 'error generates messages for attribute with one error when using first' do test 'error generates messages for attribute with one error when using first' do
@ -97,7 +97,7 @@ class ErrorTest < ActionView::TestCase
test 'error generates an error message with raw HTML tags' do test 'error generates an error message with raw HTML tags' do
with_error_for @user, :name, error_prefix: '<b>Name</b>'.html_safe with_error_for @user, :name, error_prefix: '<b>Name</b>'.html_safe
assert_select 'span.error', "Name can't be blank" assert_select 'span.error', "Name cannot be blank"
assert_select 'span.error b', "Name" assert_select 'span.error b', "Name"
end end
@ -105,7 +105,7 @@ class ErrorTest < ActionView::TestCase
test 'full error generates a full error tag for the attribute' do test 'full error generates a full error tag for the attribute' do
with_full_error_for @user, :name with_full_error_for @user, :name
assert_select 'span.error', "Super User Name! can't be blank" assert_select 'span.error', "Super User Name! cannot be blank"
end end
test 'full error generates a full error tag with a clean HTML' do test 'full error generates a full error tag with a clean HTML' do
@ -115,13 +115,13 @@ class ErrorTest < ActionView::TestCase
test 'full error allows passing options to full error tag' do test 'full error allows passing options to full error tag' do
with_full_error_for @user, :name, id: 'name_error', error_prefix: "Your name" with_full_error_for @user, :name, id: 'name_error', error_prefix: "Your name"
assert_select 'span.error#name_error', "Your name can't be blank" assert_select 'span.error#name_error', "Your name cannot be blank"
end end
test 'full error does not modify the options hash' do test 'full error does not modify the options hash' do
options = { id: 'name_error' } options = { id: 'name_error' }
with_full_error_for @user, :name, options with_full_error_for @user, :name, options
assert_select 'span.error#name_error', "Super User Name! can't be blank" assert_select 'span.error#name_error', "Super User Name! cannot be blank"
assert_equal({ id: 'name_error' }, options) assert_equal({ id: 'name_error' }, options)
end end
@ -139,7 +139,7 @@ class ErrorTest < ActionView::TestCase
test 'error with custom wrappers works' do test 'error with custom wrappers works' do
swap_wrapper do swap_wrapper do
with_error_for @user, :name with_error_for @user, :name
assert_select 'span.omg_error', "can't be blank" assert_select 'span.omg_error', "cannot be blank"
end end
end end
@ -177,7 +177,7 @@ class ErrorTest < ActionView::TestCase
# CUSTOM ERRORS # CUSTOM ERRORS
test 'input with custom error works' do test 'input with custom error works' do
error_text = "Super User Name! can't be blank" error_text = "Super User Name! cannot be blank"
with_form_for @user, :name, error: error_text with_form_for @user, :name, error: error_text
assert_select 'span.error', error_text assert_select 'span.error', error_text
@ -186,18 +186,18 @@ class ErrorTest < ActionView::TestCase
test 'input with error option as true does not use custom error' do test 'input with error option as true does not use custom error' do
with_form_for @user, :name, error: true with_form_for @user, :name, error: true
assert_select 'span.error', "can't be blank" assert_select 'span.error', "cannot be blank"
end end
test 'input with custom error does not generate the error if there is no error on the attribute' do test 'input with custom error does not generate the error if there is no error on the attribute' do
with_form_for @user, :active, error: "Super User Active! can't be blank" with_form_for @user, :active, error: "Super User Active! cannot be blank"
assert_no_select 'span.error' assert_no_select 'span.error'
end end
test 'input with custom error works when using full_error component' do test 'input with custom error works when using full_error component' do
swap_wrapper :default, self.custom_wrapper_with_full_error do swap_wrapper :default, self.custom_wrapper_with_full_error do
error_text = "Super User Name! can't be blank" error_text = "Super User Name! cannot be blank"
with_form_for @user, :name, error: error_text with_form_for @user, :name, error: error_text
assert_select 'span.error', error_text assert_select 'span.error', error_text

View File

@ -327,7 +327,7 @@ class FormBuilderTest < ActionView::TestCase
test 'builder generates errors for attribute with errors' do test 'builder generates errors for attribute with errors' do
with_form_for @user, :name with_form_for @user, :name
assert_select 'span.error', "can't be blank" assert_select 'span.error', "cannot be blank"
end end
test 'builder is able to disable showing errors for an input' do test 'builder is able to disable showing errors for an input' do
@ -337,7 +337,7 @@ class FormBuilderTest < ActionView::TestCase
test 'builder passes options to errors' do test 'builder passes options to errors' do
with_form_for @user, :name, error_html: { id: "cool" } with_form_for @user, :name, error_html: { id: "cool" }
assert_select 'span.error#cool', "can't be blank" assert_select 'span.error#cool', "cannot be blank"
end end
test 'placeholder does not be generated when set to false' do test 'placeholder does not be generated when set to false' do

View File

@ -139,7 +139,7 @@ class WrapperTest < ActionView::TestCase
test 'custom wrappers can have full error message on attributes' do test 'custom wrappers can have full error message on attributes' do
swap_wrapper :default, self.custom_wrapper_with_full_error do swap_wrapper :default, self.custom_wrapper_with_full_error do
with_form_for @user, :name with_form_for @user, :name
assert_select 'span.error', "Name can't be blank" assert_select 'span.error', "Name cannot be blank"
end end
end end

View File

@ -175,7 +175,7 @@ class User
def errors def errors
@errors ||= begin @errors ||= begin
errors = ActiveModel::Errors.new(self) errors = ActiveModel::Errors.new(self)
errors.add(:name, "can't be blank") errors.add(:name, "cannot be blank")
errors.add(:description, 'must be longer than 15 characters') errors.add(:description, 'must be longer than 15 characters')
errors.add(:age, 'is not a number') errors.add(:age, 'is not a number')
errors.add(:age, 'must be greater than 18') errors.add(:age, 'must be greater than 18')