typus 0.9.17
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/.gitignore +8 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +86 -0
- data/Rakefile +61 -0
- data/VERSION +1 -0
- data/app/controllers/admin/master_controller.rb +354 -0
- data/app/controllers/typus_controller.rb +128 -0
- data/app/helpers/admin/form_helper.rb +386 -0
- data/app/helpers/admin/master_helper.rb +104 -0
- data/app/helpers/admin/public_helper.rb +27 -0
- data/app/helpers/admin/sidebar_helper.rb +236 -0
- data/app/helpers/admin/table_helper.rb +227 -0
- data/app/helpers/typus_helper.rb +194 -0
- data/app/models/typus_mailer.rb +14 -0
- data/app/models/typus_user.rb +5 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +9 -0
- data/app/views/admin/resources/edit.html.erb +24 -0
- data/app/views/admin/resources/index.html.erb +23 -0
- data/app/views/admin/resources/new.html.erb +22 -0
- data/app/views/admin/resources/show.html.erb +18 -0
- data/app/views/admin/shared/_footer.html.erb +1 -0
- data/app/views/admin/shared/_pagination.html.erb +28 -0
- data/app/views/layouts/admin.html.erb +73 -0
- data/app/views/layouts/typus.html.erb +29 -0
- data/app/views/typus/dashboard.html.erb +9 -0
- data/app/views/typus/recover_password.html.erb +7 -0
- data/app/views/typus/reset_password.html.erb +15 -0
- data/app/views/typus/sign_in.html.erb +9 -0
- data/app/views/typus/sign_up.html.erb +7 -0
- data/app/views/typus_mailer/reset_password_link.erb +11 -0
- data/config/locales/typus/de.yml +109 -0
- data/config/locales/typus/es.yml +109 -0
- data/config/locales/typus/language.yml.template +113 -0
- data/config/locales/typus/pt-BR.yml +111 -0
- data/config/locales/typus/ru.yml +111 -0
- data/generators/typus/templates/config/initializers/typus.rb +33 -0
- data/generators/typus/templates/config/typus/README +51 -0
- data/generators/typus/templates/config/typus/application.yml +6 -0
- data/generators/typus/templates/config/typus/application_roles.yml +23 -0
- data/generators/typus/templates/config/typus/typus.yml +14 -0
- data/generators/typus/templates/config/typus/typus_roles.yml +2 -0
- data/generators/typus/templates/db/create_typus_users.rb +21 -0
- data/generators/typus/templates/public/images/admin/arrow_down.gif +0 -0
- data/generators/typus/templates/public/images/admin/arrow_up.gif +0 -0
- data/generators/typus/templates/public/images/admin/spinner.gif +0 -0
- data/generators/typus/templates/public/images/admin/status_false.gif +0 -0
- data/generators/typus/templates/public/images/admin/status_true.gif +0 -0
- data/generators/typus/templates/public/images/admin/trash.gif +0 -0
- data/generators/typus/templates/public/javascripts/admin/application.js +14 -0
- data/generators/typus/templates/public/stylesheets/admin/reset.css +68 -0
- data/generators/typus/templates/public/stylesheets/admin/screen.css +729 -0
- data/generators/typus/typus_generator.rb +122 -0
- data/generators/typus_update_schema_to_01/templates/config/typus.yml +14 -0
- data/generators/typus_update_schema_to_01/templates/migration.rb +11 -0
- data/generators/typus_update_schema_to_01/typus_update_schema_to_01_generator.rb +19 -0
- data/lib/typus.rb +122 -0
- data/lib/typus/active_record.rb +307 -0
- data/lib/typus/authentication.rb +142 -0
- data/lib/typus/configuration.rb +85 -0
- data/lib/typus/extensions/routes.rb +15 -0
- data/lib/typus/format.rb +55 -0
- data/lib/typus/generator.rb +81 -0
- data/lib/typus/hash.rb +8 -0
- data/lib/typus/locale.rb +17 -0
- data/lib/typus/object.rb +21 -0
- data/lib/typus/quick_edit.rb +40 -0
- data/lib/typus/reloader.rb +15 -0
- data/lib/typus/string.rb +11 -0
- data/lib/typus/templates/index.html.erb +11 -0
- data/lib/typus/templates/resource_controller.rb.erb +15 -0
- data/lib/typus/templates/resource_controller_test.rb.erb +10 -0
- data/lib/typus/templates/resources_controller.rb.erb +37 -0
- data/lib/typus/user.rb +134 -0
- data/lib/vendor/active_record.rb +15 -0
- data/lib/vendor/paginator.rb +143 -0
- data/rails/init.rb +3 -0
- data/tasks/typus_tasks.rake +32 -0
- data/test/config/broken/application.yml +68 -0
- data/test/config/broken/application_roles.yml +20 -0
- data/test/config/broken/empty.yml +0 -0
- data/test/config/broken/empty_roles.yml +0 -0
- data/test/config/broken/undefined.yml +3 -0
- data/test/config/broken/undefined_roles.yml +6 -0
- data/test/config/default/typus.yml +14 -0
- data/test/config/default/typus_roles.yml +2 -0
- data/test/config/empty/empty_01.yml +0 -0
- data/test/config/empty/empty_01_roles.yml +0 -0
- data/test/config/empty/empty_02.yml +0 -0
- data/test/config/empty/empty_02_roles.yml +0 -0
- data/test/config/locales/es.yml +10 -0
- data/test/config/ordered/001_roles.yml +2 -0
- data/test/config/ordered/002_roles.yml +2 -0
- data/test/config/unordered/app_one_roles.yml +2 -0
- data/test/config/unordered/app_two_roles.yml +2 -0
- data/test/config/working/application.yml +68 -0
- data/test/config/working/application_roles.yml +22 -0
- data/test/config/working/typus.yml +14 -0
- data/test/config/working/typus_roles.yml +2 -0
- data/test/fixtures/app/controllers/admin/assets_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/categories_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/comments_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/pages_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/posts_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/status_controller.rb +6 -0
- data/test/fixtures/app/controllers/admin/typus_users_controller.rb +2 -0
- data/test/fixtures/app/controllers/admin/watch_dog_controller.rb +6 -0
- data/test/fixtures/app/views/admin/comments/_edit.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_index.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_new.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_show.html.erb +1 -0
- data/test/fixtures/app/views/admin/comments/_sidebar.html.erb +1 -0
- data/test/fixtures/app/views/admin/dashboard/_content.html.erb +1 -0
- data/test/fixtures/app/views/admin/dashboard/_sidebar.html.erb +1 -0
- data/test/fixtures/app/views/admin/resources/_sidebar.html.erb +1 -0
- data/test/fixtures/app/views/admin/shared/_footer.html.erb +1 -0
- data/test/fixtures/app/views/admin/status/index.html.erb +1 -0
- data/test/fixtures/app/views/admin/templates/_datepicker.html.erb +1 -0
- data/test/fixtures/assets.yml +11 -0
- data/test/fixtures/categories.yml +14 -0
- data/test/fixtures/comments.yml +27 -0
- data/test/fixtures/pages.yml +41 -0
- data/test/fixtures/posts.yml +37 -0
- data/test/fixtures/typus_users.yml +54 -0
- data/test/functional/admin/assets_controller_test.rb +57 -0
- data/test/functional/admin/categories_controller_test.rb +106 -0
- data/test/functional/admin/comments_controller_test.rb +120 -0
- data/test/functional/admin/master_controller_test.rb +5 -0
- data/test/functional/admin/posts_controller_test.rb +261 -0
- data/test/functional/admin/status_controller_test.rb +43 -0
- data/test/functional/admin/typus_users_controller_test.rb +239 -0
- data/test/functional/typus_controller_test.rb +321 -0
- data/test/helper.rb +51 -0
- data/test/helpers/admin/form_helper_test.rb +337 -0
- data/test/helpers/admin/master_helper_test.rb +69 -0
- data/test/helpers/admin/public_helper_test.rb +26 -0
- data/test/helpers/admin/sidebar_helper_test.rb +335 -0
- data/test/helpers/admin/table_helper_test.rb +239 -0
- data/test/helpers/typus_helper_test.rb +117 -0
- data/test/lib/active_record_test.rb +382 -0
- data/test/lib/configuration_test.rb +94 -0
- data/test/lib/hash_test.rb +11 -0
- data/test/lib/routes_test.rb +71 -0
- data/test/lib/string_test.rb +25 -0
- data/test/lib/typus_test.rb +85 -0
- data/test/models.rb +51 -0
- data/test/schema.rb +64 -0
- data/test/unit/typus_mailer_test.rb +33 -0
- data/test/unit/typus_test.rb +17 -0
- data/test/unit/typus_user_roles_test.rb +90 -0
- data/test/unit/typus_user_test.rb +177 -0
- data/test/vendor/active_record_test.rb +18 -0
- data/test/vendor/paginator_test.rb +136 -0
- data/typus.gemspec +228 -0
- metadata +241 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'test/helper'
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# Test resources which are not related to an ActiveRecord model.
|
|
5
|
+
#
|
|
6
|
+
class Admin::StatusControllerTest < ActionController::TestCase
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@typus_user = typus_users(:admin)
|
|
10
|
+
@request.session[:typus_user_id] = @typus_user.id
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_should_verify_admin_can_go_to_index
|
|
14
|
+
get :index
|
|
15
|
+
assert_response :success
|
|
16
|
+
assert_template 'index'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_should_verify_status_is_not_available_if_user_not_logged
|
|
20
|
+
@request.session[:typus_user_id] = nil
|
|
21
|
+
get :index
|
|
22
|
+
assert_response :redirect
|
|
23
|
+
assert_redirected_to admin_sign_in_path(:back_to => '/admin/status')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_should_verify_admin_can_not_go_to_show
|
|
27
|
+
get :show
|
|
28
|
+
assert_response :redirect
|
|
29
|
+
assert_redirected_to admin_dashboard_path
|
|
30
|
+
assert flash[:notice]
|
|
31
|
+
assert_equal "#{@typus_user.role.capitalize} can't go to show on status.", flash[:notice]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_should_verify_editor_can_not_go_to_index
|
|
35
|
+
typus_user = typus_users(:editor)
|
|
36
|
+
@request.session[:typus_user_id] = typus_user.id
|
|
37
|
+
get :index
|
|
38
|
+
assert_response :redirect
|
|
39
|
+
assert flash[:notice]
|
|
40
|
+
assert_equal "#{typus_user.role.capitalize} can't go to index on status.", flash[:notice]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
require 'test/helper'
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# Test what TypusUsers can do.
|
|
5
|
+
#
|
|
6
|
+
class Admin::TypusUsersControllerTest < ActionController::TestCase
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
Typus::Configuration.options[:root] = 'admin'
|
|
10
|
+
@typus_user = typus_users(:admin)
|
|
11
|
+
@request.session[:typus_user_id] = @typus_user.id
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_should_allow_admin_to_create_typus_users
|
|
15
|
+
get :new
|
|
16
|
+
assert_response :success
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_should_not_allow_admin_to_toggle_her_status
|
|
20
|
+
|
|
21
|
+
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
|
22
|
+
get :toggle, { :id => @typus_user.id, :field => 'status' }
|
|
23
|
+
|
|
24
|
+
assert_response :redirect
|
|
25
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
26
|
+
assert flash[:notice]
|
|
27
|
+
assert_equal "You can't toggle your status.", flash[:notice]
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_should_allow_admin_to_toggle_other_users_status
|
|
32
|
+
|
|
33
|
+
@request.env['HTTP_REFERER'] = '/typus/typus_users'
|
|
34
|
+
editor = typus_users(:editor)
|
|
35
|
+
get :toggle, { :id => editor.id, :field => 'status' }
|
|
36
|
+
|
|
37
|
+
assert_response :redirect
|
|
38
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
39
|
+
assert flash[:success]
|
|
40
|
+
assert_equal "Typus user status changed.", flash[:success]
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_should_not_allow_non_root_typus_user_to_toggle_status
|
|
45
|
+
|
|
46
|
+
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
|
47
|
+
@typus_user = typus_users(:editor)
|
|
48
|
+
@request.session[:typus_user_id] = @typus_user.id
|
|
49
|
+
get :toggle, { :id => @typus_user.id, :field => 'status' }
|
|
50
|
+
|
|
51
|
+
assert_response :redirect
|
|
52
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
53
|
+
assert flash[:notice]
|
|
54
|
+
assert_equal "You're not allowed to toggle status.", flash[:notice]
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_should_verify_admin_cannot_destroy_herself
|
|
59
|
+
|
|
60
|
+
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
|
61
|
+
|
|
62
|
+
assert_difference('TypusUser.count', 0) do
|
|
63
|
+
delete :destroy, :id => @typus_user.id
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
assert_response :redirect
|
|
67
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
68
|
+
assert flash[:notice]
|
|
69
|
+
assert_equal "You can't remove yourself.", flash[:notice]
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_should_verify_admin_can_destroy_others
|
|
74
|
+
|
|
75
|
+
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
|
76
|
+
|
|
77
|
+
assert_difference('TypusUser.count', -1) do
|
|
78
|
+
delete :destroy, :id => typus_users(:editor).id
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
assert_response :redirect
|
|
82
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
83
|
+
assert flash[:success]
|
|
84
|
+
assert_equal "Typus user successfully removed.", flash[:success]
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_should_not_allow_editor_to_create_typus_users
|
|
89
|
+
|
|
90
|
+
@request.env['HTTP_REFERER'] = '/typus/typus_users'
|
|
91
|
+
typus_user = typus_users(:editor)
|
|
92
|
+
@request.session[:typus_user_id] = typus_user.id
|
|
93
|
+
get :new
|
|
94
|
+
|
|
95
|
+
assert_response :redirect
|
|
96
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
97
|
+
assert flash[:notice]
|
|
98
|
+
assert_equal "Editor can't perform action (new).", flash[:notice].to_s
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_should_allow_editor_to_update_himself
|
|
103
|
+
|
|
104
|
+
options = Typus::Configuration.options.merge(:index_after_save => false)
|
|
105
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
106
|
+
|
|
107
|
+
typus_user = typus_users(:editor)
|
|
108
|
+
@request.session[:typus_user_id] = typus_user.id
|
|
109
|
+
@request.env['HTTP_REFERER'] = "/admin/typus_users/edit/#{typus_user.id}"
|
|
110
|
+
get :edit, { :id => typus_user.id }
|
|
111
|
+
|
|
112
|
+
assert_response :success
|
|
113
|
+
assert_equal 'editor', typus_user.role
|
|
114
|
+
|
|
115
|
+
post :update, { :id => typus_user.id,
|
|
116
|
+
:item => { :first_name => 'Richard',
|
|
117
|
+
:last_name => 'Ashcroft',
|
|
118
|
+
:role => 'editor' } }
|
|
119
|
+
|
|
120
|
+
assert_response :redirect
|
|
121
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
122
|
+
assert flash[:success]
|
|
123
|
+
assert_equal "Typus user successfully updated.", flash[:success]
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_should_not_allow_editor_to_update_himself_to_become_admin
|
|
128
|
+
|
|
129
|
+
typus_user = typus_users(:editor)
|
|
130
|
+
@request.session[:typus_user_id] = typus_user.id
|
|
131
|
+
@request.env['HTTP_REFERER'] = "/admin/typus_users/#{typus_user.id}/edit"
|
|
132
|
+
|
|
133
|
+
assert_equal 'editor', typus_user.role
|
|
134
|
+
|
|
135
|
+
post :update, { :id => typus_user.id,
|
|
136
|
+
:item => { :role => 'admin' } }
|
|
137
|
+
|
|
138
|
+
assert_response :redirect
|
|
139
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
140
|
+
assert flash[:notice]
|
|
141
|
+
assert_equal "You can't change your role.", flash[:notice]
|
|
142
|
+
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_should_not_allow_editor_to_edit_other_users_profiles
|
|
146
|
+
|
|
147
|
+
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
|
148
|
+
typus_user = typus_users(:editor)
|
|
149
|
+
@request.session[:typus_user_id] = typus_user.id
|
|
150
|
+
get :edit, { :id => typus_user.id }
|
|
151
|
+
|
|
152
|
+
assert_response :success
|
|
153
|
+
assert_template 'edit'
|
|
154
|
+
|
|
155
|
+
get :edit, { :id => typus_users(:admin).id }
|
|
156
|
+
|
|
157
|
+
assert_response :redirect
|
|
158
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
159
|
+
assert flash[:notice]
|
|
160
|
+
assert_equal "As you're not the admin or the owner of this record you cannot edit it.", flash[:notice]
|
|
161
|
+
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def test_should_not_allow_editor_to_destroy_users
|
|
165
|
+
|
|
166
|
+
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
|
167
|
+
typus_user = typus_users(:editor)
|
|
168
|
+
@request.session[:typus_user_id] = typus_user.id
|
|
169
|
+
delete :destroy, :id => typus_users(:admin).id
|
|
170
|
+
|
|
171
|
+
assert_response :redirect
|
|
172
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
173
|
+
assert flash[:notice]
|
|
174
|
+
assert_equal "You're not allowed to remove Typus Users.", flash[:notice]
|
|
175
|
+
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def test_should_not_allow_editor_to_destroy_herself
|
|
179
|
+
|
|
180
|
+
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
|
181
|
+
typus_user = typus_users(:editor)
|
|
182
|
+
@request.session[:typus_user_id] = typus_user.id
|
|
183
|
+
delete :destroy, :id => typus_user.id
|
|
184
|
+
|
|
185
|
+
assert_response :redirect
|
|
186
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
187
|
+
assert flash[:notice]
|
|
188
|
+
assert_equal "You're not allowed to remove Typus Users.", flash[:notice]
|
|
189
|
+
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def test_should_redirect_to_admin_dashboard_if_user_does_not_have_privileges
|
|
193
|
+
|
|
194
|
+
@request.env['HTTP_REFERER'] = '/admin'
|
|
195
|
+
typus_user = typus_users(:designer)
|
|
196
|
+
@request.session[:typus_user_id] = typus_user.id
|
|
197
|
+
get :index
|
|
198
|
+
|
|
199
|
+
assert_response :redirect
|
|
200
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
201
|
+
assert flash[:notice]
|
|
202
|
+
assert_equal "Designer can't display items.", flash[:notice]
|
|
203
|
+
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def test_should_change_root_to_editor_so_editor_can_edit_others_content
|
|
207
|
+
|
|
208
|
+
typus_user = typus_users(:editor)
|
|
209
|
+
@request.session[:typus_user_id] = typus_user.id
|
|
210
|
+
@request.env['HTTP_REFERER'] = '/admin/typus_users'
|
|
211
|
+
|
|
212
|
+
assert_equal 'editor', typus_user.role
|
|
213
|
+
|
|
214
|
+
get :edit, :id => typus_user.id
|
|
215
|
+
assert_response :success
|
|
216
|
+
|
|
217
|
+
get :edit, :id => typus_users(:admin).id
|
|
218
|
+
assert_response :redirect
|
|
219
|
+
assert_redirected_to @request.env['HTTP_REFERER']
|
|
220
|
+
assert flash[:notice]
|
|
221
|
+
assert_equal "As you're not the admin or the owner of this record you cannot edit it.", flash[:notice]
|
|
222
|
+
|
|
223
|
+
##
|
|
224
|
+
# Here we change the behavior, editor has become root, so he
|
|
225
|
+
# has access to all TypusUser records.
|
|
226
|
+
#
|
|
227
|
+
|
|
228
|
+
options = Typus::Configuration.options.merge(:root => 'editor')
|
|
229
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
230
|
+
|
|
231
|
+
get :edit, :id => typus_user.id
|
|
232
|
+
assert_response :success
|
|
233
|
+
|
|
234
|
+
get :edit, :id => typus_users(:admin).id
|
|
235
|
+
assert_response :success
|
|
236
|
+
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
end
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
require 'test/helper'
|
|
2
|
+
|
|
3
|
+
class TypusControllerTest < ActionController::TestCase
|
|
4
|
+
|
|
5
|
+
def setup
|
|
6
|
+
Typus::Configuration.options[:recover_password] = true
|
|
7
|
+
Typus::Configuration.options[:app_name] = 'whatistypus.com'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_should_render_login
|
|
11
|
+
get :sign_in
|
|
12
|
+
assert_response :success
|
|
13
|
+
assert_template 'sign_in'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_should_sign_in_and_redirect_to_dashboard
|
|
17
|
+
typus_user = typus_users(:admin)
|
|
18
|
+
post :sign_in, { :user => { :email => typus_user.email,
|
|
19
|
+
:password => '12345678' } }
|
|
20
|
+
assert_equal typus_user.id, @request.session[:typus_user_id]
|
|
21
|
+
assert_response :redirect
|
|
22
|
+
assert_redirected_to admin_dashboard_path
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_should_return_message_when_sign_in_fails
|
|
26
|
+
post :sign_in, { :user => { :email => 'john@example.com',
|
|
27
|
+
:password => 'XXXXXXXX' } }
|
|
28
|
+
assert_response :redirect
|
|
29
|
+
assert_redirected_to admin_sign_in_path
|
|
30
|
+
assert flash[:error]
|
|
31
|
+
assert_equal "The email and/or password you entered is invalid.", flash[:error]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_should_not_sign_in_a_disabled_user
|
|
35
|
+
typus_user = typus_users(:disabled_user)
|
|
36
|
+
post :sign_in, { :user => { :email => typus_user.email,
|
|
37
|
+
:password => '12345678' } }
|
|
38
|
+
assert_nil @request.session[:typus_user_id]
|
|
39
|
+
assert_response :redirect
|
|
40
|
+
assert_redirected_to admin_sign_in_path
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_should_not_sign_in_a_removed_role
|
|
44
|
+
typus_user = typus_users(:removed_role)
|
|
45
|
+
post :sign_in, { :user => { :email => typus_user.email,
|
|
46
|
+
:password => '12345678' } }
|
|
47
|
+
assert_equal typus_user.id, @request.session[:typus_user_id]
|
|
48
|
+
assert_response :redirect
|
|
49
|
+
assert_redirected_to admin_dashboard_path
|
|
50
|
+
get :dashboard
|
|
51
|
+
assert_redirected_to admin_sign_in_path
|
|
52
|
+
assert_nil @request.session[:typus_user_id]
|
|
53
|
+
assert flash[:notice]
|
|
54
|
+
assert_equal 'Role does no longer exists.', flash[:notice]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_should_not_send_recovery_password_link_to_unexisting_user
|
|
58
|
+
post :recover_password, { :user => { :email => 'unexisting' } }
|
|
59
|
+
assert_response :redirect
|
|
60
|
+
assert_redirected_to admin_recover_password_path
|
|
61
|
+
[ :notice, :error, :warning ].each { |f| assert !flash[f] }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_should_send_recovery_password_link_to_existing_user
|
|
65
|
+
admin = typus_users(:admin)
|
|
66
|
+
post :recover_password, { :user => { :email => admin.email } }
|
|
67
|
+
assert_response :redirect
|
|
68
|
+
assert_redirected_to admin_sign_in_path
|
|
69
|
+
assert flash[:success]
|
|
70
|
+
assert_match /Password recovery link sent to your email/, flash[:success]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_should_sign_out
|
|
74
|
+
admin = typus_users(:admin)
|
|
75
|
+
@request.session[:typus_user_id] = admin.id
|
|
76
|
+
get :sign_out
|
|
77
|
+
assert_nil @request.session[:typus_user_id]
|
|
78
|
+
assert_response :redirect
|
|
79
|
+
assert_redirected_to admin_sign_in_path
|
|
80
|
+
[ :notice, :error, :warning ].each { |f| assert !flash[f] }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_should_verify_we_can_disable_users_and_block_acess_on_the_fly
|
|
84
|
+
|
|
85
|
+
admin = typus_users(:admin)
|
|
86
|
+
@request.session[:typus_user_id] = admin.id
|
|
87
|
+
get :dashboard
|
|
88
|
+
assert_response :success
|
|
89
|
+
|
|
90
|
+
# Disable user ...
|
|
91
|
+
|
|
92
|
+
admin.update_attributes :status => false
|
|
93
|
+
|
|
94
|
+
get :dashboard
|
|
95
|
+
assert_response :redirect
|
|
96
|
+
assert_redirected_to admin_sign_in_path
|
|
97
|
+
|
|
98
|
+
assert flash[:notice]
|
|
99
|
+
assert_equal "Typus user has been disabled.", flash[:notice]
|
|
100
|
+
assert_nil @request.session[:typus_user_id]
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_should_not_allow_reset_password_if_disabled
|
|
105
|
+
|
|
106
|
+
typus_user = typus_users(:admin)
|
|
107
|
+
get :reset_password, { :token => typus_user.token }
|
|
108
|
+
assert_response :success
|
|
109
|
+
assert_template 'reset_password'
|
|
110
|
+
|
|
111
|
+
options = Typus::Configuration.options.merge(:recover_password => false)
|
|
112
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
113
|
+
|
|
114
|
+
get :reset_password
|
|
115
|
+
assert_response :redirect
|
|
116
|
+
assert_redirected_to admin_sign_in_path
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_should_sign_in_user_after_password_change
|
|
121
|
+
typus_user = typus_users(:admin)
|
|
122
|
+
post :reset_password, { :token => typus_user.token, :user => { :password => '12345678', :password_confirmation => '12345678' } }
|
|
123
|
+
assert_response :redirect
|
|
124
|
+
assert_redirected_to admin_dashboard_path
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_should_be_redirected_if_password_does_not_match_confirmation
|
|
128
|
+
typus_user = typus_users(:admin)
|
|
129
|
+
post :reset_password, { :token => typus_user.token, :user => { :password => 'drowssap', :password_confirmation => 'drowssap2' } }
|
|
130
|
+
assert_response :success
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_should_only_be_allowed_to_reset_password
|
|
134
|
+
typus_user = typus_users(:admin)
|
|
135
|
+
post :reset_password, { :token => typus_user.token, :user => { :password => 'drowssap', :password_confirmation => 'drowssap', :role => 'superadmin' } }
|
|
136
|
+
typus_user.reload
|
|
137
|
+
assert_not_equal typus_user.role, 'superadmin'
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def test_should_return_404_when_reseting_passsowrd_if_token_is_invalid
|
|
141
|
+
assert_raise(ActiveRecord::RecordNotFound) { get :reset_password, { :token => 'INVALID' } }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def test_should_allow_a_user_with_valid_token_to_change_password
|
|
145
|
+
typus_user = typus_users(:admin)
|
|
146
|
+
get :reset_password, { :token => typus_user.token }
|
|
147
|
+
assert_response :success
|
|
148
|
+
assert_template 'reset_password'
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def test_should_verify_typus_sign_in_layout_includes_recover_password_link
|
|
152
|
+
options = Typus::Configuration.options.merge(:recover_password => true)
|
|
153
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
154
|
+
get :sign_in
|
|
155
|
+
assert @response.body.include?('Recover password')
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def test_should_verify_typus_sign_in_layout_does_not_include_recover_password_link
|
|
159
|
+
options = Typus::Configuration.options.merge(:recover_password => false)
|
|
160
|
+
Typus::Configuration.stubs(:options).returns(options)
|
|
161
|
+
get :sign_in
|
|
162
|
+
assert !@response.body.include?('Recover password')
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def test_should_render_typus_login_footer
|
|
166
|
+
expected = 'Typus'
|
|
167
|
+
get :sign_in
|
|
168
|
+
assert_response :success
|
|
169
|
+
assert_match /#{expected}/, @response.body
|
|
170
|
+
assert_match /layouts\/typus/, @controller.active_layout.to_s
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def test_should_render_admin_login_bottom
|
|
174
|
+
get :sign_in
|
|
175
|
+
assert_response :success
|
|
176
|
+
assert_select 'h1', 'whatistypus.com'
|
|
177
|
+
assert_match /layouts\/typus/, @controller.active_layout.to_s
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def test_should_verify_page_title_on_sign_in
|
|
181
|
+
get :sign_in
|
|
182
|
+
assert_select 'title', "#{Typus::Configuration.options[:app_name]} - Sign in"
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def test_should_create_first_typus_user
|
|
186
|
+
|
|
187
|
+
TypusUser.destroy_all
|
|
188
|
+
assert_nil @request.session[:typus_user_id]
|
|
189
|
+
assert TypusUser.find(:all).empty?
|
|
190
|
+
|
|
191
|
+
get :sign_in
|
|
192
|
+
assert_response :redirect
|
|
193
|
+
assert_redirected_to admin_sign_up_path
|
|
194
|
+
|
|
195
|
+
get :sign_up
|
|
196
|
+
assert flash[:notice]
|
|
197
|
+
assert_equal 'Enter your email below to create the first user.', flash[:notice]
|
|
198
|
+
|
|
199
|
+
post :sign_up, :user => { :email => 'example.com' }
|
|
200
|
+
assert_response :success
|
|
201
|
+
assert flash[:error]
|
|
202
|
+
assert_equal 'That doesn\'t seem like a valid email address.', flash[:error]
|
|
203
|
+
|
|
204
|
+
post :sign_up, :user => { :email => 'john@example.com' }
|
|
205
|
+
assert_response :redirect
|
|
206
|
+
assert_redirected_to admin_dashboard_path
|
|
207
|
+
assert flash[:notice]
|
|
208
|
+
assert_equal "Password set to \"columbia\".", flash[:notice]
|
|
209
|
+
assert @request.session[:typus_user_id]
|
|
210
|
+
assert !TypusUser.find(:all).empty?
|
|
211
|
+
|
|
212
|
+
get :sign_out
|
|
213
|
+
assert_nil @request.session[:typus_user_id]
|
|
214
|
+
assert_redirected_to admin_sign_in_path
|
|
215
|
+
|
|
216
|
+
get :sign_up
|
|
217
|
+
assert_redirected_to admin_sign_in_path
|
|
218
|
+
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def test_should_redirect_to_login_if_not_logged
|
|
222
|
+
@request.session[:typus_user_id] = nil
|
|
223
|
+
get :dashboard
|
|
224
|
+
assert_response :redirect
|
|
225
|
+
assert_redirected_to admin_sign_in_path
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def test_should_render_dashboard
|
|
229
|
+
@request.session[:typus_user_id] = typus_users(:admin).id
|
|
230
|
+
get :dashboard
|
|
231
|
+
assert_response :success
|
|
232
|
+
assert_template 'dashboard'
|
|
233
|
+
assert_match 'whatistypus.com', @response.body
|
|
234
|
+
assert_match /layouts\/admin/, @controller.active_layout.to_s
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def test_should_verify_sign_up_works
|
|
238
|
+
@request.session[:typus_user_id] = typus_users(:admin).id
|
|
239
|
+
TypusUser.destroy_all
|
|
240
|
+
get :sign_up
|
|
241
|
+
assert_response :success
|
|
242
|
+
assert_template 'sign_up'
|
|
243
|
+
assert_match /layouts\/typus/, @controller.active_layout.to_s
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def test_should_verify_page_title_on_dashboard
|
|
247
|
+
@request.session[:typus_user_id] = typus_users(:admin).id
|
|
248
|
+
get :dashboard
|
|
249
|
+
assert_select 'title', "#{Typus::Configuration.options[:app_name]} - Dashboard"
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def test_should_verify_link_to_edit_typus_user
|
|
253
|
+
|
|
254
|
+
typus_user = typus_users(:admin)
|
|
255
|
+
@request.session[:typus_user_id] = typus_user.id
|
|
256
|
+
get :dashboard
|
|
257
|
+
assert_response :success
|
|
258
|
+
|
|
259
|
+
assert_match "href=\"\/admin\/typus_users\/edit\/#{typus_user.id}\"", @response.body
|
|
260
|
+
|
|
261
|
+
assert_select 'body div#header' do
|
|
262
|
+
assert_select 'a', 'Admin Example'
|
|
263
|
+
assert_select 'a', 'Sign out'
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def test_should_verify_link_to_sign_out
|
|
269
|
+
|
|
270
|
+
@request.session[:typus_user_id] = typus_users(:admin).id
|
|
271
|
+
get :dashboard
|
|
272
|
+
assert_response :success
|
|
273
|
+
|
|
274
|
+
assert_match "href=\"\/admin\/sign_out\"", @response.body
|
|
275
|
+
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def test_should_show_add_links_in_resources_list_for_admin
|
|
279
|
+
|
|
280
|
+
@request.session[:typus_user_id] = typus_users(:admin).id
|
|
281
|
+
get :dashboard
|
|
282
|
+
|
|
283
|
+
%w( typus_users posts pages assets ).each do |resource|
|
|
284
|
+
assert_match "/admin/#{resource}/new", @response.body
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
%w( statuses orders ).each do |resource|
|
|
288
|
+
assert_no_match /\/admin\/#{resource}\n/, @response.body
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def test_should_show_add_links_in_resources_list_for_editor
|
|
294
|
+
editor = typus_users(:editor)
|
|
295
|
+
@request.session[:typus_user_id] = editor.id
|
|
296
|
+
get :dashboard
|
|
297
|
+
assert_match '/admin/posts/new', @response.body
|
|
298
|
+
assert_no_match /\/admin\/typus_users\/new/, @response.body
|
|
299
|
+
# We have loaded categories as a module, so are not displayed
|
|
300
|
+
# on the applications list.
|
|
301
|
+
assert_no_match /\/admin\/categories\/new/, @response.body
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
def test_should_show_add_links_in_resources_list_for_designer
|
|
305
|
+
designer = typus_users(:designer)
|
|
306
|
+
@request.session[:typus_user_id] = designer.id
|
|
307
|
+
get :dashboard
|
|
308
|
+
assert_no_match /\/admin\/posts\/new/, @response.body
|
|
309
|
+
assert_no_match /\/admin\/typus_users\/new/, @response.body
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def test_should_render_application_dashboard_template_extensions
|
|
313
|
+
admin = typus_users(:admin)
|
|
314
|
+
@request.session[:typus_user_id] = admin.id
|
|
315
|
+
get :dashboard
|
|
316
|
+
assert_response :success
|
|
317
|
+
partials = %w( _sidebar.html.erb )
|
|
318
|
+
partials.each { |p| assert_match p, @response.body }
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
end
|