2010-09-28 00:05:37 +00:00
|
|
|
# encoding: UTF-8
|
2010-07-06 20:29:26 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
2011-09-03 16:36:02 +00:00
|
|
|
# Tests for f.error_notification
|
2010-07-06 20:29:26 +00:00
|
|
|
class ErrorNotificationTest < ActionView::TestCase
|
|
|
|
def with_error_notification_for(object, options={}, &block)
|
2010-09-26 22:24:30 +00:00
|
|
|
with_concat_form_for(object) do |f|
|
2010-09-26 22:16:25 +00:00
|
|
|
f.error_notification(options)
|
2010-09-26 22:24:30 +00:00
|
|
|
end
|
2010-07-06 20:29:26 +00:00
|
|
|
end
|
|
|
|
|
2010-07-06 22:00:44 +00:00
|
|
|
test 'error notification is not generated when the object has no error' do
|
|
|
|
assert @validating_user.valid?
|
2012-01-03 18:10:50 +00:00
|
|
|
|
2010-07-06 22:00:44 +00:00
|
|
|
with_error_notification_for @validating_user
|
2010-07-06 20:29:26 +00:00
|
|
|
assert_no_select 'p.error_notification'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'error notification is not generated for forms without objects' do
|
|
|
|
with_error_notification_for :user
|
|
|
|
assert_no_select 'p.error_notification'
|
|
|
|
end
|
|
|
|
|
2010-07-06 22:00:44 +00:00
|
|
|
test 'error notification is generated when the object has some error' do
|
2010-07-06 20:29:26 +00:00
|
|
|
with_error_notification_for @user
|
|
|
|
assert_select 'p.error_notification', 'Some errors were found, please take a look:'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'error notification uses I18n based on model to generate the notification message' do
|
|
|
|
store_translations(:en, :simple_form => { :error_notification => { :user =>
|
|
|
|
'Alguns erros foram encontrados para o usuário:'
|
|
|
|
} }) do
|
|
|
|
with_error_notification_for @user
|
|
|
|
assert_select 'p.error_notification', 'Alguns erros foram encontrados para o usuário:'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'error notification uses I18n fallbacking to default message' do
|
|
|
|
store_translations(:en, :simple_form => { :error_notification => {
|
|
|
|
:default_message => 'Opa! Alguns erros foram encontrados, poderia verificar?'
|
|
|
|
} }) do
|
|
|
|
with_error_notification_for @user
|
|
|
|
assert_select 'p.error_notification', 'Opa! Alguns erros foram encontrados, poderia verificar?'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'error notification allows passing the notification message' do
|
|
|
|
with_error_notification_for @user, :message => 'Erro encontrado ao criar usuario'
|
|
|
|
assert_select 'p.error_notification', 'Erro encontrado ao criar usuario'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'error notification accepts other html options' do
|
|
|
|
with_error_notification_for @user, :id => 'user_error_message', :class => 'form_error'
|
|
|
|
assert_select 'p#user_error_message.form_error.error_notification'
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'error notification allows configuring the wrapper element' do
|
|
|
|
swap SimpleForm, :error_notification_tag => :div do
|
|
|
|
with_error_notification_for @user
|
|
|
|
assert_select 'div.error_notification'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|