devise_invitable 1.7.4 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise_invitable might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/{CHANGELOG → CHANGELOG.md} +54 -19
- data/README.rdoc +98 -111
- data/app/controllers/devise/invitations_controller.rb +41 -41
- data/app/controllers/devise_invitable/registrations_controller.rb +11 -11
- data/app/views/devise/invitations/edit.html.erb +14 -8
- data/app/views/devise/invitations/new.html.erb +11 -7
- data/app/views/devise/mailer/invitation_instructions.html.erb +2 -2
- data/app/views/devise/mailer/invitation_instructions.text.erb +2 -2
- data/config/locales/ar.yml +23 -0
- data/config/locales/da.yml +41 -0
- data/config/locales/de.yml +31 -0
- data/config/locales/en.yml +1 -1
- data/config/locales/es.yml +31 -0
- data/config/locales/et.yml +23 -0
- data/config/locales/fa.yml +31 -0
- data/config/locales/fr.yml +34 -0
- data/config/locales/it.yml +31 -0
- data/config/locales/ja.yml +32 -0
- data/config/locales/ko.yml +24 -0
- data/config/locales/nl.yml +32 -0
- data/config/locales/no.yml +17 -0
- data/config/locales/pl.yml +31 -0
- data/config/locales/pt-BR.yml +23 -0
- data/config/locales/pt.yml +23 -0
- data/config/locales/ru.yml +23 -0
- data/config/locales/tr.yml +24 -0
- data/config/locales/ua.yml +31 -0
- data/config/locales/vi.yml +25 -0
- data/config/locales/zh-HK.yml +31 -0
- data/config/locales/zh-TW.yml +31 -0
- data/lib/devise_invitable.rb +5 -4
- data/lib/devise_invitable/controllers/helpers.rb +3 -4
- data/lib/devise_invitable/inviter.rb +4 -3
- data/lib/devise_invitable/mailer.rb +1 -1
- data/lib/devise_invitable/mapping.rb +6 -5
- data/lib/devise_invitable/models.rb +48 -32
- data/lib/devise_invitable/parameter_sanitizer.rb +18 -18
- data/lib/devise_invitable/routes.rb +5 -5
- data/lib/devise_invitable/version.rb +1 -1
- data/lib/generators/active_record/devise_invitable_generator.rb +3 -3
- data/lib/generators/active_record/templates/migration.rb +0 -1
- data/lib/generators/devise_invitable/devise_invitable_generator.rb +4 -8
- data/lib/generators/devise_invitable/install_generator.rb +11 -14
- data/lib/generators/devise_invitable/templates/simple_form_for/invitations/edit.html.erb +10 -6
- data/lib/generators/devise_invitable/templates/simple_form_for/invitations/new.html.erb +10 -6
- data/lib/generators/devise_invitable/views_generator.rb +6 -6
- data/test/functional/registrations_controller_test.rb +24 -25
- data/test/generators/views_generator_test.rb +7 -6
- data/test/generators_test.rb +3 -2
- data/test/integration/invitation_remove_test.rb +8 -8
- data/test/integration/invitation_test.rb +46 -46
- data/test/integration_tests_helper.rb +8 -9
- data/test/model_tests_helper.rb +5 -5
- data/test/models/invitable_test.rb +123 -108
- data/test/models_test.rb +3 -3
- data/test/orm/active_record.rb +5 -1
- data/test/orm/mongoid.rb +2 -2
- data/test/rails_app/app/controllers/admins_controller.rb +4 -3
- data/test/rails_app/app/controllers/application_controller.rb +11 -10
- data/test/rails_app/app/controllers/free_invitations_controller.rb +12 -9
- data/test/rails_app/app/controllers/users_controller.rb +2 -2
- data/test/rails_app/app/models/admin.rb +7 -10
- data/test/rails_app/app/models/octopussy.rb +4 -4
- data/test/rails_app/app/models/user.rb +20 -20
- data/test/rails_app/app/views/admins/new.html.erb +9 -5
- data/test/rails_app/app/views/devise/sessions/new.html.erb +14 -6
- data/test/rails_app/app/views/free_invitations/new.html.erb +9 -5
- data/test/rails_app/app/views/layouts/application.html.erb +3 -4
- data/test/rails_app/app/views/users/invitations/new.html.erb +15 -9
- data/test/rails_app/config/application.rb +7 -6
- data/test/rails_app/config/boot.rb +2 -2
- data/test/rails_app/config/credentials.yml.enc +1 -0
- data/test/rails_app/config/initializers/devise.rb +4 -3
- data/test/rails_app/config/initializers/secret_token.rb +3 -1
- data/test/rails_app/config/initializers/session_store.rb +1 -1
- data/test/rails_app/config/initializers/wrap_parameters.rb +1 -1
- data/test/rails_app/config/master.key +1 -0
- data/test/rails_app/config/routes.rb +3 -3
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -2
- data/test/routes_test.rb +4 -4
- data/test/test_helper.rb +6 -19
- metadata +48 -23
@@ -10,37 +10,37 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
|
|
10
10
|
# josevalim: you are required to do that because the routes sets this kind
|
11
11
|
# of stuff automatically. But functional tests are not using the routes.
|
12
12
|
# see https://github.com/plataformatec/devise/issues/1196
|
13
|
-
@request.env[
|
13
|
+
@request.env['devise.mapping'] = Devise.mappings[:user]
|
14
14
|
end
|
15
15
|
|
16
16
|
test "invited users may still sign up directly by themselves" do
|
17
17
|
# invite the invitee
|
18
18
|
sign_in @issuer
|
19
|
-
invitee_email =
|
19
|
+
invitee_email = 'invitee@example.org'
|
20
20
|
|
21
|
-
User.invite!(:
|
21
|
+
User.invite!(email: invitee_email) do |u|
|
22
22
|
u.skip_invitation = true
|
23
23
|
u.invited_by = @issuer
|
24
24
|
end
|
25
25
|
sign_out @issuer
|
26
26
|
|
27
|
-
@invitee = User.where(:
|
27
|
+
@invitee = User.where(email: invitee_email).first
|
28
28
|
assert_nil @invitee.invitation_accepted_at
|
29
29
|
assert_not_nil @invitee.invitation_token
|
30
30
|
assert !@invitee.confirmed?
|
31
31
|
|
32
32
|
# sign_up the invitee
|
33
33
|
assert_difference('ActionMailer::Base.deliveries.size') do
|
34
|
-
post :create, params: {:
|
34
|
+
post :create, params: { user: { email: invitee_email, password: '1password', bio: '.' } }
|
35
35
|
end
|
36
36
|
|
37
|
-
@invitee = User.where(:
|
37
|
+
@invitee = User.where(email: invitee_email).first
|
38
38
|
|
39
39
|
# do not send emails on model changes
|
40
40
|
assert_difference('ActionMailer::Base.deliveries.size', 0) do
|
41
|
-
@invitee.bio =
|
41
|
+
@invitee.bio = 'I am a robot'
|
42
42
|
@invitee.save!
|
43
|
-
@invitee.bio =
|
43
|
+
@invitee.bio = 'I am a human'
|
44
44
|
@invitee.save!
|
45
45
|
end
|
46
46
|
|
@@ -54,20 +54,20 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
|
|
54
54
|
end
|
55
55
|
|
56
56
|
test "non-invited users may still sign up directly by themselves" do
|
57
|
-
register_email =
|
57
|
+
register_email = 'invitee@example.org'
|
58
58
|
# sign_up the invitee
|
59
59
|
assert_difference('ActionMailer::Base.deliveries.size') do
|
60
|
-
post :create, params: {:
|
60
|
+
post :create, params: { user: { email: register_email, password: '1password', bio: '.' } }
|
61
61
|
end
|
62
62
|
assert_nil @controller.current_user
|
63
63
|
|
64
|
-
@user = User.where(:
|
64
|
+
@user = User.where(email: register_email).first
|
65
65
|
|
66
66
|
# do not send emails on model changes
|
67
67
|
assert_no_difference('ActionMailer::Base.deliveries.size') do
|
68
|
-
@user.bio =
|
68
|
+
@user.bio = 'I am a robot'
|
69
69
|
@user.save!
|
70
|
-
@user.bio =
|
70
|
+
@user.bio = 'I am a human'
|
71
71
|
@user.save!
|
72
72
|
end
|
73
73
|
|
@@ -80,36 +80,35 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
|
|
80
80
|
end
|
81
81
|
|
82
82
|
test "not invitable resources can register" do
|
83
|
-
@request.env[
|
84
|
-
invitee_email =
|
83
|
+
@request.env['devise.mapping'] = Devise.mappings[:admin]
|
84
|
+
invitee_email = 'invitee@example.org'
|
85
85
|
|
86
|
-
assert_nil Admin.where(:
|
86
|
+
assert_nil Admin.where(email: invitee_email).first
|
87
87
|
|
88
|
-
post :create, params: {:
|
88
|
+
post :create, params: { admin: { email: invitee_email, password: '1password' } }
|
89
89
|
|
90
|
-
@invitee = Admin.where(:
|
90
|
+
@invitee = Admin.where(email: invitee_email).first
|
91
91
|
assert @invitee.encrypted_password.present?
|
92
92
|
end
|
93
93
|
|
94
94
|
test "not invitable resources are not logged in after sign up again" do
|
95
|
-
@request.env[
|
96
|
-
invitee_email =
|
95
|
+
@request.env['devise.mapping'] = Devise.mappings[:admin]
|
96
|
+
invitee_email = 'invitee@example.org'
|
97
97
|
|
98
|
-
post :create, params: {:
|
98
|
+
post :create, params: { admin: { email: invitee_email, password: '1password' } }
|
99
99
|
assert_response 302
|
100
100
|
|
101
|
-
@invitee = Admin.where(:
|
101
|
+
@invitee = Admin.where(email: invitee_email).first
|
102
102
|
assert @invitee.encrypted_password.present?
|
103
103
|
|
104
104
|
sign_out @invitee
|
105
|
-
post :create, params: {:
|
105
|
+
post :create, params: { admin: { email: invitee_email, password: "2password" } }
|
106
106
|
assert_response 200
|
107
|
-
assert_equal @invitee.encrypted_password, Admin.where(:
|
107
|
+
assert_equal @invitee.encrypted_password, Admin.where(email: invitee_email).first.encrypted_password
|
108
108
|
assert @controller.send(:resource).errors.present?
|
109
109
|
end
|
110
110
|
|
111
111
|
test "missing params on a create should not cause an error" do
|
112
|
-
|
113
112
|
assert_nothing_raised { post :create }
|
114
113
|
end
|
115
114
|
end
|
@@ -28,13 +28,14 @@ class ViewsGeneratorTest < ::Rails::Generators::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
|
-
def assert_files
|
32
|
-
assert views = { @invitations_path => %w/edit.html.erb new.html.erb/, @mailer_path => %w/invitation_instructions.html.erb/ }
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def assert_files
|
33
|
+
assert views = { @invitations_path => %w/edit.html.erb new.html.erb/, @mailer_path => %w/invitation_instructions.html.erb/ }
|
34
|
+
|
35
|
+
views.each do |path, files|
|
36
|
+
files.each do |file|
|
37
|
+
assert_file File.join path, file
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
|
-
end
|
40
41
|
end
|
data/test/generators_test.rb
CHANGED
@@ -17,13 +17,14 @@ class GeneratorsTest < ActiveSupport::TestCase
|
|
17
17
|
|
18
18
|
test "rails g devise_invitable:install" do
|
19
19
|
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:install -p`
|
20
|
-
|
20
|
+
puts @output
|
21
|
+
assert @output.match(%r{(inject|insert|File unchanged! The supplied flag value not found!).* config/initializers/devise\.rb\n})
|
21
22
|
assert @output.match(%r|create.* config/locales/devise_invitable\.en\.yml\n|)
|
22
23
|
end
|
23
24
|
|
24
25
|
test "rails g devise_invitable Octopussy" do
|
25
26
|
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable Octopussy -p`
|
26
|
-
assert @output.match(%r{(inject|insert).* app/models/octopussy\.rb\n})
|
27
|
+
assert @output.match(%r{(inject|insert|File unchanged! The supplied flag value not found!).* app/models/octopussy\.rb\n})
|
27
28
|
assert @output.match(%r|invoke.* #{DEVISE_ORM}\n|)
|
28
29
|
if DEVISE_ORM == :active_record
|
29
30
|
assert @output.match(%r|create.* db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
|
@@ -4,26 +4,26 @@ require 'integration_tests_helper'
|
|
4
4
|
class InvitationRemoveTest < ActionDispatch::IntegrationTest
|
5
5
|
|
6
6
|
test 'invited user can choose to remove his account/invite' do
|
7
|
-
User.invite!(:
|
7
|
+
User.invite!(email: 'valid@email.com')
|
8
8
|
|
9
9
|
# remove!
|
10
|
-
visit remove_user_invitation_path(:
|
10
|
+
visit remove_user_invitation_path(invitation_token: Thread.current[:token])
|
11
11
|
assert_equal root_path, current_path
|
12
|
-
assert page.has_css?('p#notice', :
|
12
|
+
assert page.has_css?('p#notice', text: 'Your invitation was removed.')
|
13
13
|
|
14
14
|
# try to remove again!
|
15
|
-
visit remove_user_invitation_path(:
|
15
|
+
visit remove_user_invitation_path(invitation_token: Thread.current[:token])
|
16
16
|
assert_equal root_path, current_path
|
17
|
-
assert page.has_css?('p#alert', :
|
17
|
+
assert page.has_css?('p#alert', text: 'The invitation token provided is not valid!')
|
18
18
|
end
|
19
19
|
|
20
20
|
test 'accepted user cannot remove his account (by using the original invitation token)' do
|
21
|
-
user = User.invite!(:
|
21
|
+
user = User.invite!(email: 'valid@email.com')
|
22
22
|
saved_token = Thread.current[:token]
|
23
23
|
user.accept_invitation!
|
24
24
|
|
25
|
-
visit remove_user_invitation_path(:
|
25
|
+
visit remove_user_invitation_path(invitation_token: saved_token)
|
26
26
|
assert_equal root_path, current_path
|
27
|
-
assert page.has_css?('p#alert', :
|
27
|
+
assert page.has_css?('p#alert', text: 'The invitation token provided is not valid!')
|
28
28
|
end
|
29
29
|
end
|
@@ -9,18 +9,18 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
9
9
|
def send_invitation(url = new_user_invitation_path, &block)
|
10
10
|
visit url
|
11
11
|
|
12
|
-
fill_in 'user_email', :
|
12
|
+
fill_in 'user_email', with: 'user@test.com'
|
13
13
|
yield if block_given?
|
14
14
|
click_button 'Send an invitation'
|
15
15
|
end
|
16
16
|
|
17
|
-
def set_password(options={}, &block)
|
17
|
+
def set_password(options = {}, &block)
|
18
18
|
unless options[:visit] == false
|
19
|
-
visit accept_user_invitation_path(:
|
19
|
+
visit accept_user_invitation_path(invitation_token: options[:invitation_token])
|
20
20
|
end
|
21
21
|
|
22
|
-
fill_in 'user_password', :
|
23
|
-
fill_in 'user_password_confirmation', :
|
22
|
+
fill_in 'user_password', with: '987654321'
|
23
|
+
fill_in 'user_password_confirmation', with: '987654321'
|
24
24
|
yield if block_given?
|
25
25
|
click_button options[:button] || 'Set my password'
|
26
26
|
end
|
@@ -28,7 +28,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
28
28
|
test 'not authenticated user should be able to send a free invitation' do
|
29
29
|
send_invitation new_free_invitation_path
|
30
30
|
assert_equal root_path, current_path
|
31
|
-
assert page.has_css?('p#notice', :
|
31
|
+
assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
|
32
32
|
end
|
33
33
|
|
34
34
|
test 'not authenticated user should not be able to send an invitation' do
|
@@ -41,19 +41,19 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
41
41
|
|
42
42
|
send_invitation
|
43
43
|
assert_equal root_path, current_path
|
44
|
-
assert page.has_css?('p#notice', :
|
44
|
+
assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
|
45
45
|
end
|
46
46
|
|
47
47
|
test 'authenticated user with existing email should receive an error message' do
|
48
48
|
user = create_full_user
|
49
49
|
sign_in_as_user(user)
|
50
50
|
send_invitation do
|
51
|
-
fill_in 'user_email', :
|
51
|
+
fill_in 'user_email', with: user.email
|
52
52
|
end
|
53
53
|
|
54
54
|
assert_equal user_invitation_path, current_path
|
55
55
|
assert page.has_css?("input[type=text][value='#{user.email}']")
|
56
|
-
assert page.has_css?('#error_explanation li', :
|
56
|
+
assert page.has_css?('#error_explanation li', text: 'Email has already been taken')
|
57
57
|
end
|
58
58
|
|
59
59
|
test 'authenticated user should not be able to visit edit invitation page' do
|
@@ -65,63 +65,63 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
65
65
|
end
|
66
66
|
|
67
67
|
test 'invited user without password should not be able to sign in' do
|
68
|
-
user = User.invite!(:
|
68
|
+
user = User.invite!(email: 'valid@email.com')
|
69
69
|
user.password = 'test'
|
70
70
|
sign_in_as_user user
|
71
71
|
|
72
72
|
assert_equal new_user_session_path, current_path
|
73
|
-
assert page.has_css?('p#alert', :
|
73
|
+
assert page.has_css?('p#alert', text: 'You have a pending invitation, accept it to finish creating your account.')
|
74
74
|
end
|
75
75
|
|
76
76
|
test 'invited user with password should not be able to sign in' do
|
77
|
-
user = User.invite!(:
|
77
|
+
user = User.invite!(email: 'valid@email.com')
|
78
78
|
user.password = '987654321'
|
79
79
|
user.save
|
80
80
|
sign_in_as_user user
|
81
81
|
|
82
82
|
assert_equal new_user_session_path, current_path
|
83
|
-
assert page.has_css?('p#alert', :
|
83
|
+
assert page.has_css?('p#alert', text: 'You have a pending invitation, accept it to finish creating your account.')
|
84
84
|
end
|
85
85
|
|
86
86
|
test 'not authenticated user with invalid invitation token should not be able to set his password' do
|
87
|
-
user = User.invite!(:
|
87
|
+
user = User.invite!(email: 'valid@email.com')
|
88
88
|
user.accept_invitation!
|
89
|
-
visit accept_user_invitation_path(:
|
89
|
+
visit accept_user_invitation_path(invitation_token: 'invalid_token')
|
90
90
|
|
91
91
|
assert_equal root_path, current_path
|
92
|
-
assert page.has_css?('p#alert', :
|
92
|
+
assert page.has_css?('p#alert', text: 'The invitation token provided is not valid!')
|
93
93
|
end
|
94
94
|
|
95
95
|
test 'not authenticated user with valid invitation token but invalid password should not be able to set his password' do
|
96
|
-
user = User.invite!(:
|
97
|
-
set_password :
|
98
|
-
fill_in 'Password confirmation', :
|
96
|
+
user = User.invite!(email: 'valid@email.com')
|
97
|
+
set_password invitation_token: Thread.current[:token] do
|
98
|
+
fill_in 'Password confirmation', with: 'other_password'
|
99
99
|
end
|
100
100
|
assert_equal user_invitation_path, current_path
|
101
|
-
assert page.has_css?('#error_explanation li', :
|
101
|
+
assert page.has_css?('#error_explanation li', text: /Password .*doesn\'t match/)
|
102
102
|
assert !user.confirmed?
|
103
103
|
end
|
104
104
|
|
105
105
|
test 'not authenticated user with valid data should be able to change his password' do
|
106
|
-
user = User.invite!(:
|
107
|
-
set_password :
|
106
|
+
user = User.invite!(email: 'valid@email.com')
|
107
|
+
set_password invitation_token: Thread.current[:token]
|
108
108
|
|
109
109
|
assert_equal root_path, current_path
|
110
|
-
assert page.has_css?('p#notice', :
|
110
|
+
assert page.has_css?('p#notice', text: 'Your password was set successfully. You are now signed in.')
|
111
111
|
assert user.reload.valid_password?('987654321')
|
112
112
|
assert user.confirmed?
|
113
113
|
end
|
114
114
|
|
115
115
|
test 'after entering invalid data user should still be able to set his password' do
|
116
|
-
user = User.invite!(:
|
117
|
-
set_password :
|
118
|
-
fill_in 'Password confirmation', :
|
116
|
+
user = User.invite!(email: 'valid@email.com')
|
117
|
+
set_password invitation_token: Thread.current[:token] do
|
118
|
+
fill_in 'Password confirmation', with: 'other_password'
|
119
119
|
end
|
120
120
|
assert_equal user_invitation_path, current_path
|
121
121
|
assert page.has_css?('#error_explanation')
|
122
122
|
|
123
|
-
set_password :
|
124
|
-
assert page.has_css?('p#notice', :
|
123
|
+
set_password visit: false
|
124
|
+
assert page.has_css?('p#notice', text: 'Your password was set successfully. You are now signed in.')
|
125
125
|
assert user.reload.valid_password?('987654321')
|
126
126
|
end
|
127
127
|
|
@@ -129,8 +129,8 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
129
129
|
original_option_value = Devise.allow_insecure_sign_in_after_accept
|
130
130
|
Devise.allow_insecure_sign_in_after_accept = true
|
131
131
|
|
132
|
-
User.invite!(:
|
133
|
-
set_password :
|
132
|
+
User.invite!(email: 'valid@email.com')
|
133
|
+
set_password invitation_token: Thread.current[:token]
|
134
134
|
|
135
135
|
assert_equal root_path, current_path
|
136
136
|
Devise.allow_insecure_sign_in_after_accept = original_option_value
|
@@ -140,22 +140,22 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
140
140
|
original_option_value = Devise.allow_insecure_sign_in_after_accept
|
141
141
|
Devise.allow_insecure_sign_in_after_accept = false
|
142
142
|
|
143
|
-
User.invite!(:
|
144
|
-
set_password :
|
143
|
+
User.invite!(email: 'valid@email.com')
|
144
|
+
set_password invitation_token: Thread.current[:token]
|
145
145
|
|
146
146
|
assert_equal new_user_session_path, current_path
|
147
147
|
Devise.allow_insecure_sign_in_after_accept = original_option_value
|
148
148
|
end
|
149
149
|
|
150
150
|
test 'clear token and set invitation_accepted_at after recover password instead of accept_invitation' do
|
151
|
-
user = User.invite!(:
|
151
|
+
user = User.invite!(email: 'valid@email.com')
|
152
152
|
|
153
153
|
visit new_user_password_path
|
154
|
-
fill_in 'user_email', :
|
154
|
+
fill_in 'user_email', with: 'valid@email.com'
|
155
155
|
click_button 'Send me reset password instructions'
|
156
156
|
|
157
|
-
visit edit_user_password_path(:
|
158
|
-
set_password :
|
157
|
+
visit edit_user_password_path(reset_password_token: Thread.current[:token])
|
158
|
+
set_password visit: false, button: 'Change my password'
|
159
159
|
|
160
160
|
user.reload
|
161
161
|
assert_nil user.invitation_token
|
@@ -174,7 +174,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
174
174
|
send_invitation
|
175
175
|
end
|
176
176
|
assert_equal root_path, current_path
|
177
|
-
assert page.has_css?('p#notice', :
|
177
|
+
assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
|
178
178
|
user = User.find(user.id)
|
179
179
|
assert !user.has_invitations_left?
|
180
180
|
end
|
@@ -191,7 +191,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
191
191
|
send_invitation
|
192
192
|
end
|
193
193
|
assert_equal user_invitation_path, current_path
|
194
|
-
assert page.has_css?('p#alert', :
|
194
|
+
assert page.has_css?('p#alert', text: 'No invitations remaining')
|
195
195
|
end
|
196
196
|
|
197
197
|
test 'user with nil invitation_limit should default to User.invitation_limit' do
|
@@ -204,7 +204,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
204
204
|
|
205
205
|
send_invitation
|
206
206
|
assert_equal root_path, current_path
|
207
|
-
assert page.has_css?('p#notice', :
|
207
|
+
assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
|
208
208
|
user = User.find(user.id)
|
209
209
|
assert_equal 2, user.invitation_limit
|
210
210
|
end
|
@@ -219,13 +219,13 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
219
219
|
|
220
220
|
send_invitation
|
221
221
|
assert_equal root_path, current_path
|
222
|
-
assert page.has_css?('p#notice', :
|
222
|
+
assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
|
223
223
|
user = User.find(user.id)
|
224
224
|
assert_equal 2, user.invitation_limit
|
225
225
|
|
226
226
|
send_invitation
|
227
227
|
assert_equal root_path, current_path
|
228
|
-
assert page.has_css?('p#notice', :
|
228
|
+
assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
|
229
229
|
user = User.find(user.id)
|
230
230
|
assert_equal 2, user.invitation_limit
|
231
231
|
end
|
@@ -235,7 +235,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
235
235
|
sign_in_as_user(user)
|
236
236
|
send_invitation
|
237
237
|
|
238
|
-
invited_user = User.where(:
|
238
|
+
invited_user = User.where(email: 'user@test.com').first
|
239
239
|
assert invited_user
|
240
240
|
assert_equal user, invited_user.invited_by
|
241
241
|
end
|
@@ -248,20 +248,20 @@ class InvitationTest < ActionDispatch::IntegrationTest
|
|
248
248
|
end
|
249
249
|
|
250
250
|
test 'authenticated admin should be able to send an admin invitation' do
|
251
|
-
admin = Admin.create(:
|
251
|
+
admin = Admin.create(email: 'admin@test.com', password: '123456', password_confirmation: '123456')
|
252
252
|
sign_in_as_user admin
|
253
253
|
|
254
254
|
send_invitation new_admin_path
|
255
255
|
assert_equal root_path, current_path
|
256
|
-
assert page.has_css?('p#notice', :
|
256
|
+
assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
|
257
257
|
end
|
258
258
|
|
259
259
|
test 'authenticated admin should be redirected to own page after send a free invitation' do
|
260
|
-
admin = Admin.create(:
|
260
|
+
admin = Admin.create(email: 'admin@test.com', password: '123456', password_confirmation: '123456')
|
261
261
|
sign_in_as_user admin
|
262
262
|
|
263
263
|
send_invitation new_free_invitation_path
|
264
264
|
assert_equal root_path, current_path
|
265
|
-
assert page.has_css?('p#notice', :
|
265
|
+
assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
|
266
266
|
end
|
267
267
|
end
|
@@ -7,11 +7,11 @@ class ActionDispatch::IntegrationTest
|
|
7
7
|
def create_full_user
|
8
8
|
@user ||= begin
|
9
9
|
user = User.create!(
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
10
|
+
username: 'usertest',
|
11
|
+
email: 'fulluser@test.com',
|
12
|
+
password: '123456',
|
13
|
+
password_confirmation: '123456',
|
14
|
+
created_at: Time.now.utc,
|
15
15
|
)
|
16
16
|
user.confirm
|
17
17
|
user
|
@@ -22,20 +22,19 @@ class ActionDispatch::IntegrationTest
|
|
22
22
|
user ||= create_full_user
|
23
23
|
resource_name = user.class.name.underscore
|
24
24
|
visit send("new_#{resource_name}_session_path")
|
25
|
-
fill_in "#{resource_name}_email", :
|
26
|
-
fill_in "#{resource_name}_password", :
|
25
|
+
fill_in "#{resource_name}_email", with: user.email
|
26
|
+
fill_in "#{resource_name}_password", with: user.password
|
27
27
|
click_button 'Log in'
|
28
28
|
end
|
29
29
|
|
30
30
|
# Fix assert_redirect_to in integration sessions because they don't take into
|
31
31
|
# account Middleware redirects.
|
32
|
-
#
|
33
32
|
def assert_redirected_to(url)
|
34
33
|
assert [301, 302].include?(@integration_session.status),
|
35
34
|
"Expected status to be 301 or 302, got #{@integration_session.status}"
|
36
35
|
|
37
36
|
url = prepend_host(url)
|
38
|
-
location = prepend_host(@integration_session.headers[
|
37
|
+
location = prepend_host(@integration_session.headers['Location'])
|
39
38
|
assert_equal url, location
|
40
39
|
end
|
41
40
|
|