benaldred-clearance 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/CHANGELOG.md +274 -0
  2. data/LICENSE +21 -0
  3. data/README.md +129 -0
  4. data/Rakefile +87 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/clearance/confirmations_controller.rb +76 -0
  7. data/app/controllers/clearance/passwords_controller.rb +85 -0
  8. data/app/controllers/clearance/sessions_controller.rb +67 -0
  9. data/app/controllers/clearance/users_controller.rb +35 -0
  10. data/app/models/clearance_mailer.rb +21 -0
  11. data/app/views/clearance_mailer/change_password.html.erb +9 -0
  12. data/app/views/clearance_mailer/confirmation.html.erb +5 -0
  13. data/app/views/passwords/edit.html.erb +23 -0
  14. data/app/views/passwords/new.html.erb +15 -0
  15. data/app/views/sessions/new.html.erb +24 -0
  16. data/app/views/users/_form.html.erb +13 -0
  17. data/app/views/users/new.html.erb +6 -0
  18. data/generators/clearance/USAGE +1 -0
  19. data/generators/clearance/clearance_generator.rb +68 -0
  20. data/generators/clearance/lib/insert_commands.rb +33 -0
  21. data/generators/clearance/lib/rake_commands.rb +22 -0
  22. data/generators/clearance/templates/README +24 -0
  23. data/generators/clearance/templates/clearance.rb +3 -0
  24. data/generators/clearance/templates/factories.rb +13 -0
  25. data/generators/clearance/templates/migrations/create_users.rb +21 -0
  26. data/generators/clearance/templates/migrations/update_users.rb +41 -0
  27. data/generators/clearance/templates/user.rb +3 -0
  28. data/generators/clearance_features/USAGE +1 -0
  29. data/generators/clearance_features/clearance_features_generator.rb +19 -0
  30. data/generators/clearance_features/templates/features/password_reset.feature +33 -0
  31. data/generators/clearance_features/templates/features/sign_in.feature +35 -0
  32. data/generators/clearance_features/templates/features/sign_out.feature +15 -0
  33. data/generators/clearance_features/templates/features/sign_up.feature +45 -0
  34. data/generators/clearance_features/templates/features/step_definitions/clearance_steps.rb +122 -0
  35. data/generators/clearance_features/templates/features/support/paths.rb +23 -0
  36. data/generators/clearance_views/USAGE +0 -0
  37. data/generators/clearance_views/clearance_views_generator.rb +27 -0
  38. data/generators/clearance_views/templates/formtastic/passwords/edit.html.erb +21 -0
  39. data/generators/clearance_views/templates/formtastic/passwords/new.html.erb +15 -0
  40. data/generators/clearance_views/templates/formtastic/sessions/new.html.erb +21 -0
  41. data/generators/clearance_views/templates/formtastic/users/_inputs.html.erb +6 -0
  42. data/generators/clearance_views/templates/formtastic/users/new.html.erb +10 -0
  43. data/lib/clearance.rb +7 -0
  44. data/lib/clearance/authentication.rb +131 -0
  45. data/lib/clearance/configuration.rb +26 -0
  46. data/lib/clearance/extensions/errors.rb +6 -0
  47. data/lib/clearance/extensions/rescue.rb +5 -0
  48. data/lib/clearance/routes.rb +49 -0
  49. data/lib/clearance/user.rb +215 -0
  50. data/rails/init.rb +1 -0
  51. data/shoulda_macros/clearance.rb +266 -0
  52. data/test/controllers/confirmations_controller_test.rb +104 -0
  53. data/test/controllers/passwords_controller_test.rb +183 -0
  54. data/test/controllers/sessions_controller_test.rb +146 -0
  55. data/test/controllers/users_controller_test.rb +65 -0
  56. data/test/models/clearance_mailer_test.rb +55 -0
  57. data/test/models/user_test.rb +255 -0
  58. data/test/rails_root/app/controllers/accounts_controller.rb +10 -0
  59. data/test/rails_root/app/controllers/application_controller.rb +6 -0
  60. data/test/rails_root/app/helpers/application_helper.rb +5 -0
  61. data/test/rails_root/app/helpers/confirmations_helper.rb +2 -0
  62. data/test/rails_root/app/helpers/passwords_helper.rb +2 -0
  63. data/test/rails_root/app/models/user.rb +3 -0
  64. data/test/rails_root/config/boot.rb +110 -0
  65. data/test/rails_root/config/environment.rb +17 -0
  66. data/test/rails_root/config/environments/development.rb +19 -0
  67. data/test/rails_root/config/environments/production.rb +1 -0
  68. data/test/rails_root/config/environments/test.rb +36 -0
  69. data/test/rails_root/config/initializers/clearance.rb +3 -0
  70. data/test/rails_root/config/initializers/inflections.rb +10 -0
  71. data/test/rails_root/config/initializers/mime_types.rb +5 -0
  72. data/test/rails_root/config/initializers/requires.rb +13 -0
  73. data/test/rails_root/config/initializers/time_formats.rb +4 -0
  74. data/test/rails_root/config/routes.rb +6 -0
  75. data/test/rails_root/features/step_definitions/clearance_steps.rb +122 -0
  76. data/test/rails_root/features/step_definitions/web_steps.rb +259 -0
  77. data/test/rails_root/features/support/env.rb +47 -0
  78. data/test/rails_root/features/support/paths.rb +23 -0
  79. data/test/rails_root/public/dispatch.rb +10 -0
  80. data/test/rails_root/script/create_project.rb +52 -0
  81. data/test/rails_root/test/factories/clearance.rb +13 -0
  82. data/test/rails_root/test/functional/accounts_controller_test.rb +23 -0
  83. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +21 -0
  84. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/formtastic.rb +1236 -0
  85. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/justin_french/formtastic.rb +10 -0
  86. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/rails/init.rb +3 -0
  87. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/formtastic_spec.rb +2900 -0
  88. data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/test_helper.rb +14 -0
  89. data/test/test_helper.rb +19 -0
  90. metadata +160 -0
@@ -0,0 +1 @@
1
+ require 'clearance'
@@ -0,0 +1,266 @@
1
+ module Clearance
2
+ module Shoulda
3
+
4
+ # STATE OF AUTHENTICATION
5
+
6
+ def should_be_signed_in_as(&block)
7
+ warn "[DEPRECATION] should_be_signed_in_as cannot be used in functional tests anymore now that it depends on cookies, which are unavailable until the next request."
8
+ should "be signed in as #{block.bind(self).call}" do
9
+ user = block.bind(self).call
10
+ assert_not_nil user,
11
+ "please pass a User. try: should_be_signed_in_as { @user }"
12
+ assert_equal user, @controller.send(:current_user),
13
+ "#{user.inspect} is not the current_user, " <<
14
+ "which is #{@controller.send(:current_user).inspect}"
15
+ end
16
+ end
17
+
18
+ def should_be_signed_in_and_email_confirmed_as(&block)
19
+ warn "[DEPRECATION] should_be_signed_in_and_email_confirmed_as: questionable usefulness"
20
+ should_be_signed_in_as &block
21
+
22
+ should "have confirmed email" do
23
+ user = block.bind(self).call
24
+
25
+ assert_not_nil user
26
+ assert_equal user, assigns(:user)
27
+ assert assigns(:user).email_confirmed?
28
+ end
29
+ end
30
+
31
+ def should_not_be_signed_in
32
+ warn "[DEPRECATION] should_not_be_signed_in is no longer a valid test since we now store a remember_token in cookies, not user_id in session"
33
+ should "not be signed in" do
34
+ assert_nil session[:user_id]
35
+ end
36
+ end
37
+
38
+ def should_deny_access_on(http_method, action, opts = {})
39
+ warn "[DEPRECATION] should_deny_access_on: use a setup & should_deny_access(:flash => ?)"
40
+ flash_message = opts.delete(:flash)
41
+ context "on #{http_method} to #{action}" do
42
+ setup do
43
+ send(http_method, action, opts)
44
+ end
45
+
46
+ should_deny_access(:flash => flash_message)
47
+ end
48
+ end
49
+
50
+ def should_deny_access(opts = {})
51
+ if opts[:flash]
52
+ should_set_the_flash_to opts[:flash]
53
+ else
54
+ should_not_set_the_flash
55
+ end
56
+
57
+ should_redirect_to('sign in page') { sign_in_url }
58
+ end
59
+
60
+ # HTTP FLUENCY
61
+
62
+ def should_forbid(description, &block)
63
+ should "forbid #{description}" do
64
+ assert_raises ActionController::Forbidden do
65
+ instance_eval(&block)
66
+ end
67
+ end
68
+ end
69
+
70
+ # CONTEXTS
71
+
72
+ def signed_in_user_context(&blk)
73
+ warn "[DEPRECATION] signed_in_user_context: creates a Mystery Guest, causes Obscure Test"
74
+ context "A signed in user" do
75
+ setup do
76
+ @user = Factory(:user)
77
+ @user.confirm_email!
78
+ sign_in_as @user
79
+ end
80
+ merge_block(&blk)
81
+ end
82
+ end
83
+
84
+ def public_context(&blk)
85
+ warn "[DEPRECATION] public_context: common case is no-op. call sign_out otherwise"
86
+ context "The public" do
87
+ setup { sign_out }
88
+ merge_block(&blk)
89
+ end
90
+ end
91
+
92
+ # CREATING USERS
93
+
94
+ def should_create_user_successfully
95
+ warn "[DEPRECATION] should_create_user_successfully: not meant to be public, no longer used internally"
96
+ should_assign_to :user
97
+ should_change 'User.count', :by => 1
98
+
99
+ should "send the confirmation email" do
100
+ assert_sent_email do |email|
101
+ email.subject =~ /account confirmation/i
102
+ end
103
+ end
104
+
105
+ should_set_the_flash_to /confirm/i
106
+ should_redirect_to_url_after_create
107
+ end
108
+
109
+ # RENDERING
110
+
111
+ def should_render_nothing
112
+ should "render nothing" do
113
+ assert @response.body.blank?
114
+ end
115
+ end
116
+
117
+ # REDIRECTS
118
+
119
+ def should_redirect_to_url_after_create
120
+ should_redirect_to("the post-create url") do
121
+ @controller.send(:url_after_create)
122
+ end
123
+ end
124
+
125
+ def should_redirect_to_url_after_update
126
+ should_redirect_to("the post-update url") do
127
+ @controller.send(:url_after_update)
128
+ end
129
+ end
130
+
131
+ def should_redirect_to_url_after_destroy
132
+ should_redirect_to("the post-destroy url") do
133
+ @controller.send(:url_after_destroy)
134
+ end
135
+ end
136
+
137
+ def should_redirect_to_url_already_confirmed
138
+ should_redirect_to("the already confirmed url") do
139
+ @controller.send(:url_already_confirmed)
140
+ end
141
+ end
142
+
143
+ # VALIDATIONS
144
+
145
+ def should_validate_confirmation_of(attribute, opts = {})
146
+ warn "[DEPRECATION] should_validate_confirmation_of: not meant to be public, no longer used internally"
147
+ raise ArgumentError if opts[:factory].nil?
148
+
149
+ context "on save" do
150
+ should_validate_confirmation_is_not_blank opts[:factory], attribute
151
+ should_validate_confirmation_is_not_bad opts[:factory], attribute
152
+ end
153
+ end
154
+
155
+ def should_validate_confirmation_is_not_blank(factory, attribute, opts = {})
156
+ warn "[DEPRECATION] should_validate_confirmation_is_not_blank: not meant to be public, no longer used internally"
157
+ should "validate #{attribute}_confirmation is not blank" do
158
+ model = Factory.build(factory, blank_confirmation_options(attribute))
159
+ model.save
160
+ assert_confirmation_error(model, attribute,
161
+ "#{attribute}_confirmation cannot be blank")
162
+ end
163
+ end
164
+
165
+ def should_validate_confirmation_is_not_bad(factory, attribute, opts = {})
166
+ warn "[DEPRECATION] should_validate_confirmation_is_not_bad: not meant to be public, no longer used internally"
167
+ should "validate #{attribute}_confirmation is different than #{attribute}" do
168
+ model = Factory.build(factory, bad_confirmation_options(attribute))
169
+ model.save
170
+ assert_confirmation_error(model, attribute,
171
+ "#{attribute}_confirmation cannot be different than #{attribute}")
172
+ end
173
+ end
174
+
175
+ # FORMS
176
+
177
+ def should_display_a_password_update_form
178
+ warn "[DEPRECATION] should_display_a_password_update_form: not meant to be public, no longer used internally"
179
+ should "have a form for the user's token, password, and password confirm" do
180
+ update_path = ERB::Util.h(
181
+ user_password_path(@user, :token => @user.confirmation_token)
182
+ )
183
+
184
+ assert_select 'form[action=?]', update_path do
185
+ assert_select 'input[name=_method][value=?]', 'put'
186
+ assert_select 'input[name=?]', 'user[password]'
187
+ assert_select 'input[name=?]', 'user[password_confirmation]'
188
+ end
189
+ end
190
+ end
191
+
192
+ def should_display_a_sign_up_form
193
+ warn "[DEPRECATION] should_display_a_sign_up_form: not meant to be public, no longer used internally"
194
+ should "display a form to sign up" do
195
+ assert_select "form[action=#{users_path}][method=post]",
196
+ true, "There must be a form to sign up" do
197
+ assert_select "input[type=text][name=?]",
198
+ "user[email]", true, "There must be an email field"
199
+ assert_select "input[type=password][name=?]",
200
+ "user[password]", true, "There must be a password field"
201
+ assert_select "input[type=password][name=?]",
202
+ "user[password_confirmation]", true, "There must be a password confirmation field"
203
+ assert_select "input[type=submit]", true,
204
+ "There must be a submit button"
205
+ end
206
+ end
207
+ end
208
+
209
+ def should_display_a_sign_in_form
210
+ warn "[DEPRECATION] should_display_a_sign_in_form: not meant to be public, no longer used internally"
211
+ should 'display a "sign in" form' do
212
+ assert_select "form[action=#{session_path}][method=post]",
213
+ true, "There must be a form to sign in" do
214
+ assert_select "input[type=text][name=?]",
215
+ "session[email]", true, "There must be an email field"
216
+ assert_select "input[type=password][name=?]",
217
+ "session[password]", true, "There must be a password field"
218
+ assert_select "input[type=submit]", true,
219
+ "There must be a submit button"
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ module Clearance
227
+ module Shoulda
228
+ module Helpers
229
+ def sign_in_as(user)
230
+ @controller.current_user = user
231
+ return user
232
+ end
233
+
234
+ def sign_in
235
+ sign_in_as Factory(:email_confirmed_user)
236
+ end
237
+
238
+ def sign_out
239
+ @controller.current_user = nil
240
+ end
241
+
242
+ def blank_confirmation_options(attribute)
243
+ warn "[DEPRECATION] blank_confirmation_options: not meant to be public, no longer used internally"
244
+ opts = { attribute => attribute.to_s }
245
+ opts.merge("#{attribute}_confirmation".to_sym => "")
246
+ end
247
+
248
+ def bad_confirmation_options(attribute)
249
+ warn "[DEPRECATION] bad_confirmation_options: not meant to be public, no longer used internally"
250
+ opts = { attribute => attribute.to_s }
251
+ opts.merge("#{attribute}_confirmation".to_sym => "not_#{attribute}")
252
+ end
253
+
254
+ def assert_confirmation_error(model, attribute, message = "confirmation error")
255
+ warn "[DEPRECATION] assert_confirmation_error: not meant to be public, no longer used internally"
256
+ assert model.errors.on(attribute).include?("doesn't match confirmation"),
257
+ message
258
+ end
259
+ end
260
+ end
261
+ end
262
+
263
+ class Test::Unit::TestCase
264
+ include Clearance::Shoulda::Helpers
265
+ end
266
+ Test::Unit::TestCase.extend(Clearance::Shoulda)
@@ -0,0 +1,104 @@
1
+ require 'test_helper'
2
+
3
+ class ConfirmationsControllerTest < ActionController::TestCase
4
+
5
+ tests Clearance::ConfirmationsController
6
+
7
+ should_filter_params :token
8
+
9
+ context "a user whose email has not been confirmed" do
10
+ setup { @user = Factory(:user) }
11
+
12
+ should "have a token" do
13
+ assert_not_nil @user.confirmation_token
14
+ assert_not_equal "", @user.confirmation_token
15
+ end
16
+
17
+ context "on GET to #new with correct id and token" do
18
+ setup do
19
+ get :new, :user_id => @user.to_param,
20
+ :token => @user.confirmation_token
21
+ end
22
+
23
+ should_set_the_flash_to /confirmed email/i
24
+ should_set_the_flash_to /signed in/i
25
+ should_redirect_to_url_after_create
26
+
27
+ should "set the current user" do
28
+ assert_equal @user, @controller.current_user
29
+ end
30
+ end
31
+
32
+ context "with an incorrect token" do
33
+ setup do
34
+ @bad_token = "bad token"
35
+ assert_not_equal @bad_token, @user.confirmation_token
36
+ end
37
+
38
+ should_forbid "on GET to #new with incorrect token" do
39
+ get :new, :user_id => @user.to_param,
40
+ :token => @bad_token
41
+ end
42
+ end
43
+
44
+ should_forbid "on GET to #new with blank token" do
45
+ get :new, :user_id => @user.to_param, :token => ""
46
+ end
47
+
48
+ should_forbid "on GET to #new with no token" do
49
+ get :new, :user_id => @user.to_param
50
+ end
51
+ end
52
+
53
+ context "a signed in confirmed user on GET to #new with token" do
54
+ setup do
55
+ @user = Factory(:user)
56
+ @token = @user.confirmation_token
57
+ @user.confirm_email!
58
+ sign_in_as @user
59
+
60
+ get :new, :user_id => @user.to_param, :token => @token
61
+ end
62
+
63
+ should_set_the_flash_to /confirmed email/i
64
+ should_redirect_to_url_after_create
65
+ end
66
+
67
+ context "a bad user" do
68
+ setup do
69
+ @user = Factory(:user)
70
+ @token = @user.confirmation_token
71
+ @user.confirm_email!
72
+
73
+ @bad_user = Factory(:email_confirmed_user)
74
+ sign_in_as @bad_user
75
+ end
76
+
77
+ should_forbid "on GET to #new with token for another user" do
78
+ get :new, :user_id => @user.to_param, :token => @token
79
+ end
80
+ end
81
+
82
+ context "a signed out confirmed user on GET to #new with token" do
83
+ setup do
84
+ @user = Factory(:user)
85
+ @token = @user.confirmation_token
86
+ @user.confirm_email!
87
+ get :new, :user_id => @user.to_param, :token => @token
88
+ end
89
+
90
+ should_set_the_flash_to /already confirmed/i
91
+ should_set_the_flash_to /sign in/i
92
+ should_not_be_signed_in
93
+ should_redirect_to_url_already_confirmed
94
+ end
95
+
96
+ context "no users" do
97
+ setup { assert_equal 0, ::User.count }
98
+
99
+ should_forbid "on GET to #new with nonexistent id and token" do
100
+ get :new, :user_id => '123', :token => '123'
101
+ end
102
+ end
103
+
104
+ end
@@ -0,0 +1,183 @@
1
+ require 'test_helper'
2
+
3
+ class PasswordsControllerTest < ActionController::TestCase
4
+
5
+ tests Clearance::PasswordsController
6
+
7
+ should_route :get, '/users/1/password/edit',
8
+ :controller => 'clearance/passwords', :action => 'edit', :user_id => '1'
9
+
10
+ context "a signed up user" do
11
+ setup do
12
+ @user = Factory(:user)
13
+ end
14
+
15
+ context "on GET to #new" do
16
+ setup { get :new, :user_id => @user.to_param }
17
+
18
+ should_respond_with :success
19
+ should_render_template "new"
20
+ end
21
+
22
+ context "on POST to #create" do
23
+ context "with correct email address" do
24
+ setup do
25
+ ActionMailer::Base.deliveries.clear
26
+ post :create, :password => { :email => @user.email }
27
+ end
28
+
29
+ should "generate a token for the change your password email" do
30
+ assert_not_nil @user.reload.confirmation_token
31
+ end
32
+
33
+ should "send the change your password email" do
34
+ assert_sent_email do |email|
35
+ email.subject =~ /change your password/i
36
+ end
37
+ end
38
+
39
+ should_set_the_flash_to /password/i
40
+ should_redirect_to_url_after_create
41
+ end
42
+
43
+ context "with incorrect email address" do
44
+ setup do
45
+ email = "user1@example.com"
46
+ assert ! ::User.exists?(['email = ?', email])
47
+ ActionMailer::Base.deliveries.clear
48
+ assert_equal @user.confirmation_token,
49
+ @user.reload.confirmation_token
50
+
51
+ post :create, :password => { :email => email }
52
+ end
53
+
54
+ should "not generate a token for the change your password email" do
55
+ assert_equal @user.confirmation_token,
56
+ @user.reload.confirmation_token
57
+ end
58
+
59
+ should "not send a password reminder email" do
60
+ assert ActionMailer::Base.deliveries.empty?
61
+ end
62
+
63
+ should "set the failure flash to Unknown email" do
64
+ assert_match /unknown email/i, flash.now[:failure]
65
+ end
66
+
67
+ should_render_template :new
68
+ end
69
+ end
70
+ end
71
+
72
+ context "a signed up user and forgotten password" do
73
+ setup do
74
+ @user = Factory(:user)
75
+ @user.forgot_password!
76
+ end
77
+
78
+ context "on GET to #edit with correct id and token" do
79
+ setup do
80
+ get :edit, :user_id => @user.to_param,
81
+ :token => @user.confirmation_token
82
+ end
83
+
84
+ should "find the user" do
85
+ assert_equal @user, assigns(:user)
86
+ end
87
+
88
+ should_respond_with :success
89
+ should_render_template "edit"
90
+ should_display_a_password_update_form
91
+ end
92
+
93
+ should_forbid "on GET to #edit with correct id but blank token" do
94
+ get :edit, :user_id => @user.to_param, :token => ""
95
+ end
96
+
97
+ should_forbid "on GET to #edit with correct id but no token" do
98
+ get :edit, :user_id => @user.to_param
99
+ end
100
+
101
+ context "on PUT to #update with matching password and password confirmation" do
102
+ setup do
103
+ new_password = "new_password"
104
+ @encrypted_new_password = @user.send(:encrypt, new_password)
105
+ assert_not_equal @encrypted_new_password, @user.encrypted_password
106
+
107
+ put(:update,
108
+ :user_id => @user,
109
+ :token => @user.confirmation_token,
110
+ :user => {
111
+ :password => new_password,
112
+ :password_confirmation => new_password
113
+ })
114
+ @user.reload
115
+ end
116
+
117
+ should "update password" do
118
+ assert_equal @encrypted_new_password,
119
+ @user.encrypted_password
120
+ end
121
+
122
+ should "clear confirmation token" do
123
+ assert_nil @user.confirmation_token
124
+ end
125
+
126
+ should "set remember token" do
127
+ assert_not_nil @user.remember_token
128
+ end
129
+
130
+ should_set_the_flash_to(/signed in/i)
131
+ should_redirect_to_url_after_update
132
+ end
133
+
134
+ context "on PUT to #update with password but blank password confirmation" do
135
+ setup do
136
+ new_password = "new_password"
137
+ @encrypted_new_password = @user.send(:encrypt, new_password)
138
+
139
+ put(:update,
140
+ :user_id => @user.to_param,
141
+ :token => @user.confirmation_token,
142
+ :user => {
143
+ :password => new_password,
144
+ :password_confirmation => ''
145
+ })
146
+ @user.reload
147
+ end
148
+
149
+ should "not update password" do
150
+ assert_not_equal @encrypted_new_password,
151
+ @user.encrypted_password
152
+ end
153
+
154
+ should "not clear token" do
155
+ assert_not_nil @user.confirmation_token
156
+ end
157
+
158
+ should_not_be_signed_in
159
+ should_not_set_the_flash
160
+ should_respond_with :success
161
+ should_render_template :edit
162
+
163
+ should_display_a_password_update_form
164
+ end
165
+
166
+ should_forbid "on PUT to #update with id but no token" do
167
+ put :update, :user_id => @user.to_param, :token => ""
168
+ end
169
+ end
170
+
171
+ context "given two users and user one signs in" do
172
+ setup do
173
+ @user_one = Factory(:user)
174
+ @user_two = Factory(:user)
175
+ sign_in_as @user_one
176
+ end
177
+
178
+ should_forbid "when user one tries to change user two's password on GET with no token" do
179
+ get :edit, :user_id => @user_two.to_param
180
+ end
181
+ end
182
+
183
+ end