branston 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/branston/Gemfile +25 -0
- data/lib/branston/Gemfile.lock +76 -0
- data/lib/branston/app/controllers/application_controller.rb +1 -1
- data/lib/branston/app/controllers/outcomes_controller.rb +2 -0
- data/lib/branston/app/controllers/stories_controller.rb +82 -86
- data/lib/branston/app/controllers/users_controller.rb +69 -11
- data/lib/branston/app/helpers/iterations_helper.rb +13 -13
- data/lib/branston/app/models/iteration.rb +3 -1
- data/lib/branston/app/models/release.rb +0 -1
- data/lib/branston/app/models/story.rb +30 -28
- data/lib/branston/app/models/user.rb +46 -1
- data/lib/branston/app/views/layouts/_header.html.erb +8 -3
- data/lib/branston/app/views/layouts/user_roles.html.erb +5 -5
- data/lib/branston/app/views/sessions/new.html.erb +8 -14
- data/lib/branston/app/views/users/_admin_controls.html.erb +14 -0
- data/lib/branston/app/views/users/_form.html.erb +27 -0
- data/lib/branston/app/views/users/edit.html.erb +9 -0
- data/lib/branston/app/views/users/index.html.erb +14 -0
- data/lib/branston/app/views/users/new.html.erb +3 -22
- data/lib/branston/config/boot.rb +20 -0
- data/lib/branston/config/environment.rb +2 -7
- data/lib/branston/config/environments/test.rb +0 -8
- data/lib/branston/config/preinitializer.rb +21 -0
- data/lib/branston/config/routes.rb +15 -10
- data/lib/branston/db/development.sqlite3 +0 -0
- data/lib/branston/db/development_structure.sql +21 -8
- data/lib/branston/db/migrate/20100723161424_add_state_to_user.rb +12 -0
- data/lib/branston/db/migrate/20100726150322_add_activation_fields_to_user.rb +12 -0
- data/lib/branston/db/migrate/20100729125551_set_default_user_state_to_pending.rb +10 -0
- data/lib/branston/db/migrate/20100812133837_add_is_admin_property_to_user.rb +10 -0
- data/lib/branston/db/migrate/20100812140532_set_default_user_state_to_active.rb +10 -0
- data/lib/branston/db/migrate/20100812143455_add_default_admin_user.rb +17 -0
- data/lib/branston/db/migrate/20110408162438_remove_is_admin_property_and_add_role_instead.rb +12 -0
- data/lib/branston/db/pristine.sqlite3 +0 -0
- data/lib/branston/db/schema.rb +6 -8
- data/lib/branston/db/test.sqlite3 +0 -0
- data/lib/branston/log/development.log +1181 -433
- data/lib/branston/log/test.log +145306 -52026
- data/lib/branston/test/blueprints.rb +22 -28
- data/lib/branston/test/functional/iterations_controller_test.rb +149 -113
- data/lib/branston/test/functional/outcomes_controller_test.rb +94 -60
- data/lib/branston/test/functional/preconditions_controller_test.rb +101 -67
- data/lib/branston/test/functional/releases_controller_test.rb +85 -49
- data/lib/branston/test/functional/scenarios_controller_test.rb +104 -70
- data/lib/branston/test/functional/stories_controller_test.rb +41 -12
- data/lib/branston/test/functional/users_controller_test.rb +364 -43
- data/lib/branston/test/unit/iteration_test.rb +37 -6
- data/lib/branston/test/unit/outcome_test.rb +2 -2
- data/lib/branston/test/unit/participation_test.rb +2 -2
- data/lib/branston/test/unit/precondition_test.rb +3 -3
- data/lib/branston/test/unit/release_test.rb +4 -0
- data/lib/branston/test/unit/scenario_test.rb +4 -4
- data/lib/branston/test/unit/story_test.rb +62 -40
- data/lib/branston/test/unit/user_test.rb +195 -5
- metadata +136 -156
- data/lib/branston/app/controllers/user_roles_controller.rb +0 -105
- data/lib/branston/app/helpers/user_roles_helper.rb +0 -2
- data/lib/branston/app/models/user_role.rb +0 -21
- data/lib/branston/app/views/layouts/outcomes.html.erb +0 -17
- data/lib/branston/app/views/layouts/preconditions.html.erb +0 -17
- data/lib/branston/app/views/layouts/releases.html.erb +0 -17
- data/lib/branston/app/views/user_roles/edit.html.erb +0 -16
- data/lib/branston/app/views/user_roles/index.html.erb +0 -20
- data/lib/branston/app/views/user_roles/new.html.erb +0 -15
- data/lib/branston/app/views/user_roles/show.html.erb +0 -8
- data/lib/branston/coverage/app-controllers-application_controller_rb.html +0 -231
- data/lib/branston/coverage/app-controllers-iterations_controller_rb.html +0 -801
- data/lib/branston/coverage/app-controllers-outcomes_controller_rb.html +0 -759
- data/lib/branston/coverage/app-controllers-preconditions_controller_rb.html +0 -783
- data/lib/branston/coverage/app-controllers-releases_controller_rb.html +0 -705
- data/lib/branston/coverage/app-controllers-scenarios_controller_rb.html +0 -777
- data/lib/branston/coverage/app-controllers-sessions_controller_rb.html +0 -411
- data/lib/branston/coverage/app-controllers-stories_controller_rb.html +0 -1071
- data/lib/branston/coverage/app-controllers-user_roles_controller_rb.html +0 -693
- data/lib/branston/coverage/app-controllers-users_controller_rb.html +0 -315
- data/lib/branston/coverage/app-helpers-application_helper_rb.html +0 -327
- data/lib/branston/coverage/app-helpers-iterations_helper_rb.html +0 -363
- data/lib/branston/coverage/app-helpers-outcomes_helper_rb.html +0 -75
- data/lib/branston/coverage/app-helpers-preconditions_helper_rb.html +0 -75
- data/lib/branston/coverage/app-helpers-releases_helper_rb.html +0 -75
- data/lib/branston/coverage/app-helpers-sessions_helper_rb.html +0 -75
- data/lib/branston/coverage/app-helpers-stories_helper_rb.html +0 -75
- data/lib/branston/coverage/app-helpers-user_roles_helper_rb.html +0 -75
- data/lib/branston/coverage/app-models-iteration_rb.html +0 -321
- data/lib/branston/coverage/app-models-outcome_rb.html +0 -243
- data/lib/branston/coverage/app-models-participation_rb.html +0 -189
- data/lib/branston/coverage/app-models-precondition_rb.html +0 -243
- data/lib/branston/coverage/app-models-release_rb.html +0 -195
- data/lib/branston/coverage/app-models-scenario_rb.html +0 -231
- data/lib/branston/coverage/app-models-story_rb.html +0 -621
- data/lib/branston/coverage/app-models-user_rb.html +0 -513
- data/lib/branston/coverage/app-models-user_role_rb.html +0 -189
- data/lib/branston/coverage/index.html +0 -570
- data/lib/branston/coverage/jquery-1.3.2.min.js +0 -19
- data/lib/branston/coverage/jquery.tablesorter.min.js +0 -15
- data/lib/branston/coverage/lib-client_rb.html +0 -537
- data/lib/branston/coverage/lib-faker_extras_rb.html +0 -207
- data/lib/branston/coverage/lib-story_generator_rb.html +0 -873
- data/lib/branston/coverage/print.css +0 -12
- data/lib/branston/coverage/rcov.js +0 -42
- data/lib/branston/coverage/screen.css +0 -270
- data/lib/branston/db/migrate/20091127131037_create_user_roles.rb +0 -13
- data/lib/branston/db/migrate/20091127172950_add_story_id_to_user_role.rb +0 -10
- data/lib/branston/test/functional/user_roles_controller_test.rb +0 -71
- data/lib/branston/test/unit/helpers/user_roles_helper_test.rb +0 -4
- data/lib/branston/test/unit/user_role_test.rb +0 -9
- data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_flat.txt +0 -8
- data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_graph.html +0 -6718
- data/lib/branston/tmp/performance/BrowsingTest#test_homepage_process_time_tree.txt +0 -9942
- data/lib/branston/vendor/plugins/state_machine/CHANGELOG.rdoc +0 -298
- data/lib/branston/vendor/plugins/state_machine/LICENSE +0 -20
- data/lib/branston/vendor/plugins/state_machine/README.rdoc +0 -466
- data/lib/branston/vendor/plugins/state_machine/Rakefile +0 -98
- data/lib/branston/vendor/plugins/state_machine/examples/AutoShop_state.png +0 -0
- data/lib/branston/vendor/plugins/state_machine/examples/Car_state.png +0 -0
- data/lib/branston/vendor/plugins/state_machine/examples/TrafficLight_state.png +0 -0
- data/lib/branston/vendor/plugins/state_machine/examples/Vehicle_state.png +0 -0
- data/lib/branston/vendor/plugins/state_machine/examples/auto_shop.rb +0 -11
- data/lib/branston/vendor/plugins/state_machine/examples/car.rb +0 -19
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/controller.rb +0 -51
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/model.rb +0 -28
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_edit.html.erb +0 -24
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_index.html.erb +0 -23
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_new.html.erb +0 -13
- data/lib/branston/vendor/plugins/state_machine/examples/merb-rest/view_show.html.erb +0 -17
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/controller.rb +0 -43
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/migration.rb +0 -11
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/model.rb +0 -23
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_edit.html.erb +0 -25
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_index.html.erb +0 -23
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_new.html.erb +0 -14
- data/lib/branston/vendor/plugins/state_machine/examples/rails-rest/view_show.html.erb +0 -17
- data/lib/branston/vendor/plugins/state_machine/examples/traffic_light.rb +0 -7
- data/lib/branston/vendor/plugins/state_machine/examples/vehicle.rb +0 -31
- data/lib/branston/vendor/plugins/state_machine/init.rb +0 -1
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine.rb +0 -388
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/assertions.rb +0 -36
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/callback.rb +0 -189
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/condition_proxy.rb +0 -94
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/eval_helpers.rb +0 -67
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/event.rb +0 -252
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/event_collection.rb +0 -122
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/extensions.rb +0 -149
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/guard.rb +0 -230
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations.rb +0 -68
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record.rb +0 -492
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record/locale.rb +0 -11
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/active_record/observer.rb +0 -41
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/data_mapper.rb +0 -351
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/data_mapper/observer.rb +0 -139
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/integrations/sequel.rb +0 -322
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/machine.rb +0 -1467
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/machine_collection.rb +0 -155
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/matcher.rb +0 -123
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/matcher_helpers.rb +0 -54
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/node_collection.rb +0 -152
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/state.rb +0 -249
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/state_collection.rb +0 -112
- data/lib/branston/vendor/plugins/state_machine/lib/state_machine/transition.rb +0 -394
- data/lib/branston/vendor/plugins/state_machine/state_machine.gemspec +0 -30
- data/lib/branston/vendor/plugins/state_machine/tasks/state_machine.rake +0 -1
- data/lib/branston/vendor/plugins/state_machine/tasks/state_machine.rb +0 -30
- data/lib/branston/vendor/plugins/state_machine/test/classes/switch.rb +0 -11
- data/lib/branston/vendor/plugins/state_machine/test/functional/state_machine_test.rb +0 -941
- data/lib/branston/vendor/plugins/state_machine/test/test_helper.rb +0 -4
- data/lib/branston/vendor/plugins/state_machine/test/unit/assertions_test.rb +0 -40
- data/lib/branston/vendor/plugins/state_machine/test/unit/callback_test.rb +0 -455
- data/lib/branston/vendor/plugins/state_machine/test/unit/condition_proxy_test.rb +0 -328
- data/lib/branston/vendor/plugins/state_machine/test/unit/eval_helpers_test.rb +0 -120
- data/lib/branston/vendor/plugins/state_machine/test/unit/event_collection_test.rb +0 -326
- data/lib/branston/vendor/plugins/state_machine/test/unit/event_test.rb +0 -743
- data/lib/branston/vendor/plugins/state_machine/test/unit/guard_test.rb +0 -908
- data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/active_record_test.rb +0 -1367
- data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/data_mapper_test.rb +0 -962
- data/lib/branston/vendor/plugins/state_machine/test/unit/integrations/sequel_test.rb +0 -859
- data/lib/branston/vendor/plugins/state_machine/test/unit/integrations_test.rb +0 -42
- data/lib/branston/vendor/plugins/state_machine/test/unit/invalid_event_test.rb +0 -7
- data/lib/branston/vendor/plugins/state_machine/test/unit/invalid_transition_test.rb +0 -7
- data/lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb +0 -938
- data/lib/branston/vendor/plugins/state_machine/test/unit/machine_test.rb +0 -2004
- data/lib/branston/vendor/plugins/state_machine/test/unit/matcher_helpers_test.rb +0 -37
- data/lib/branston/vendor/plugins/state_machine/test/unit/matcher_test.rb +0 -155
- data/lib/branston/vendor/plugins/state_machine/test/unit/node_collection_test.rb +0 -207
- data/lib/branston/vendor/plugins/state_machine/test/unit/state_collection_test.rb +0 -280
- data/lib/branston/vendor/plugins/state_machine/test/unit/state_machine_test.rb +0 -31
- data/lib/branston/vendor/plugins/state_machine/test/unit/state_test.rb +0 -795
- data/lib/branston/vendor/plugins/state_machine/test/unit/transition_test.rb +0 -1212
@@ -77,7 +77,6 @@ class StoriesControllerTest < ActionController::TestCase
|
|
77
77
|
end
|
78
78
|
|
79
79
|
context "creating a story" do
|
80
|
-
|
81
80
|
context "with valid params" do
|
82
81
|
setup do
|
83
82
|
assert_difference("Story.count") do
|
@@ -164,8 +163,10 @@ class StoriesControllerTest < ActionController::TestCase
|
|
164
163
|
end
|
165
164
|
end
|
166
165
|
|
167
|
-
context "with story status set to '
|
166
|
+
context "with story status set to 'in_progress'" do
|
168
167
|
setup do
|
168
|
+
@story.status = "in_progress"
|
169
|
+
@story.save
|
169
170
|
put :update,{ :id => @story.to_param, :story => {
|
170
171
|
:description => "bar", :status => "new"},
|
171
172
|
:iteration_id => @iteration.to_param }
|
@@ -189,7 +190,6 @@ class StoriesControllerTest < ActionController::TestCase
|
|
189
190
|
assert_equal assigns(:story).status, "completed"
|
190
191
|
end
|
191
192
|
end
|
192
|
-
|
193
193
|
end
|
194
194
|
|
195
195
|
context "with invalid parameters" do
|
@@ -204,22 +204,51 @@ class StoriesControllerTest < ActionController::TestCase
|
|
204
204
|
end
|
205
205
|
end
|
206
206
|
end
|
207
|
-
|
208
207
|
end
|
209
208
|
|
210
|
-
context "
|
209
|
+
context "when a request comes from the Branston client" do
|
210
|
+
setup do
|
211
|
+
@user = User.make
|
212
|
+
end
|
211
213
|
|
212
|
-
|
213
|
-
|
214
|
-
|
214
|
+
context "with a username and password" do
|
215
|
+
setup do
|
216
|
+
get :show,
|
217
|
+
:id => @story.to_param, :iteration_id => @iteration.to_param,
|
218
|
+
:username => @user.login, :password => "password"
|
219
|
+
end
|
220
|
+
|
221
|
+
should "show details about a story" do
|
222
|
+
assert_response :success
|
223
|
+
assert assigns(:story)
|
224
|
+
assert_match /#{@story.description.gsub('"', """)}/, @response.body
|
225
|
+
end
|
215
226
|
end
|
216
227
|
|
217
|
-
|
218
|
-
|
219
|
-
|
228
|
+
context "where the the slug is not found" do
|
229
|
+
setup do
|
230
|
+
@user = User.make
|
231
|
+
get :show,
|
232
|
+
:id => 'none-such-story', :iteration_id => @iteration.to_param,
|
233
|
+
:username => @user.login, :password => "monkey"
|
234
|
+
end
|
235
|
+
should "fail gracefully" do
|
236
|
+
assert_response 404
|
237
|
+
end
|
220
238
|
end
|
221
|
-
end
|
222
239
|
|
240
|
+
context "without a username and password" do
|
241
|
+
setup do
|
242
|
+
get :show,
|
243
|
+
:id => @story.to_param, :iteration_id => @iteration.to_param
|
244
|
+
end
|
245
|
+
should "fail gracefully" do
|
246
|
+
get :show, :id => 'none-such-story', :iteration_id => @iteration.to_param
|
247
|
+
assert_response 404
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
223
252
|
end
|
224
253
|
end
|
225
254
|
|
@@ -5,57 +5,378 @@ require 'users_controller'
|
|
5
5
|
class UsersController; def rescue_action(e) raise e end; end
|
6
6
|
|
7
7
|
class UsersControllerTest < ActionController::TestCase
|
8
|
+
context "The UsersController" do
|
9
|
+
context "when the user is not logged in" do
|
10
|
+
[:index, :new, :edit].each do |action|
|
11
|
+
context "on GET to #{action.to_s}" do
|
12
|
+
setup do
|
13
|
+
get action
|
14
|
+
end
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_allow_new
|
17
|
-
get :new
|
18
|
-
assert_response :success
|
19
|
-
end
|
16
|
+
should "redirect to login" do
|
17
|
+
assert_redirected_to new_session_path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
context "on PUT to :update" do
|
23
|
+
setup do
|
24
|
+
put :update
|
25
|
+
end
|
26
|
+
should "redirect to login" do
|
27
|
+
assert_redirected_to new_session_path
|
28
|
+
end
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
context "on POST to :create" do
|
32
|
+
setup do
|
33
|
+
post :create
|
34
|
+
end
|
35
|
+
should "redirect to login" do
|
36
|
+
assert_redirected_to new_session_path
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
[:activate, :suspend, :destroy].each do |action|
|
41
|
+
context "on POST to #{action.to_s}" do
|
42
|
+
setup do
|
43
|
+
post action
|
44
|
+
end
|
45
|
+
|
46
|
+
should "redirect to login" do
|
47
|
+
assert_redirected_to new_session_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
36
51
|
|
37
|
-
def test_should_require_password_confirmation_on_signup
|
38
|
-
assert_no_difference 'User.count' do
|
39
|
-
create_user(:password_confirmation => nil)
|
40
|
-
assert assigns(:user).errors.on(:password_confirmation)
|
41
|
-
assert_response :success
|
42
52
|
end
|
43
|
-
end
|
44
53
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
54
|
+
context "when logged in" do
|
55
|
+
setup do
|
56
|
+
login_as(User.make)
|
57
|
+
end
|
58
|
+
|
59
|
+
context "on GET to index" do
|
60
|
+
setup do
|
61
|
+
get :index
|
62
|
+
end
|
63
|
+
should respond_with :success
|
64
|
+
should render_template :index
|
65
|
+
should assign_to :users
|
66
|
+
end
|
67
|
+
|
68
|
+
context "on GET to new" do
|
69
|
+
context "as an admin user" do
|
70
|
+
setup do
|
71
|
+
@admin = User.make(:admin)
|
72
|
+
login_as(@admin)
|
73
|
+
get :new
|
74
|
+
end
|
75
|
+
should respond_with :success
|
76
|
+
end
|
77
|
+
context "as a non-admin user" do
|
78
|
+
setup do
|
79
|
+
login_as(User.make)
|
80
|
+
get :new
|
81
|
+
end
|
82
|
+
should redirect_to("the users page") { users_path }
|
83
|
+
should set_the_flash.to("You are not allowed to do that.")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "on POST to create" do
|
88
|
+
context "as an admin user" do
|
89
|
+
setup do
|
90
|
+
@admin = User.make(:admin)
|
91
|
+
login_as(@admin)
|
92
|
+
end
|
93
|
+
context "with all parameters" do
|
94
|
+
setup do
|
95
|
+
assert_difference 'User.count' do
|
96
|
+
create_user(:role => "admin")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
should redirect_to("the users page"){ users_path }
|
101
|
+
should "set the user to be an admin" do
|
102
|
+
assert assigns(:user).has_role?("admin")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "with the :state param set to 'active'" do
|
107
|
+
setup do
|
108
|
+
create_user(:state => "active")
|
109
|
+
end
|
110
|
+
|
111
|
+
should "create user with state 'active'" do
|
112
|
+
assert_equal assigns(:user).state, "active"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "with no login supplied" do
|
117
|
+
setup do
|
118
|
+
assert_no_difference 'User.count' do
|
119
|
+
create_user(:login => nil)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
should respond_with :success
|
124
|
+
should "have errors on the user's login" do
|
125
|
+
assert assigns(:user).errors.on(:login)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "with no password supplied" do
|
130
|
+
setup do
|
131
|
+
assert_no_difference 'User.count' do
|
132
|
+
create_user(:password => nil)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
should respond_with :success
|
137
|
+
should "have errors on the user's password" do
|
138
|
+
assert assigns(:user).errors.on(:password)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "with no password_confirmation supplied" do
|
143
|
+
setup do
|
144
|
+
assert_no_difference 'User.count' do
|
145
|
+
create_user(:password_confirmation => nil)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
should respond_with :success
|
150
|
+
should "have errors on the user's password_confirmation" do
|
151
|
+
assert assigns(:user).errors.on(:password_confirmation)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "with no email supplied" do
|
156
|
+
setup do
|
157
|
+
assert_no_difference 'User.count' do
|
158
|
+
create_user(:email => nil)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
should respond_with :success
|
162
|
+
should "have errors on the user's email" do
|
163
|
+
assert assigns(:user).errors.on(:email)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "as a non-admin user" do
|
169
|
+
setup do
|
170
|
+
@user = User.make
|
171
|
+
login_as(@user)
|
172
|
+
post :create
|
173
|
+
end
|
174
|
+
|
175
|
+
should redirect_to("the users page") { users_path }
|
176
|
+
should set_the_flash.to("You are not allowed to do that.")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
[:activate, :suspend, :destroy].each do |action|
|
181
|
+
context "on POST to #{action.to_s}" do
|
182
|
+
context "as a non-admin user" do
|
183
|
+
setup do
|
184
|
+
post action, :id => User.make.id
|
185
|
+
end
|
186
|
+
should redirect_to("the users page"){ users_path }
|
187
|
+
should set_the_flash.to("You are not allowed to do that.")
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context "on POST to suspend" do
|
193
|
+
context "as an admin user" do
|
194
|
+
setup do
|
195
|
+
login_as(User.make(:admin))
|
196
|
+
@user = User.make(:state => "active")
|
197
|
+
@original_state = @user.state
|
198
|
+
post :suspend, :id => @user.id
|
199
|
+
end
|
200
|
+
should "suspend the user" do
|
201
|
+
assert_equal User.find(@user.id).state, "suspended"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "on POST to activate" do
|
207
|
+
context "as an admin user" do
|
208
|
+
context "when user has state 'suspended'" do
|
209
|
+
setup do
|
210
|
+
login_as(User.make(:admin))
|
211
|
+
@user = User.make(:state => "suspended")
|
212
|
+
@original_state = @user.state
|
213
|
+
@user.activated_at = Time.now
|
214
|
+
post :activate, :id => @user.id
|
215
|
+
end
|
216
|
+
should "activate the user" do
|
217
|
+
assert_equal "active", assigns(:user).state
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "when user has state 'pending'" do
|
223
|
+
context "as an admin user" do
|
224
|
+
setup do
|
225
|
+
login_as(User.make(:admin))
|
226
|
+
@user = User.make(:state => "pending")
|
227
|
+
@original_state = @user.state
|
228
|
+
@user.activated_at = Time.now
|
229
|
+
post :activate, :id => @user.id
|
230
|
+
end
|
231
|
+
should "activate the user" do
|
232
|
+
assert_equal assigns(:user).state, "active"
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context "on POST to destroy" do
|
239
|
+
context "as an admin user" do
|
240
|
+
setup do
|
241
|
+
login_as(User.make(:admin))
|
242
|
+
@user = User.make(:state => "pending")
|
243
|
+
@original_state = @user.state
|
244
|
+
post :destroy, :id => @user.id
|
245
|
+
end
|
246
|
+
should "delete the user" do
|
247
|
+
assert_equal assigns(:user).state, "deleted"
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
context "on GET to edit" do
|
253
|
+
setup do
|
254
|
+
@user = User.make
|
255
|
+
end
|
256
|
+
context "as an admin user" do
|
257
|
+
setup do
|
258
|
+
@admin = User.make(:admin)
|
259
|
+
login_as(@admin)
|
260
|
+
get :edit, :id => @user.id
|
261
|
+
end
|
262
|
+
should respond_with :success
|
263
|
+
should render_template "edit"
|
264
|
+
should assign_to :user
|
265
|
+
should "retrieve the right user" do
|
266
|
+
assert_equal @user, assigns(:user)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context "for a user changing their own details" do
|
271
|
+
setup do
|
272
|
+
login_as(@user)
|
273
|
+
get :edit, :id => @user.id
|
274
|
+
end
|
275
|
+
should respond_with :success
|
276
|
+
should render_template "edit"
|
277
|
+
should assign_to :user
|
278
|
+
should "retrieve the right user" do
|
279
|
+
assert_equal @user, assigns(:user)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context "for a non-admin user" do
|
284
|
+
setup do
|
285
|
+
get :edit, :id => @user.id
|
286
|
+
end
|
287
|
+
should_not assign_to :user
|
288
|
+
should set_the_flash.to "You are not allowed to do that."
|
289
|
+
should redirect_to("the users list") { users_path }
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
context "on PUT to update" do
|
294
|
+
context "as an admin user" do
|
295
|
+
setup do
|
296
|
+
@user = User.make
|
297
|
+
@admin = User.make(:admin)
|
298
|
+
login_as(@admin)
|
299
|
+
end
|
300
|
+
context "with good params" do
|
301
|
+
setup do
|
302
|
+
put :update, :id => @user.id, :user => {:email => "foo@superfoo.org", :role => "admin" }
|
303
|
+
end
|
304
|
+
should redirect_to("the users list") { users_path }
|
305
|
+
should assign_to :user
|
306
|
+
should "retrieve the right user" do
|
307
|
+
assert_equal @user, assigns(:user)
|
308
|
+
end
|
309
|
+
should "update the email properly" do
|
310
|
+
assert_equal "foo@superfoo.org", assigns(:user).email
|
311
|
+
end
|
312
|
+
should "allow the role change" do
|
313
|
+
assert_equal true, assigns(:user).has_role?("admin")
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
context "with bad params" do
|
318
|
+
setup do
|
319
|
+
put :update, :id => @user.id, :user => {:email => "foo", :role => "admin" }
|
320
|
+
end
|
321
|
+
should respond_with :success
|
322
|
+
should render_template 'edit'
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
context "as the user changing their own details" do
|
327
|
+
setup do
|
328
|
+
@user = User.make
|
329
|
+
login_as(@user)
|
330
|
+
end
|
331
|
+
|
332
|
+
context "with good params" do
|
333
|
+
setup do
|
334
|
+
put :update, :id => @user.id, :user => {:email => "foo@superfoo.org", :is_admin => true }
|
335
|
+
end
|
336
|
+
should redirect_to("the users list") { users_path }
|
337
|
+
should assign_to :user
|
338
|
+
should "retrieve the right user" do
|
339
|
+
assert_equal @user, assigns(:user)
|
340
|
+
end
|
341
|
+
should "update the email properly" do
|
342
|
+
assert_equal "foo@superfoo.org", assigns(:user).email
|
343
|
+
end
|
344
|
+
should "not allow the is_admin state to change" do
|
345
|
+
assert_equal false, assigns(:user).has_role?("admin")
|
346
|
+
end
|
347
|
+
end
|
348
|
+
context "with bad params" do
|
349
|
+
setup do
|
350
|
+
put :update, :id => @user.id, :user => {:email => "foo", :is_admin => true }
|
351
|
+
end
|
352
|
+
should respond_with :success
|
353
|
+
should render_template 'edit'
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
context "as some random non-admin user" do
|
358
|
+
setup do
|
359
|
+
@user = User.make
|
360
|
+
@another_user = User.make
|
361
|
+
login_as(@another_user)
|
362
|
+
put :update, :id => @user.id, :user => {:email => "foo", :role => "admin" }
|
363
|
+
@user.reload
|
364
|
+
end
|
365
|
+
should redirect_to("the users page") { users_path }
|
366
|
+
should set_the_flash.to "You are not allowed to do that."
|
367
|
+
should "not allow the role change" do
|
368
|
+
assert_not_equal("admin", @user.role)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
50
372
|
end
|
51
373
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
374
|
|
56
375
|
protected
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
376
|
+
|
377
|
+
def create_user(options = {})
|
378
|
+
post :create, :user => { :login => 'quire', :email => 'quire@example.com',
|
379
|
+
:password => 'quire69', :password_confirmation => 'quire69' }.merge(options)
|
380
|
+
end
|
61
381
|
end
|
382
|
+
|