goma 0.0.1.rc2 → 0.0.1.rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Rakefile +11 -6
- data/lib/generators/goma/helpers/helpers.rb +39 -0
- data/lib/generators/goma/install/templates/goma.rb +1 -2
- data/lib/generators/goma/mailer/templates/mailer.rb +1 -1
- data/lib/generators/goma/model/active_record_generator.rb +3 -1
- data/lib/generators/goma/scaffold/user_generator.rb +2 -0
- data/lib/generators/goma/scaffold_controller/scaffold_controller_generator.rb +2 -0
- data/lib/generators/goma/scaffold_controller/templates/confirmation_controller.rb +4 -4
- data/lib/generators/goma/scaffold_controller/templates/user_controller.rb +3 -3
- data/lib/generators/test_unit/goma/model/model_generator.rb +13 -0
- data/lib/generators/test_unit/goma/model/templates/fixtures.yml +30 -0
- data/lib/generators/test_unit/goma/model/templates/unit_test.rb +9 -0
- data/lib/generators/test_unit/goma/scaffold/scaffold_generator.rb +36 -0
- data/lib/generators/test_unit/goma/scaffold/templates/confirmation_functional_test.rb +137 -0
- data/lib/generators/test_unit/goma/scaffold/templates/functional_test.rb +51 -0
- data/lib/generators/test_unit/goma/scaffold/templates/oauth_functional_test.rb +6 -0
- data/lib/generators/test_unit/goma/scaffold/templates/password_functional_test.rb +67 -0
- data/lib/generators/test_unit/goma/scaffold/templates/session_functional_test.rb +122 -0
- data/lib/generators/test_unit/goma/scaffold/templates/unlock_functional_test.rb +47 -0
- data/lib/generators/test_unit/goma/scaffold/templates/user_functional_test.rb +118 -0
- data/lib/goma.rb +1 -1
- data/lib/goma/config.rb +0 -1
- data/lib/goma/controller_test_helpers.rb +65 -0
- data/lib/goma/controllers.rb +1 -1
- data/lib/goma/models/authenticatable.rb +20 -11
- data/lib/goma/models/confirmable.rb +1 -1
- data/lib/goma/models/lockable.rb +1 -2
- data/lib/goma/version.rb +1 -1
- data/test/models/lockable_test.rb +0 -2
- data/test/rails_app/app/controllers/confirmations_controller.rb +4 -4
- data/test/rails_app/app/controllers/users_controller.rb +3 -3
- data/test/rails_app/app/mailers/user_mailer.rb +1 -1
- data/test/rails_app/config/initializers/goma.rb +1 -2
- data/test/rails_app/db/migrate/{20140515111009_create_users.rb → 20140524062919_create_users.rb} +0 -1
- data/test/rails_app/db/migrate/{20140515111010_create_authentications.rb → 20140524062920_create_authentications.rb} +0 -0
- data/test/rails_app/db/schema.rb +1 -2
- data/test/rails_app/test/controllers/authentications_controller_test.rb +4 -0
- data/test/rails_app/test/controllers/confirmations_controller_test.rb +127 -0
- data/test/rails_app/test/controllers/passwords_controller_test.rb +65 -0
- data/test/rails_app/test/controllers/sessions_controller_test.rb +70 -0
- data/test/rails_app/test/controllers/unlocks_controller_test.rb +43 -0
- data/test/rails_app/test/controllers/users_controller_test.rb +109 -0
- data/test/rails_app/test/fixtures/authentications.yml +11 -0
- data/test/rails_app/test/fixtures/users.yml +17 -0
- data/test/rails_app/test/helpers/authentications_helper_test.rb +4 -0
- data/test/rails_app/test/helpers/confirmations_helper_test.rb +4 -0
- data/test/rails_app/test/helpers/passwords_helper_test.rb +4 -0
- data/test/rails_app/test/helpers/sessions_helper_test.rb +4 -0
- data/test/rails_app/test/helpers/unlocks_helper_test.rb +4 -0
- data/test/rails_app/test/helpers/users_helper_test.rb +4 -0
- data/test/rails_app/test/mailers/user_mailer_test.rb +7 -0
- data/test/rails_app/test/models/authentication_test.rb +7 -0
- data/test/rails_app/test/models/user_test.rb +7 -0
- data/test/rails_app/test/test_helper.rb +16 -0
- data/test/test_helper.rb +1 -1
- metadata +54 -7
- data/lib/goma/test_helpers.rb +0 -67
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
@<%= singular_table_name %> = <%= table_name %>(:one)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should get index" do
|
10
|
+
get :index
|
11
|
+
assert_response :success
|
12
|
+
assert_not_nil assigns(:<%= table_name %>)
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should get new" do
|
16
|
+
get :new
|
17
|
+
assert_response :success
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should create <%= singular_table_name %>" do
|
21
|
+
assert_difference('<%= class_name %>.count') do
|
22
|
+
post :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
|
26
|
+
end
|
27
|
+
|
28
|
+
test "should show <%= singular_table_name %>" do
|
29
|
+
get :show, id: <%= "@#{singular_table_name}" %>
|
30
|
+
assert_response :success
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should get edit" do
|
34
|
+
get :edit, id: <%= "@#{singular_table_name}" %>
|
35
|
+
assert_response :success
|
36
|
+
end
|
37
|
+
|
38
|
+
test "should update <%= singular_table_name %>" do
|
39
|
+
patch :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
|
40
|
+
assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
|
41
|
+
end
|
42
|
+
|
43
|
+
test "should destroy <%= singular_table_name %>" do
|
44
|
+
assert_difference('<%= class_name %>.count', -1) do
|
45
|
+
delete :destroy, id: <%= "@#{singular_table_name}" %>
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_redirected_to <%= index_helper %>_path
|
49
|
+
end
|
50
|
+
end
|
51
|
+
<% end -%>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
@<%= resource_name %> = <%= resource_name.pluralize %>(:one)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should get new" do
|
10
|
+
get :new
|
11
|
+
assert_response :success
|
12
|
+
end
|
13
|
+
|
14
|
+
test "should resend reset password token with <%= goma_config.email_attribute_name %>" do
|
15
|
+
@<%= resource_name %>.send_reset_password_instructions!
|
16
|
+
<%= goma_config.reset_password_token_attribute_name %> = @<%= resource_name %>.<%= goma_config.unlock_token_attribute_name %>
|
17
|
+
assert_difference 'ActionMailer::Base.deliveries.size', 1 do
|
18
|
+
post :create, <%= goma_config.authentication_keys.to_field_name %>: @<%= resource_name %>.<%= goma_config.email_attribute_name %>
|
19
|
+
end
|
20
|
+
assert_redirected_to <%= login_url %>
|
21
|
+
@<%= resource_name %>.reload
|
22
|
+
assert_not_equal <%= goma_config.reset_password_token_attribute_name %>, @<%= resource_name %>.<%= goma_config.reset_password_token_attribute_name %>
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
test "should get edit" do
|
27
|
+
@<%= resource_name %>.send_reset_password_instructions!
|
28
|
+
<%= goma_config.reset_password_token_to_send_attribute_name %> = @<%= resource_name %>.<%= goma_config.reset_password_token_to_send_attribute_name %>
|
29
|
+
get :edit, id: <%= goma_config.reset_password_token_to_send_attribute_name %>
|
30
|
+
assert_response :success
|
31
|
+
assert_match /<input[^>]*type="hidden"[^>]*value="#{<%= goma_config.reset_password_token_to_send_attribute_name %>}"/, response.body
|
32
|
+
end
|
33
|
+
|
34
|
+
test "should update password" do
|
35
|
+
@<%= resource_name %>.send_reset_password_instructions!
|
36
|
+
<%= goma_config.reset_password_token_to_send_attribute_name %> = @<%= resource_name %>.<%= goma_config.reset_password_token_to_send_attribute_name %>
|
37
|
+
patch :update, id: <%= goma_config.reset_password_token_to_send_attribute_name %>, <%= resource_name %>: { <%= goma_config.reset_password_token_to_send_attribute_name %>: <%= goma_config.reset_password_token_to_send_attribute_name %>, <%= goma_config.password_attribute_name %>: 'newpassword', <%= goma_config.password_confirmation_attribute_name %>: 'newpassword' }
|
38
|
+
assert_redirected_to root_path
|
39
|
+
@<%= resource_name %>.reload
|
40
|
+
assert @<%= resource_name %>.valid_password? 'newpassword'
|
41
|
+
refute @<%= resource_name %>.valid_password? 'password'
|
42
|
+
end
|
43
|
+
|
44
|
+
test "should not update password with wrong token" do
|
45
|
+
@<%= resource_name %>.send_reset_password_instructions!
|
46
|
+
<%= goma_config.reset_password_token_to_send_attribute_name %> = @<%= resource_name %>.<%= goma_config.reset_password_token_to_send_attribute_name %>
|
47
|
+
patch :update, id: <%= goma_config.reset_password_token_to_send_attribute_name %>, <%= resource_name %>: { <%= goma_config.reset_password_token_to_send_attribute_name %>: 'oops', <%= goma_config.password_attribute_name %>: 'newpassword', <%= goma_config.password_confirmation_attribute_name %>: 'newpassword' }
|
48
|
+
assert_template :edit
|
49
|
+
assert_match /make sure you used the full URL provided/, flash[:alert]
|
50
|
+
@<%= resource_name %>.reload
|
51
|
+
refute @<%= resource_name %>.valid_password? 'newpassword'
|
52
|
+
assert @<%= resource_name %>.valid_password? 'password'
|
53
|
+
end
|
54
|
+
|
55
|
+
test "should not update password with expired token" do
|
56
|
+
@<%= resource_name %>.send_reset_password_instructions!
|
57
|
+
<%= goma_config.reset_password_token_to_send_attribute_name %> = @<%= resource_name %>.<%= goma_config.reset_password_token_to_send_attribute_name %>
|
58
|
+
@<%= resource_name %>.update_column(:<%= goma_config.reset_password_token_sent_at_attribute_name %>, <%= expire(goma_config.reset_password_within) %>.ago)
|
59
|
+
patch :update, id: <%= goma_config.reset_password_token_to_send_attribute_name %>, <%= resource_name %>: { <%= goma_config.reset_password_token_to_send_attribute_name %>: <%= goma_config.reset_password_token_to_send_attribute_name %>, <%= goma_config.password_attribute_name %>: 'newpassword', <%= goma_config.password_confirmation_attribute_name %>: 'newpassword' }
|
60
|
+
assert_template :new
|
61
|
+
assert_match /The password reset URL you visited has expired/, flash[:alert]
|
62
|
+
@<%= resource_name %>.reload
|
63
|
+
refute @<%= resource_name %>.valid_password? 'newpassword'
|
64
|
+
assert @<%= resource_name %>.valid_password? 'password'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
<% end -%>
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
@<%= resource_name %> = <%= resource_name.pluralize %>(:one)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should get new" do
|
10
|
+
get :new
|
11
|
+
assert_response :success
|
12
|
+
end
|
13
|
+
|
14
|
+
<% goma_config.authentication_keys.each do |key| -%>
|
15
|
+
test "should login with <%= key %>" do
|
16
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
17
|
+
refute logged_in?
|
18
|
+
<% else -%>
|
19
|
+
refute <%= resource_name %>_logged_in?
|
20
|
+
<% end -%>
|
21
|
+
post :create, <%= "#{goma_config.authentication_keys.to_field_name}: @#{resource_name}.#{key}, #{goma_config.password_attribute_name}: 'password'" %>
|
22
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
23
|
+
assert logged_in?
|
24
|
+
<% else -%>
|
25
|
+
assert <%= resource_name %>_logged_in?
|
26
|
+
<% end -%>
|
27
|
+
assert_redirected_to root_path
|
28
|
+
assert_match /Login successful/, flash[:notice]
|
29
|
+
end
|
30
|
+
|
31
|
+
test "should not login with <%= key %> with wrong password" do
|
32
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
33
|
+
refute logged_in?
|
34
|
+
<% else -%>
|
35
|
+
refute <%= resource_name %>_logged_in?
|
36
|
+
<% end -%>
|
37
|
+
post :create, <%= "#{goma_config.authentication_keys.to_field_name}: @#{resource_name}.#{key}, #{goma_config.password_attribute_name}: 'wrongpass'" %>
|
38
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
39
|
+
refute logged_in?
|
40
|
+
<% else -%>
|
41
|
+
refute <%= resource_name %>_logged_in?
|
42
|
+
<% end -%>
|
43
|
+
assert_template :new
|
44
|
+
assert_match /Login failed/, flash[:alert]
|
45
|
+
end
|
46
|
+
|
47
|
+
<% if goma_config.modules.include? :confirmable -%>
|
48
|
+
<% if goma_config.allow_unactivated_access_for > 0 -%>
|
49
|
+
test "should login unactivated <%= resource_name %> with <%= key %> for <%= goma_config.allow_unactivated_access_for %>" do
|
50
|
+
unactivated_<%= resource_name %> = <%= resource_name.pluralize %>(:unactivated_<%= resource_name %>)
|
51
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
52
|
+
refute logged_in?
|
53
|
+
<% else -%>
|
54
|
+
refute <%= resource_name %>_logged_in?
|
55
|
+
<% end -%>
|
56
|
+
post :create, <%= "#{goma_config.authentication_keys.to_field_name}: @#{resource_name}.#{key}, #{goma_config.password_attribute_name}: 'password'" %>
|
57
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
58
|
+
assert logged_in?
|
59
|
+
<% else -%>
|
60
|
+
assert <%= resource_name %>_logged_in?
|
61
|
+
<% end -%>
|
62
|
+
assert_redirected_to root_path
|
63
|
+
assert_match /Login successful/, flash[:alert]
|
64
|
+
end
|
65
|
+
|
66
|
+
test "should not login unactivated <%= resource_name %> with <%= key %> <%= goma_config.allow_unactivated_access_for %> passed after registration" do
|
67
|
+
unactivated_<%= resource_name %> = <%= resource_name.pluralize %>(:unactivated_<%= resource_name %>)
|
68
|
+
unactivated_<%= resource_name %>.update_column(:created_at, <%= expire(goma_config.allow_unactivated_access_for) %>.ago)
|
69
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
70
|
+
refute logged_in?
|
71
|
+
<% else -%>
|
72
|
+
refute <%= resource_name %>_logged_in?
|
73
|
+
<% end -%>
|
74
|
+
post :create, <%= "#{goma_config.authentication_keys.to_field_name}: @#{resource_name}.#{key}, #{goma_config.password_attribute_name}: 'password'" %>
|
75
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
76
|
+
refute logged_in?
|
77
|
+
<% else -%>
|
78
|
+
refute <%= resource_name %>_logged_in?
|
79
|
+
<% end -%>
|
80
|
+
assert_template :new
|
81
|
+
assert_match /Not activated/, flash[:alert]
|
82
|
+
end
|
83
|
+
|
84
|
+
<% else -%>
|
85
|
+
test "should not login unactivated <%= resource_name %> with <%= key %>" do
|
86
|
+
unactivated_<%= resource_name %> = <%= resource_name.pluralize %>(:unactivated_<%= resource_name %>)
|
87
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
88
|
+
refute logged_in?
|
89
|
+
<% else -%>
|
90
|
+
refute <%= resource_name %>_logged_in?
|
91
|
+
<% end -%>
|
92
|
+
post :create, <%= "#{goma_config.authentication_keys.to_field_name}: unactivated_#{resource_name}.#{key}, #{goma_config.password_attribute_name}: 'password'" %>
|
93
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
94
|
+
refute logged_in?
|
95
|
+
<% else -%>
|
96
|
+
refute <%= resource_name %>_logged_in?
|
97
|
+
<% end -%>
|
98
|
+
assert_template :new
|
99
|
+
assert_match /Not activated/, flash[:alert]
|
100
|
+
end
|
101
|
+
<% end # if goma_config.allow_unactivated_access_for > 0 -%>
|
102
|
+
<% end # if goma_config.modules.include? :confirmable -%>
|
103
|
+
<% end # goma_config.authentication_keys.each do |key| -%>
|
104
|
+
|
105
|
+
test "should logout <%= resource_name %>" do
|
106
|
+
force_login(@<%= resource_name %>)
|
107
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
108
|
+
assert logged_in?
|
109
|
+
<% else -%>
|
110
|
+
assert <%= resource_name %>_logged_in?
|
111
|
+
<% end -%>
|
112
|
+
delete :destroy, id: <%= "@#{resource_name}" %>
|
113
|
+
assert_redirected_to root_path
|
114
|
+
assert_match /Logged out/, flash[:notice]
|
115
|
+
<% if resource_name.to_sym == goma_config.default_scope -%>
|
116
|
+
refute logged_in?
|
117
|
+
<% else -%>
|
118
|
+
refute <%= resource_name %>_logged_in?
|
119
|
+
<% end -%>
|
120
|
+
end
|
121
|
+
end
|
122
|
+
<% end -%>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
5
|
+
<% if goma_config.unlock_strategies.include? :email -%>
|
6
|
+
setup do
|
7
|
+
@<%= resource_name %> = <%= resource_name.pluralize %>(:one)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "should get new" do
|
11
|
+
get :new
|
12
|
+
assert_response :success
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should resend unlock token with <%= goma_config.email_attribute_name %>" do
|
16
|
+
@<%= resource_name %>.lock_access!
|
17
|
+
<%= goma_config.unlock_token_attribute_name %> = @<%= resource_name %>.<%= goma_config.unlock_token_attribute_name %>
|
18
|
+
assert_difference 'ActionMailer::Base.deliveries.size', 1 do
|
19
|
+
post :create, <%= goma_config.authentication_keys.to_field_name %>: @<%= resource_name %>.<%= goma_config.email_attribute_name %>
|
20
|
+
end
|
21
|
+
assert_redirected_to <%= login_url %>
|
22
|
+
@<%= resource_name %>.reload
|
23
|
+
assert_not_equal <%= goma_config.unlock_token_attribute_name %>, @<%= resource_name %>.<%= goma_config.unlock_token_attribute_name %>
|
24
|
+
end
|
25
|
+
|
26
|
+
test "should unlock <%= resource_name %>" do
|
27
|
+
@<%= resource_name %>.lock_access!
|
28
|
+
<%= goma_config.unlock_token_to_send_attribute_name %> = @<%= resource_name%>.<%= goma_config.unlock_token_to_send_attribute_name %>
|
29
|
+
get :show, id: <%= goma_config.unlock_token_to_send_attribute_name %>
|
30
|
+
assert_redirected_to <%= login_url %>
|
31
|
+
assert_match /Your account has been unlocked successfully/, flash[:notice]
|
32
|
+
@<%= resource_name %>.reload
|
33
|
+
refute @<%=resource_name %>.access_locked?
|
34
|
+
end
|
35
|
+
|
36
|
+
test "should not unlock <%= resource_name %> with wrong token" do
|
37
|
+
@<%= resource_name %>.lock_access!
|
38
|
+
<%= goma_config.unlock_token_to_send_attribute_name %> = @<%= resource_name%>.<%= goma_config.unlock_token_to_send_attribute_name %>
|
39
|
+
get :show, id: 'oops'
|
40
|
+
assert_template :new
|
41
|
+
assert_match /Not found any account by this URL/, flash[:alert]
|
42
|
+
@<%= resource_name %>.reload
|
43
|
+
assert @<%=resource_name %>.access_locked?
|
44
|
+
end
|
45
|
+
<% end -%>
|
46
|
+
end
|
47
|
+
<% end -%>
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
@<%= singular_table_name %> = <%= table_name %>(:one)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "should get index" do
|
10
|
+
get :index
|
11
|
+
assert_response :success
|
12
|
+
assert_not_nil assigns(:<%= table_name %>)
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should get new" do
|
16
|
+
get :new
|
17
|
+
assert_response :success
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should create <%= singular_table_name %>" do
|
21
|
+
assert_difference('<%= class_name %>.count') do
|
22
|
+
post :create, <%= "#{singular_table_name}: #{new_resource_attributes.inspect19}" %>
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_redirected_to <%= login_path %>
|
26
|
+
end
|
27
|
+
|
28
|
+
test "should show <%= singular_table_name %>" do
|
29
|
+
get :show, id: <%= "@#{singular_table_name}" %>
|
30
|
+
assert_response :success
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should not get edit unless logged in" do
|
34
|
+
get :edit, id: <%= "@#{singular_table_name}" %>
|
35
|
+
assert_redirected_to root_path
|
36
|
+
assert_match /Login required/, flash[:alert]
|
37
|
+
end
|
38
|
+
|
39
|
+
test "should get edit" do
|
40
|
+
force_login(@user)
|
41
|
+
get :edit, id: <%= "@#{singular_table_name}" %>
|
42
|
+
assert_response :success
|
43
|
+
end
|
44
|
+
|
45
|
+
test "should not get edit of another user" do
|
46
|
+
force_login(@<%= singular_table_name %>)
|
47
|
+
get :edit, id: <%= table_name %>(:two)
|
48
|
+
assert_redirected_to root_url
|
49
|
+
end
|
50
|
+
|
51
|
+
<% if goma_config.modules.include? :confirmable -%>
|
52
|
+
test "should not update <%= goma_config.email_attribute_name %> unless logged in" do
|
53
|
+
original_email = @<%= singular_table_name %>.<%= goma_config.email_attribute_name %>
|
54
|
+
patch :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{goma_config.email_attribute_name}: 'new@example.com' }" %>
|
55
|
+
assert_redirected_to root_path
|
56
|
+
assert_match /Login required/, flash[:alert]
|
57
|
+
@<%= singular_table_name %>.reload
|
58
|
+
assert_equal original_email, @<%= singular_table_name %>.<%= goma_config.email_attribute_name %>
|
59
|
+
assert_equal nil, @<%= singular_table_name %>.<%= goma_config.unconfirmed_email_attribute_name %>
|
60
|
+
end
|
61
|
+
|
62
|
+
test "should confirm <%= goma_config.email_attribute_name %> before update" do
|
63
|
+
force_login(@<%= singular_table_name %>)
|
64
|
+
original_email = @<%= singular_table_name %>.<%= goma_config.email_attribute_name %>
|
65
|
+
assert_difference 'ActionMailer::Base.deliveries.size', 1 do
|
66
|
+
patch :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{goma_config.email_attribute_name}: 'new@example.com' }" %>
|
67
|
+
end
|
68
|
+
assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
|
69
|
+
assert_match /we need to verify your new email address/, flash[:notice]
|
70
|
+
@<%= singular_table_name %>.reload
|
71
|
+
assert_equal original_email, @<%= singular_table_name %>.<%= goma_config.email_attribute_name %>
|
72
|
+
assert_equal 'new@example.com', @<%= singular_table_name %>.<%= goma_config.unconfirmed_email_attribute_name %>
|
73
|
+
end
|
74
|
+
|
75
|
+
<% auth_keys = goma_config.authentication_keys - [goma_config.email_attribute_name] -%>
|
76
|
+
<% else -%>
|
77
|
+
<% auth_keys = goma_config.authentication_keys -%>
|
78
|
+
<% end -%>
|
79
|
+
<% auth_keys.each do |key| -%>
|
80
|
+
<% new_value = key == goma_config.email_attribute_name ? 'new@example.com' : "new_#{key}" %>
|
81
|
+
test "should not update <%= key %> unless logged in" do
|
82
|
+
original = @<%= singular_table_name %>.<%= key %>
|
83
|
+
patch :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{key}: '#{new_value}' }" %>
|
84
|
+
assert_redirected_to root_path
|
85
|
+
@<%= singular_table_name %>.reload
|
86
|
+
assert_equal original, @<%= singular_table_name %>.<%= key %>
|
87
|
+
assert_match /Login required/, flash[:alert]
|
88
|
+
end
|
89
|
+
|
90
|
+
test "should update <%= key %>" do
|
91
|
+
force_login(@<%= singular_table_name %>)
|
92
|
+
patch :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{key}: '#{new_value}' }" %>
|
93
|
+
assert_redirected_to <%= singular_table_name %>_path(assigns(:<%= singular_table_name %>))
|
94
|
+
@<%= singular_table_name %>.reload
|
95
|
+
assert_equal '<%= new_value %>', @<%= singular_table_name %>.<%= key %>
|
96
|
+
end
|
97
|
+
|
98
|
+
<% end -%>
|
99
|
+
|
100
|
+
test "should not destroy <%= singular_table_name %> unless logged in" do
|
101
|
+
assert_no_difference('<%= class_name %>.count') do
|
102
|
+
delete :destroy, id: <%= "@#{singular_table_name}" %>
|
103
|
+
end
|
104
|
+
|
105
|
+
assert_redirected_to root_path
|
106
|
+
assert_match /Login required/, flash[:alert]
|
107
|
+
end
|
108
|
+
|
109
|
+
test "should destroy <%= singular_table_name %>" do
|
110
|
+
force_login(@<%= singular_table_name %>)
|
111
|
+
assert_difference('<%= class_name %>.count', -1) do
|
112
|
+
delete :destroy, id: <%= "@#{singular_table_name}" %>
|
113
|
+
end
|
114
|
+
|
115
|
+
assert_redirected_to <%= index_helper %>_path
|
116
|
+
end
|
117
|
+
end
|
118
|
+
<% end -%>
|
data/lib/goma.rb
CHANGED
data/lib/goma/config.rb
CHANGED
@@ -109,7 +109,6 @@ module Goma
|
|
109
109
|
config_accessor(:locked_at_attribute_name) { :locked_at }
|
110
110
|
config_accessor(:unlock_in) { 1.hour }
|
111
111
|
config_accessor(:unlock_token_attribute_name) { :unlock_token }
|
112
|
-
config_accessor(:unlock_token_sent_at_attribute_name) { :unlock_token_sent_at }
|
113
112
|
config_accessor(:unlock_token_to_send_attribute_name) { :raw_unlock_token }
|
114
113
|
|
115
114
|
# Recoverable
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Goma
|
2
|
+
# Goma::ControllerTestHelpers provides a facility to test controllers in isolation
|
3
|
+
# Most of the code was extracted from Devise's Devise::TestHelpers.
|
4
|
+
module ControllerTestHelpers
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
setup :setup_controller_for_warden, :warden if respond_to?(:setup)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Override process to consider warden.
|
12
|
+
def process(*)
|
13
|
+
# Make sure we always return @response, a la ActionController::TestCase::Behavior#process, even if warden interrupts
|
14
|
+
_catch_warden {super} || @response
|
15
|
+
end
|
16
|
+
|
17
|
+
# We need to setup the environment variables and the response in the controller
|
18
|
+
def setup_controller_for_warden
|
19
|
+
@request.env['action_controller.instance'] = @controller
|
20
|
+
end
|
21
|
+
|
22
|
+
# Quick access to Warden::Proxy.
|
23
|
+
def warden
|
24
|
+
@warden ||= begin
|
25
|
+
manager = Warden::Manager.new(nil, &Rails.application.config.middleware.detect{|m| m.name == 'Warden::Manager'}.block)
|
26
|
+
@request.env['warden'] = Warden::Proxy.new(@request.env, manager)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
# Catch warden continuations and handle like the middleware would.
|
33
|
+
# Returns nil when interrupted, otherwise the normal result of the block.
|
34
|
+
def _catch_warden(&block)
|
35
|
+
result = catch(:warden, &block)
|
36
|
+
|
37
|
+
if result.is_a?(Hash) && !warden.custom_failure? && !@controller.send(:performed?)
|
38
|
+
result[:action] ||= :unauthenticated
|
39
|
+
|
40
|
+
env = @controller.request.env
|
41
|
+
env['PATH_INFO'] = "/#{result[:action]}"
|
42
|
+
env['warden.options'] = result
|
43
|
+
Warden::Manager._run_callbacks(:before_failure, env, result)
|
44
|
+
|
45
|
+
status, headers, body = warden.config[:failure_app].call(env).to_a
|
46
|
+
@controller.send :render, :status => status, :text => body,
|
47
|
+
:content_type => headers['Content-Type'], :location => headers['Location']
|
48
|
+
|
49
|
+
nil
|
50
|
+
else
|
51
|
+
result
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def method_missing(m, *args)
|
56
|
+
name = m.to_s
|
57
|
+
if name =~ /^(?:(#{Goma.config.scopes.join('|')})_)?(?:login!?|logout|logged_in\?)$/ || name == 'force_login' || name =~ /^current_(#{Goma.config.scopes.join('|')})$/
|
58
|
+
@controller.send(m, *args)
|
59
|
+
else
|
60
|
+
super
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|