-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathdevise_helper_test.rb
51 lines (40 loc) · 1.51 KB
/
devise_helper_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true
require 'test_helper'
class DeviseHelperTest < Devise::IntegrationTest
setup do
model_labels = { models: { user: "the user" } }
translations = {
errors: { messages: { not_saved: {
one: "Can't save %{resource} because of 1 error",
other: "Can't save %{resource} because of %{count} errors",
} } },
activerecord: model_labels,
mongoid: model_labels
}
I18n.backend.eager_load!
I18n.backend.store_translations(:en, translations)
end
teardown do
I18n.reload!
end
test 'test errors.messages.not_saved with single error from i18n' do
get new_user_registration_path
fill_in 'password', with: 'new_user123'
fill_in 'password confirmation', with: 'new_user123'
click_button 'Sign up'
assert_have_selector '#error_explanation'
assert_contain "Can't save the user because of 1 error"
end
test 'test errors.messages.not_saved with multiple errors from i18n' do
# 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
get new_user_registration_path
fill_in 'email', with: 'invalid_email'
fill_in 'password', with: 'new_user123'
fill_in 'password confirmation', with: 'new_user321'
click_button 'Sign up'
assert_have_selector '#error_explanation'
assert_contain "Can't save the user because of 2 errors"
end
end