typus 0.9.29 → 0.9.30
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.
- data/README.rdoc +4 -54
- data/VERSION +1 -1
- data/app/controllers/admin/master_controller.rb +36 -18
- data/app/helpers/admin/form_helper.rb +40 -7
- data/app/helpers/admin/table_helper.rb +6 -17
- data/app/views/admin/resources/show.html.erb +1 -2
- data/app/views/admin/templates/_file.html.erb +2 -40
- data/app/views/layouts/admin.html.erb +3 -0
- data/config/locales/de.yml +0 -1
- data/config/locales/es.yml +0 -1
- data/config/locales/fr.yml +0 -1
- data/config/locales/language.yml.template +0 -1
- data/config/locales/pt-BR.yml +0 -1
- data/config/locales/ru.yml +0 -1
- data/generators/typus/templates/public/stylesheets/admin/screen.css +1 -1
- data/generators/typus/typus_generator.rb +1 -1
- data/lib/typus/preview.rb +66 -2
- data/tasks/typus_tasks.rake +0 -2
- data/test/config/working/application.yml +9 -3
- data/test/config/working/application_roles.yml +3 -1
- data/test/fixtures/app/views/admin/{comments → posts}/_edit.html.erb +0 -0
- data/test/fixtures/app/views/admin/{comments → posts}/_index.html.erb +0 -0
- data/test/fixtures/app/views/admin/{comments → posts}/_new.html.erb +0 -0
- data/test/fixtures/app/views/admin/{comments → posts}/_show.html.erb +0 -0
- data/test/fixtures/app/views/admin/{comments → posts}/_sidebar.html.erb +0 -0
- data/test/functional/admin/{assets_controller_test.rb → master_controller_assets_relationships.rb} +23 -13
- data/test/functional/admin/master_controller_categories_lists_test.rb +64 -0
- data/test/functional/admin/master_controller_posts_before_test.rb +10 -0
- data/test/functional/admin/master_controller_posts_crud_test.rb +97 -0
- data/test/functional/admin/master_controller_posts_formats_test.rb +59 -0
- data/test/functional/admin/master_controller_posts_permissions_test.rb +127 -0
- data/test/functional/admin/master_controller_posts_relationships_test.rb +86 -0
- data/test/functional/admin/master_controller_posts_roles.rb +50 -0
- data/test/functional/admin/master_controller_posts_toggle_test.rb +35 -0
- data/test/functional/admin/master_controller_posts_views_test.rb +209 -0
- data/test/functional/admin/{status_controller_test.rb → master_controller_tableless_resource_test.rb} +5 -11
- data/test/functional/admin/{typus_users_controller_test.rb → master_controller_typus_users_test.rb} +10 -37
- data/test/functional/typus_controller_test.rb +154 -136
- data/test/helpers/admin/form_helper_test.rb +49 -27
- data/test/helpers/admin/sidebar_helper_test.rb +4 -7
- data/test/lib/active_record_test.rb +8 -8
- data/test/lib/typus_test.rb +1 -1
- data/test/models.rb +8 -1
- data/test/schema.rb +6 -0
- data/test/unit/typus_user_roles_test.rb +4 -4
- data/typus.gemspec +31 -21
- metadata +31 -21
- data/test/functional/admin/categories_controller_test.rb +0 -105
- data/test/functional/admin/comments_controller_test.rb +0 -121
- data/test/functional/admin/master_controller_test.rb +0 -51
- data/test/functional/admin/posts_controller_test.rb +0 -300
@@ -1,12 +1,9 @@
|
|
1
1
|
require 'test/helper'
|
2
2
|
|
3
|
-
# Test resources which are not related to an ActiveRecord model.
|
4
|
-
|
5
3
|
class Admin::StatusControllerTest < ActionController::TestCase
|
6
4
|
|
7
5
|
def setup
|
8
|
-
@
|
9
|
-
@request.session[:typus_user_id] = @typus_user.id
|
6
|
+
@request.session[:typus_user_id] = typus_users(:admin).id
|
10
7
|
end
|
11
8
|
|
12
9
|
def test_should_verify_admin_can_go_to_index
|
@@ -22,21 +19,18 @@ class Admin::StatusControllerTest < ActionController::TestCase
|
|
22
19
|
assert_redirected_to admin_sign_in_path(:back_to => '/admin/status')
|
23
20
|
end
|
24
21
|
|
25
|
-
def
|
22
|
+
def test_should_verify_admin_cannot_go_to_show
|
26
23
|
get :show
|
27
24
|
assert_response :redirect
|
28
25
|
assert_redirected_to admin_dashboard_path
|
29
|
-
|
30
|
-
assert_equal "#{@typus_user.role.capitalize} can't go to show on status.", flash[:notice]
|
26
|
+
assert_equal "Admin can't go to show on status.", flash[:notice]
|
31
27
|
end
|
32
28
|
|
33
29
|
def test_should_verify_editor_can_not_go_to_index
|
34
|
-
|
35
|
-
@request.session[:typus_user_id] = typus_user.id
|
30
|
+
@request.session[:typus_user_id] = typus_users(:editor).id
|
36
31
|
get :index
|
37
32
|
assert_response :redirect
|
38
|
-
|
39
|
-
assert_equal "#{typus_user.role.capitalize} can't go to index on status.", flash[:notice]
|
33
|
+
assert_equal "Editor can't go to index on status.", flash[:notice]
|
40
34
|
end
|
41
35
|
|
42
36
|
end
|
data/test/functional/admin/{typus_users_controller_test.rb → master_controller_typus_users_test.rb}
RENAMED
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'test/helper'
|
2
2
|
|
3
|
-
# Test what TypusUsers can do.
|
4
|
-
|
5
3
|
class Admin::TypusUsersControllerTest < ActionController::TestCase
|
6
4
|
|
7
5
|
def setup
|
8
6
|
Typus::Configuration.options[:root] = 'admin'
|
9
7
|
@typus_user = typus_users(:admin)
|
10
8
|
@request.session[:typus_user_id] = @typus_user.id
|
9
|
+
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
11
10
|
end
|
12
11
|
|
13
12
|
def test_should_allow_admin_to_create_typus_users
|
@@ -17,84 +16,69 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
17
16
|
|
18
17
|
def test_should_not_allow_admin_to_toggle_her_status
|
19
18
|
|
20
|
-
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
21
19
|
get :toggle, { :id => @typus_user.id, :field => 'status' }
|
22
20
|
|
23
21
|
assert_response :redirect
|
24
22
|
assert_redirected_to @request.env['HTTP_REFERER']
|
25
|
-
assert flash[:notice]
|
26
23
|
assert_equal "You can't toggle your status.", flash[:notice]
|
27
24
|
|
28
25
|
end
|
29
26
|
|
30
27
|
def test_should_allow_admin_to_toggle_other_users_status
|
31
28
|
|
32
|
-
|
33
|
-
editor = typus_users(:editor)
|
34
|
-
get :toggle, { :id => editor.id, :field => 'status' }
|
29
|
+
get :toggle, { :id => typus_users(:editor).id, :field => 'status' }
|
35
30
|
|
36
31
|
assert_response :redirect
|
37
32
|
assert_redirected_to @request.env['HTTP_REFERER']
|
38
|
-
assert flash[:success]
|
39
33
|
assert_equal "Typus user status changed.", flash[:success]
|
40
34
|
|
41
35
|
end
|
42
36
|
|
43
37
|
def test_should_not_allow_non_root_typus_user_to_toggle_status
|
44
38
|
|
45
|
-
|
46
|
-
@
|
47
|
-
|
48
|
-
get :toggle, { :id => @typus_user.id, :field => 'status' }
|
39
|
+
typus_user = typus_users(:editor)
|
40
|
+
@request.session[:typus_user_id] = typus_user.id
|
41
|
+
get :toggle, { :id => typus_user.id, :field => 'status' }
|
49
42
|
|
50
43
|
assert_response :redirect
|
51
44
|
assert_redirected_to @request.env['HTTP_REFERER']
|
52
|
-
assert flash[:notice]
|
53
45
|
assert_equal "You're not allowed to toggle status.", flash[:notice]
|
54
46
|
|
55
47
|
end
|
56
48
|
|
57
49
|
def test_should_verify_admin_cannot_destroy_herself
|
58
50
|
|
59
|
-
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
60
|
-
|
61
51
|
assert_difference('TypusUser.count', 0) do
|
62
52
|
delete :destroy, :id => @typus_user.id
|
63
53
|
end
|
64
54
|
|
65
55
|
assert_response :redirect
|
66
56
|
assert_redirected_to @request.env['HTTP_REFERER']
|
67
|
-
assert flash[:notice]
|
68
57
|
assert_equal "You can't remove yourself.", flash[:notice]
|
69
58
|
|
70
59
|
end
|
71
60
|
|
72
61
|
def test_should_verify_admin_can_destroy_others
|
73
62
|
|
74
|
-
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
75
|
-
|
76
63
|
assert_difference('TypusUser.count', -1) do
|
77
64
|
delete :destroy, :id => typus_users(:editor).id
|
78
65
|
end
|
79
66
|
|
80
67
|
assert_response :redirect
|
81
68
|
assert_redirected_to @request.env['HTTP_REFERER']
|
82
|
-
assert flash[:success]
|
83
69
|
assert_equal "Typus user successfully removed.", flash[:success]
|
84
70
|
|
85
71
|
end
|
86
72
|
|
87
73
|
def test_should_not_allow_editor_to_create_typus_users
|
88
74
|
|
89
|
-
@request.env['HTTP_REFERER'] = '/typus/typus_users'
|
90
75
|
typus_user = typus_users(:editor)
|
91
76
|
@request.session[:typus_user_id] = typus_user.id
|
92
77
|
get :new
|
93
78
|
|
94
79
|
assert_response :redirect
|
95
80
|
assert_redirected_to @request.env['HTTP_REFERER']
|
96
|
-
|
97
|
-
assert_equal "Editor can't perform action (new).", flash[:notice].to_s
|
81
|
+
assert_equal "Editor can't perform action. (new)", flash[:notice].to_s
|
98
82
|
|
99
83
|
end
|
100
84
|
|
@@ -118,7 +102,6 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
118
102
|
|
119
103
|
assert_response :redirect
|
120
104
|
assert_redirected_to @request.env['HTTP_REFERER']
|
121
|
-
assert flash[:success]
|
122
105
|
assert_equal "Typus user successfully updated.", flash[:success]
|
123
106
|
|
124
107
|
end
|
@@ -136,14 +119,12 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
136
119
|
|
137
120
|
assert_response :redirect
|
138
121
|
assert_redirected_to @request.env['HTTP_REFERER']
|
139
|
-
assert flash[:notice]
|
140
122
|
assert_equal "You can't change your role.", flash[:notice]
|
141
123
|
|
142
124
|
end
|
143
125
|
|
144
126
|
def test_should_not_allow_editor_to_edit_other_users_profiles
|
145
127
|
|
146
|
-
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
147
128
|
typus_user = typus_users(:editor)
|
148
129
|
@request.session[:typus_user_id] = typus_user.id
|
149
130
|
get :edit, { :id => typus_user.id }
|
@@ -155,35 +136,30 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
155
136
|
|
156
137
|
assert_response :redirect
|
157
138
|
assert_redirected_to @request.env['HTTP_REFERER']
|
158
|
-
assert flash[:notice]
|
159
139
|
assert_equal "As you're not the admin or the owner of this record you cannot edit it.", flash[:notice]
|
160
140
|
|
161
141
|
end
|
162
142
|
|
163
143
|
def test_should_not_allow_editor_to_destroy_users
|
164
144
|
|
165
|
-
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
166
145
|
typus_user = typus_users(:editor)
|
167
146
|
@request.session[:typus_user_id] = typus_user.id
|
168
147
|
delete :destroy, :id => typus_users(:admin).id
|
169
148
|
|
170
149
|
assert_response :redirect
|
171
150
|
assert_redirected_to @request.env['HTTP_REFERER']
|
172
|
-
assert flash[:notice]
|
173
151
|
assert_equal "You're not allowed to remove Typus Users.", flash[:notice]
|
174
152
|
|
175
153
|
end
|
176
154
|
|
177
155
|
def test_should_not_allow_editor_to_destroy_herself
|
178
156
|
|
179
|
-
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
180
157
|
typus_user = typus_users(:editor)
|
181
158
|
@request.session[:typus_user_id] = typus_user.id
|
182
159
|
delete :destroy, :id => typus_user.id
|
183
160
|
|
184
161
|
assert_response :redirect
|
185
162
|
assert_redirected_to @request.env['HTTP_REFERER']
|
186
|
-
assert flash[:notice]
|
187
163
|
assert_equal "You're not allowed to remove Typus Users.", flash[:notice]
|
188
164
|
|
189
165
|
end
|
@@ -197,7 +173,6 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
197
173
|
|
198
174
|
assert_response :redirect
|
199
175
|
assert_redirected_to @request.env['HTTP_REFERER']
|
200
|
-
assert flash[:notice]
|
201
176
|
assert_equal "Designer can't display items.", flash[:notice]
|
202
177
|
|
203
178
|
end
|
@@ -206,17 +181,15 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
206
181
|
|
207
182
|
typus_user = typus_users(:editor)
|
208
183
|
@request.session[:typus_user_id] = typus_user.id
|
209
|
-
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
210
184
|
|
211
185
|
assert_equal 'editor', typus_user.role
|
212
186
|
|
213
|
-
get :edit, :id => typus_user.id
|
187
|
+
get :edit, { :id => typus_user.id }
|
214
188
|
assert_response :success
|
215
189
|
|
216
|
-
get :edit, :id => typus_users(:admin).id
|
190
|
+
get :edit, { :id => typus_users(:admin).id }
|
217
191
|
assert_response :redirect
|
218
192
|
assert_redirected_to @request.env['HTTP_REFERER']
|
219
|
-
assert flash[:notice]
|
220
193
|
assert_equal "As you're not the admin or the owner of this record you cannot edit it.", flash[:notice]
|
221
194
|
|
222
195
|
##
|
@@ -227,10 +200,10 @@ class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
227
200
|
options = Typus::Configuration.options.merge(:root => 'editor')
|
228
201
|
Typus::Configuration.stubs(:options).returns(options)
|
229
202
|
|
230
|
-
get :edit, :id => typus_user.id
|
203
|
+
get :edit, { :id => typus_user.id }
|
231
204
|
assert_response :success
|
232
205
|
|
233
|
-
get :edit, :id => typus_users(:admin).id
|
206
|
+
get :edit, { :id => typus_users(:admin).id }
|
234
207
|
assert_response :success
|
235
208
|
|
236
209
|
end
|
@@ -1,25 +1,22 @@
|
|
1
1
|
require 'test/helper'
|
2
2
|
|
3
|
-
# Test TypusController:
|
4
|
-
#
|
5
|
-
# - sign_up, sign_in & sign_out
|
6
|
-
# - dashboard
|
7
|
-
# - reset_password, recover_password
|
8
|
-
|
9
3
|
class TypusControllerTest < ActionController::TestCase
|
10
4
|
|
11
5
|
def setup
|
12
|
-
Typus::Configuration.options[:recover_password] = true
|
13
|
-
Typus::Configuration.options[:app_name] = 'whatistypus.com'
|
6
|
+
# Typus::Configuration.options[:recover_password] = true
|
14
7
|
end
|
15
8
|
|
16
|
-
|
9
|
+
##
|
10
|
+
# get :sign_in
|
11
|
+
##
|
12
|
+
|
13
|
+
def test_should_sign_in
|
17
14
|
get :sign_in
|
18
15
|
assert_response :success
|
19
16
|
assert_template 'sign_in'
|
20
17
|
end
|
21
18
|
|
22
|
-
def
|
19
|
+
def test_should_sign_in_with_post_and_redirect_to_dashboard
|
23
20
|
typus_user = typus_users(:admin)
|
24
21
|
post :sign_in, { :user => { :email => typus_user.email, :password => '12345678' } }
|
25
22
|
assert_equal typus_user.id, @request.session[:typus_user_id]
|
@@ -27,11 +24,10 @@ class TypusControllerTest < ActionController::TestCase
|
|
27
24
|
assert_redirected_to admin_dashboard_path
|
28
25
|
end
|
29
26
|
|
30
|
-
def
|
27
|
+
def test_should_sign_in_with_post_and_redirect_to_sign_in_with_an_error
|
31
28
|
post :sign_in, { :user => { :email => 'john@example.com', :password => 'XXXXXXXX' } }
|
32
29
|
assert_response :redirect
|
33
30
|
assert_redirected_to admin_sign_in_path
|
34
|
-
assert flash[:error]
|
35
31
|
assert_equal "The email and/or password you entered is invalid.", flash[:error]
|
36
32
|
end
|
37
33
|
|
@@ -52,24 +48,33 @@ class TypusControllerTest < ActionController::TestCase
|
|
52
48
|
get :dashboard
|
53
49
|
assert_redirected_to admin_sign_in_path
|
54
50
|
assert_nil @request.session[:typus_user_id]
|
55
|
-
|
56
|
-
assert_equal 'Role does no longer exists.', flash[:notice]
|
51
|
+
assert_equal "Role does no longer exists.", flash[:notice]
|
57
52
|
end
|
58
53
|
|
59
54
|
def test_should_not_send_recovery_password_link_to_unexisting_user
|
55
|
+
|
56
|
+
options = Typus::Configuration.options.merge(:recover_password => true)
|
57
|
+
Typus::Configuration.stubs(:options).returns(options)
|
58
|
+
|
60
59
|
post :recover_password, { :user => { :email => 'unexisting' } }
|
61
60
|
assert_response :redirect
|
62
61
|
assert_redirected_to admin_recover_password_path
|
63
62
|
[ :notice, :error, :warning ].each { |f| assert !flash[f] }
|
63
|
+
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_should_send_recovery_password_link_to_existing_user
|
67
|
+
|
68
|
+
options = Typus::Configuration.options.merge(:recover_password => true)
|
69
|
+
Typus::Configuration.stubs(:options).returns(options)
|
70
|
+
|
67
71
|
admin = typus_users(:admin)
|
68
72
|
post :recover_password, { :user => { :email => admin.email } }
|
73
|
+
|
69
74
|
assert_response :redirect
|
70
75
|
assert_redirected_to admin_sign_in_path
|
71
|
-
|
72
|
-
|
76
|
+
assert_equal "Password recovery link sent to your email.", flash[:success]
|
77
|
+
|
73
78
|
end
|
74
79
|
|
75
80
|
def test_should_sign_out
|
@@ -82,7 +87,7 @@ class TypusControllerTest < ActionController::TestCase
|
|
82
87
|
[ :notice, :error, :warning ].each { |f| assert !flash[f] }
|
83
88
|
end
|
84
89
|
|
85
|
-
def
|
90
|
+
def test_should_verify_block_users_on_the_fly
|
86
91
|
|
87
92
|
admin = typus_users(:admin)
|
88
93
|
@request.session[:typus_user_id] = admin.id
|
@@ -98,130 +103,192 @@ class TypusControllerTest < ActionController::TestCase
|
|
98
103
|
assert_response :redirect
|
99
104
|
assert_redirected_to admin_sign_in_path
|
100
105
|
|
101
|
-
assert flash[:notice]
|
102
106
|
assert_equal "Typus user has been disabled.", flash[:notice]
|
103
107
|
assert_nil @request.session[:typus_user_id]
|
104
108
|
|
105
109
|
end
|
106
110
|
|
107
|
-
|
111
|
+
##
|
112
|
+
# reset_password
|
113
|
+
##
|
114
|
+
|
115
|
+
def test_should_not_reset_password
|
116
|
+
|
117
|
+
get :reset_password
|
118
|
+
assert_response :redirect
|
119
|
+
assert_redirected_to admin_sign_in_path
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_should_reset_password_when_recover_password_is_true
|
124
|
+
|
125
|
+
options = Typus::Configuration.options.merge(:recover_password => true)
|
126
|
+
Typus::Configuration.stubs(:options).returns(options)
|
108
127
|
|
109
128
|
typus_user = typus_users(:admin)
|
110
129
|
get :reset_password, { :token => typus_user.token }
|
130
|
+
|
111
131
|
assert_response :success
|
112
132
|
assert_template 'reset_password'
|
113
133
|
|
114
|
-
|
115
|
-
Typus::Configuration.stubs(:options).returns(options)
|
134
|
+
end
|
116
135
|
|
117
|
-
|
118
|
-
assert_response :redirect
|
119
|
-
assert_redirected_to admin_sign_in_path
|
136
|
+
def test_should_redirect_to_sign_in_user_after_reset_password
|
120
137
|
|
121
|
-
|
138
|
+
options = Typus::Configuration.options.merge(:recover_password => true)
|
139
|
+
Typus::Configuration.stubs(:options).returns(options)
|
122
140
|
|
123
|
-
def test_should_sign_in_user_after_password_change
|
124
141
|
typus_user = typus_users(:admin)
|
125
142
|
post :reset_password, { :token => typus_user.token, :user => { :password => '12345678', :password_confirmation => '12345678' } }
|
143
|
+
|
126
144
|
assert_response :redirect
|
127
145
|
assert_redirected_to admin_dashboard_path
|
146
|
+
|
128
147
|
end
|
129
148
|
|
130
149
|
def test_should_be_redirected_if_password_does_not_match_confirmation
|
150
|
+
|
151
|
+
options = Typus::Configuration.options.merge(:recover_password => true)
|
152
|
+
Typus::Configuration.stubs(:options).returns(options)
|
153
|
+
|
131
154
|
typus_user = typus_users(:admin)
|
132
155
|
post :reset_password, { :token => typus_user.token, :user => { :password => 'drowssap', :password_confirmation => 'drowssap2' } }
|
133
156
|
assert_response :success
|
157
|
+
|
134
158
|
end
|
135
159
|
|
136
160
|
def test_should_only_be_allowed_to_reset_password
|
161
|
+
|
162
|
+
options = Typus::Configuration.options.merge(:recover_password => true)
|
163
|
+
Typus::Configuration.stubs(:options).returns(options)
|
164
|
+
|
137
165
|
typus_user = typus_users(:admin)
|
138
166
|
post :reset_password, { :token => typus_user.token, :user => { :password => 'drowssap', :password_confirmation => 'drowssap', :role => 'superadmin' } }
|
139
167
|
typus_user.reload
|
140
168
|
assert_not_equal typus_user.role, 'superadmin'
|
169
|
+
|
141
170
|
end
|
142
171
|
|
143
|
-
def
|
172
|
+
def test_should_return_404_on_reset_passsword_if_token_is_not_valid
|
173
|
+
|
174
|
+
options = Typus::Configuration.options.merge(:recover_password => true)
|
175
|
+
Typus::Configuration.stubs(:options).returns(options)
|
176
|
+
|
144
177
|
assert_raise(ActiveRecord::RecordNotFound) { get :reset_password, { :token => 'INVALID' } }
|
178
|
+
|
145
179
|
end
|
146
180
|
|
147
|
-
def
|
181
|
+
def test_should_reset_password_with_valid_token
|
182
|
+
|
183
|
+
options = Typus::Configuration.options.merge(:recover_password => true)
|
184
|
+
Typus::Configuration.stubs(:options).returns(options)
|
185
|
+
|
148
186
|
typus_user = typus_users(:admin)
|
149
187
|
get :reset_password, { :token => typus_user.token }
|
150
188
|
assert_response :success
|
151
189
|
assert_template 'reset_password'
|
152
|
-
end
|
153
190
|
|
154
|
-
def test_should_verify_typus_sign_in_layout_includes_recover_password_link
|
155
|
-
options = Typus::Configuration.options.merge(:recover_password => true)
|
156
|
-
Typus::Configuration.stubs(:options).returns(options)
|
157
|
-
get :sign_in
|
158
|
-
assert @response.body.include?('Recover password')
|
159
191
|
end
|
160
192
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
193
|
+
##
|
194
|
+
# sign_up
|
195
|
+
##
|
196
|
+
|
197
|
+
def test_should_verify_sign_up_works
|
198
|
+
|
199
|
+
TypusUser.destroy_all
|
200
|
+
assert TypusUser.find(:all).empty?
|
201
|
+
|
202
|
+
get :sign_up
|
167
203
|
|
168
|
-
def test_should_render_typus_login_footer
|
169
|
-
expected = 'Typus'
|
170
|
-
get :sign_in
|
171
204
|
assert_response :success
|
172
|
-
|
205
|
+
assert_template 'sign_up'
|
173
206
|
assert_match /layouts\/typus/, @controller.active_layout.to_s
|
207
|
+
assert_equal "Enter your email below to create the first user.", flash[:notice]
|
208
|
+
|
174
209
|
end
|
175
210
|
|
176
|
-
def
|
177
|
-
|
211
|
+
def test_should_should_not_sign_up_invalid_email
|
212
|
+
|
213
|
+
TypusUser.destroy_all
|
214
|
+
|
215
|
+
post :sign_up, :user => { :email => 'example.com' }
|
216
|
+
|
178
217
|
assert_response :success
|
179
|
-
|
180
|
-
assert_match /layouts\/typus/, @controller.active_layout.to_s
|
181
|
-
end
|
218
|
+
assert_equal "That doesn't seem like a valid email address.", flash[:error]
|
182
219
|
|
183
|
-
def test_should_verify_page_title_on_sign_in
|
184
|
-
get :sign_in
|
185
|
-
assert_select 'title', "#{Typus::Configuration.options[:app_name]} - Sign in"
|
186
220
|
end
|
187
221
|
|
188
|
-
def
|
222
|
+
def test_should_sign_up_valid_email
|
189
223
|
|
190
224
|
TypusUser.destroy_all
|
191
|
-
assert_nil @request.session[:typus_user_id]
|
192
|
-
assert TypusUser.find(:all).empty?
|
193
225
|
|
194
|
-
|
226
|
+
assert_difference 'TypusUser.count' do
|
227
|
+
post :sign_up, :user => { :email => 'john@example.com' }
|
228
|
+
end
|
229
|
+
|
195
230
|
assert_response :redirect
|
196
|
-
assert_redirected_to
|
231
|
+
assert_redirected_to admin_dashboard_path
|
232
|
+
assert_equal %Q[Password set to "columbia".], flash[:notice]
|
233
|
+
assert @request.session[:typus_user_id]
|
197
234
|
|
198
|
-
|
199
|
-
assert flash[:notice]
|
200
|
-
assert_equal 'Enter your email below to create the first user.', flash[:notice]
|
235
|
+
end
|
201
236
|
|
202
|
-
|
237
|
+
##
|
238
|
+
# sign_in
|
239
|
+
##
|
240
|
+
|
241
|
+
def test_should_render_sign_in
|
242
|
+
|
243
|
+
options = Typus::Configuration.options.merge(:app_name => 'Typus Test')
|
244
|
+
Typus::Configuration.stubs(:options).returns(options)
|
245
|
+
|
246
|
+
get :sign_in
|
203
247
|
assert_response :success
|
204
|
-
assert flash[:error]
|
205
|
-
assert_equal 'That doesn\'t seem like a valid email address.', flash[:error]
|
206
248
|
|
207
|
-
|
249
|
+
assert_select 'title', "Typus Test - Sign in"
|
250
|
+
assert_select 'h1', 'Typus Test'
|
251
|
+
assert_match /layouts\/typus/, @controller.active_layout.to_s
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_should_redirect_to_sign_up_when_no_typus_users
|
256
|
+
TypusUser.destroy_all
|
257
|
+
get :sign_in
|
208
258
|
assert_response :redirect
|
209
|
-
assert_redirected_to
|
210
|
-
|
211
|
-
assert_equal "Password set to \"columbia\".", flash[:notice]
|
212
|
-
assert @request.session[:typus_user_id]
|
213
|
-
assert !TypusUser.find(:all).empty?
|
259
|
+
assert_redirected_to admin_sign_up_path
|
260
|
+
end
|
214
261
|
|
262
|
+
def test_should_verify_typus_sign_in_layout_does_not_include_recover_password_link
|
263
|
+
options = Typus::Configuration.options.merge(:recover_password => false)
|
264
|
+
Typus::Configuration.stubs(:options).returns(options)
|
265
|
+
get :sign_in
|
266
|
+
assert !@response.body.include?('Recover password')
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_should_verify_typus_sign_in_layout_includes_recover_password_link
|
270
|
+
options = Typus::Configuration.options.merge(:recover_password => true)
|
271
|
+
Typus::Configuration.stubs(:options).returns(options)
|
272
|
+
get :sign_in
|
273
|
+
assert @response.body.include?('Recover password')
|
274
|
+
end
|
275
|
+
|
276
|
+
##
|
277
|
+
# sign_out
|
278
|
+
##
|
279
|
+
|
280
|
+
def test_should_verify_sign_out
|
281
|
+
@request.session[:typus_user_id] = typus_users(:admin).id
|
215
282
|
get :sign_out
|
216
283
|
assert_nil @request.session[:typus_user_id]
|
217
284
|
assert_redirected_to admin_sign_in_path
|
218
|
-
|
219
|
-
get :sign_up
|
220
|
-
assert_redirected_to admin_sign_in_path
|
221
|
-
|
222
285
|
end
|
223
286
|
|
224
|
-
|
287
|
+
##
|
288
|
+
# get dashboard
|
289
|
+
##
|
290
|
+
|
291
|
+
def test_should_redirect_to_sign_in_when_not_signed_in
|
225
292
|
@request.session[:typus_user_id] = nil
|
226
293
|
get :dashboard
|
227
294
|
assert_response :redirect
|
@@ -229,96 +296,47 @@ class TypusControllerTest < ActionController::TestCase
|
|
229
296
|
end
|
230
297
|
|
231
298
|
def test_should_render_dashboard
|
299
|
+
|
232
300
|
@request.session[:typus_user_id] = typus_users(:admin).id
|
233
301
|
get :dashboard
|
302
|
+
|
234
303
|
assert_response :success
|
235
304
|
assert_template 'dashboard'
|
236
|
-
assert_match 'whatistypus.com', @response.body
|
237
305
|
assert_match /layouts\/admin/, @controller.active_layout.to_s
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_should_verify_sign_up_works
|
241
|
-
@request.session[:typus_user_id] = typus_users(:admin).id
|
242
|
-
TypusUser.destroy_all
|
243
|
-
get :sign_up
|
244
|
-
assert_response :success
|
245
|
-
assert_template 'sign_up'
|
246
|
-
assert_match /layouts\/typus/, @controller.active_layout.to_s
|
247
|
-
end
|
248
|
-
|
249
|
-
def test_should_verify_page_title_on_dashboard
|
250
|
-
@request.session[:typus_user_id] = typus_users(:admin).id
|
251
|
-
get :dashboard
|
252
306
|
assert_select 'title', "#{Typus::Configuration.options[:app_name]} - Dashboard"
|
253
|
-
end
|
254
|
-
|
255
|
-
def test_should_verify_link_to_edit_typus_user
|
256
307
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
308
|
+
[ 'Typus',
|
309
|
+
%Q[href="/admin/sign_out"],
|
310
|
+
%Q[href="/admin/typus_users/edit/#{@request.session[:typus_user_id]}] ].each do |string|
|
311
|
+
assert_match string, @response.body
|
312
|
+
end
|
261
313
|
|
262
|
-
assert_match "
|
314
|
+
%w( typus_users posts pages assets ).each { |r| assert_match "/admin/#{r}/new", @response.body }
|
315
|
+
%w( statuses orders ).each { |r| assert_no_match /\/admin\/#{r}\n/, @response.body }
|
263
316
|
|
264
317
|
assert_select 'body div#header' do
|
265
318
|
assert_select 'a', 'Admin Example'
|
266
319
|
assert_select 'a', 'Sign out'
|
267
320
|
end
|
268
321
|
|
269
|
-
|
270
|
-
|
271
|
-
def test_should_verify_link_to_sign_out
|
272
|
-
|
273
|
-
@request.session[:typus_user_id] = typus_users(:admin).id
|
274
|
-
get :dashboard
|
275
|
-
assert_response :success
|
276
|
-
|
277
|
-
assert_match "href=\"\/admin\/sign_out\"", @response.body
|
278
|
-
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_should_show_add_links_in_resources_list_for_admin
|
282
|
-
|
283
|
-
@request.session[:typus_user_id] = typus_users(:admin).id
|
284
|
-
get :dashboard
|
285
|
-
|
286
|
-
%w( typus_users posts pages assets ).each do |resource|
|
287
|
-
assert_match "/admin/#{resource}/new", @response.body
|
288
|
-
end
|
289
|
-
|
290
|
-
%w( statuses orders ).each do |resource|
|
291
|
-
assert_no_match /\/admin\/#{resource}\n/, @response.body
|
292
|
-
end
|
322
|
+
partials = %w( _sidebar.html.erb )
|
323
|
+
partials.each { |p| assert_match p, @response.body }
|
293
324
|
|
294
325
|
end
|
295
326
|
|
296
327
|
def test_should_show_add_links_in_resources_list_for_editor
|
297
|
-
|
298
|
-
@request.session[:typus_user_id] = editor.id
|
328
|
+
@request.session[:typus_user_id] = typus_users(:editor).id
|
299
329
|
get :dashboard
|
300
330
|
assert_match '/admin/posts/new', @response.body
|
301
331
|
assert_no_match /\/admin\/typus_users\/new/, @response.body
|
302
|
-
# We have loaded categories as a module, so are not displayed
|
303
|
-
# on the applications list.
|
304
332
|
assert_no_match /\/admin\/categories\/new/, @response.body
|
305
333
|
end
|
306
334
|
|
307
335
|
def test_should_show_add_links_in_resources_list_for_designer
|
308
|
-
|
309
|
-
@request.session[:typus_user_id] = designer.id
|
336
|
+
@request.session[:typus_user_id] = typus_users(:designer).id
|
310
337
|
get :dashboard
|
311
338
|
assert_no_match /\/admin\/posts\/new/, @response.body
|
312
339
|
assert_no_match /\/admin\/typus_users\/new/, @response.body
|
313
340
|
end
|
314
341
|
|
315
|
-
def test_should_render_application_dashboard_template_extensions
|
316
|
-
admin = typus_users(:admin)
|
317
|
-
@request.session[:typus_user_id] = admin.id
|
318
|
-
get :dashboard
|
319
|
-
assert_response :success
|
320
|
-
partials = %w( _sidebar.html.erb )
|
321
|
-
partials.each { |p| assert_match p, @response.body }
|
322
|
-
end
|
323
|
-
|
324
342
|
end
|