2011-06-27 14:31:03 -04:00
|
|
|
require 'test_helper'
|
|
|
|
|
2015-08-18 19:42:56 -04:00
|
|
|
class DeviseHelperTest < Devise::IntegrationTest
|
2011-06-27 14:31:03 -04:00
|
|
|
setup do
|
2014-09-11 16:01:07 -04:00
|
|
|
model_labels = { models: { user: "the user" } }
|
|
|
|
translations = {
|
2014-02-25 11:42:55 -05:00
|
|
|
errors: { messages: { not_saved: {
|
2014-09-11 16:01:07 -04:00
|
|
|
one: "Can't save %{resource} because of 1 error",
|
|
|
|
other: "Can't save %{resource} because of %{count} errors",
|
2011-06-27 14:31:03 -04:00
|
|
|
} } },
|
2014-02-25 11:42:55 -05:00
|
|
|
activerecord: model_labels,
|
|
|
|
mongoid: model_labels
|
2011-06-27 14:31:03 -04:00
|
|
|
}
|
2011-06-28 06:05:35 -04:00
|
|
|
|
2014-09-11 16:01:07 -04:00
|
|
|
I18n.available_locales
|
|
|
|
I18n.backend.store_translations(:en, translations)
|
2011-06-27 14:31:03 -04:00
|
|
|
end
|
2011-06-28 06:05:35 -04:00
|
|
|
|
|
|
|
teardown do
|
2014-09-11 16:01:07 -04:00
|
|
|
I18n.reload!
|
2011-06-28 06:05:35 -04:00
|
|
|
end
|
|
|
|
|
2011-06-27 14:31:03 -04:00
|
|
|
test 'test errors.messages.not_saved with single error from i18n' do
|
|
|
|
get new_user_registration_path
|
2011-06-28 06:05:35 -04:00
|
|
|
|
2014-02-25 11:42:55 -05:00
|
|
|
fill_in 'password', with: 'new_user123'
|
|
|
|
fill_in 'password confirmation', with: 'new_user123'
|
2011-06-27 14:31:03 -04:00
|
|
|
click_button 'Sign up'
|
|
|
|
|
|
|
|
assert_have_selector '#error_explanation'
|
2014-09-11 16:01:07 -04:00
|
|
|
assert_contain "Can't save the user because of 1 error"
|
2011-06-27 14:31:03 -04:00
|
|
|
end
|
2011-06-28 06:05:35 -04:00
|
|
|
|
2011-06-27 14:31:03 -04:00
|
|
|
test 'test errors.messages.not_saved with multiple errors from i18n' do
|
2011-08-04 14:38:42 -04:00
|
|
|
# Dirty tracking behavior prevents email validations from being applied:
|
|
|
|
# https://github.com/mongoid/mongoid/issues/756
|
|
|
|
(pending "Fails on Mongoid < 2.1"; break) if defined?(Mongoid) && Mongoid::VERSION.to_f < 2.1
|
|
|
|
|
2011-06-27 14:31:03 -04:00
|
|
|
get new_user_registration_path
|
2011-06-28 06:05:35 -04:00
|
|
|
|
2014-02-25 11:42:55 -05:00
|
|
|
fill_in 'email', with: 'invalid_email'
|
|
|
|
fill_in 'password', with: 'new_user123'
|
|
|
|
fill_in 'password confirmation', with: 'new_user321'
|
2011-06-27 14:31:03 -04:00
|
|
|
click_button 'Sign up'
|
|
|
|
|
|
|
|
assert_have_selector '#error_explanation'
|
2014-09-11 16:01:07 -04:00
|
|
|
assert_contain "Can't save the user because of 2 errors"
|
2011-06-27 14:31:03 -04:00
|
|
|
end
|
2011-08-04 14:38:42 -04:00
|
|
|
end
|