rules_engine_users 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rules_engine/controller_users.rb +3 -3
- data/rails_generators/manifests/rules_engine_users.rb +15 -3
- data/rails_generators/manifests/rules_engine_users.yml +4 -3
- data/rails_generators/templates/app/controllers/admin/users_controller.rb +2 -0
- data/rails_generators/templates/app/controllers/users_controller.rb +81 -5
- data/rails_generators/templates/app/models/user_mailer.rb +1 -1
- data/rails_generators/templates/app/models/user_observer.rb +1 -0
- data/rails_generators/templates/app/views/users/_login_form.html.erb +24 -0
- data/rails_generators/templates/app/views/users/_pswd_forgot_form.html.erb +22 -0
- data/rails_generators/templates/app/views/users/_signup_form.html.erb +26 -0
- data/rails_generators/templates/app/views/users/change_form.html.erb +5 -9
- data/rails_generators/templates/app/views/users/details.html.erb +1 -0
- data/rails_generators/templates/app/views/users/login_form.html.erb +8 -22
- data/rails_generators/templates/app/views/users/login_form.js.erb +37 -0
- data/rails_generators/templates/app/views/users/pswd_change_form.html.erb +5 -8
- data/rails_generators/templates/app/views/users/pswd_forgot_form.html.erb +13 -18
- data/rails_generators/templates/app/views/users/pswd_forgot_form.js.erb +29 -0
- data/rails_generators/templates/app/views/users/pswd_reset_form.html.erb +3 -8
- data/rails_generators/templates/app/views/users/signup_form.html.erb +13 -0
- data/rails_generators/templates/app/views/users/signup_form.js.erb +29 -0
- data/rails_generators/templates/app/views/users/welcome_form.html.erb +3 -7
- data/rails_generators/templates/config/initializers/rules_engine_users.rb +4 -0
- data/rails_generators/templates/db/migrate/20100104014507_create_users.rb +1 -1
- data/rails_generators/templates/doc/README.rules_engine_users +83 -76
- data/rails_generators/templates/spec/controllers/users_controller_spec.rb +312 -183
- data/rails_generators/templates/spec/models/user_mailer_spec.rb +1 -1
- data/rails_generators/templates/{features/support/blueprint_users.rb → spec/support/rules_engine_users_blueprints.rb} +0 -0
- data/rails_generators/templates/spec/support/rules_engine_users_macros.rb +16 -0
- data/spec/rules_engine/controller_users_spec.rb +3 -3
- metadata +17 -13
- data/.document +0 -5
- data/.gitignore +0 -22
- data/Rakefile +0 -47
- data/rails_generators/templates/spec/support/rules_engine_macros.rb +0 -16
- data/rules_engine_users.gemspec +0 -141
@@ -1,16 +1,22 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe UsersController do
|
4
|
-
|
4
|
+
integrate_views
|
5
|
+
|
5
6
|
before(:each) do
|
6
7
|
controller.instance_eval { flash.stub!(:sweep) }
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
+
describe "GET login_form" do
|
10
11
|
it "should render the 'login_form' template" do
|
11
12
|
get :login_form
|
12
13
|
response.should render_template(:login_form)
|
13
14
|
end
|
15
|
+
|
16
|
+
it "should render 'login_form' template for JAVASCRIPT" do
|
17
|
+
xhr :get, :login_form
|
18
|
+
response.should render_template(:login_form)
|
19
|
+
end
|
14
20
|
|
15
21
|
describe "already logged in" do
|
16
22
|
before(:each) do
|
@@ -26,13 +32,18 @@ describe UsersController do
|
|
26
32
|
get :login_form
|
27
33
|
response.should redirect_to(root_path)
|
28
34
|
end
|
35
|
+
|
36
|
+
it "should redirect to the root_path JAVASCRIPT" do
|
37
|
+
xhr :get, :login_form
|
38
|
+
response.body.should == "window.location.href = '#{root_path}';"
|
39
|
+
end
|
29
40
|
end
|
30
41
|
end
|
31
|
-
|
42
|
+
|
32
43
|
describe "POST login" do
|
33
44
|
before do
|
34
45
|
# User.stub!(:new).and_return @user = mock_model(User)
|
35
|
-
@user =
|
46
|
+
@user = User.make(:access_level => User::ACCESS_LEVEL_ADMIN )
|
36
47
|
User.stub!(:authenticate_by_email).and_return(@user)
|
37
48
|
@user.stub(:remember_token).and_return('mock_remember_token')
|
38
49
|
@user.stub(:remember_token_expires_at).and_return(Time.now)
|
@@ -63,6 +74,17 @@ describe UsersController do
|
|
63
74
|
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
64
75
|
response.should redirect_to('/mock_return_to')
|
65
76
|
end
|
77
|
+
|
78
|
+
it "should redirect to the root_path JAVASCRIPT" do
|
79
|
+
xhr :post, :login, :user => { :name => "mock_email", :password => "mock_password"}
|
80
|
+
response.body.should == "window.location.href = '#{root_path}';"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should redirect to the session[:return_to] path ror JAVASCRIPT" do
|
84
|
+
controller.stub(:session).and_return(:return_to => '/mock_return_to')
|
85
|
+
xhr :post, :login, :user => { :name => "mock_email", :password => "mock_password"}
|
86
|
+
response.body.should == "window.location.href = '/mock_return_to';"
|
87
|
+
end
|
66
88
|
|
67
89
|
describe ":remember me set" do
|
68
90
|
it "should set the remember me token" do
|
@@ -85,17 +107,24 @@ describe UsersController do
|
|
85
107
|
describe "authentication failed" do
|
86
108
|
before(:each) do
|
87
109
|
User.stub!(:authenticate_by_email).and_return(nil)
|
110
|
+
User.stub!(:authenticate_by_login).and_return(nil)
|
88
111
|
end
|
89
112
|
|
90
113
|
it "should set an error message" do
|
91
114
|
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
92
|
-
flash.now[:error].should_not be_blank
|
115
|
+
# flash.now[:error].should_not be_blank
|
116
|
+
response.should have_tag("div.error")
|
93
117
|
end
|
94
118
|
|
95
119
|
it "should render the login form" do
|
96
120
|
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
97
121
|
response.should render_template(:login_form)
|
98
122
|
end
|
123
|
+
|
124
|
+
it "should render the login form JAVASCRIPT" do
|
125
|
+
xhr :post, :login, :user => { :name => "mock_email", :password => "mock_password"}
|
126
|
+
response.should render_template(:login_form)
|
127
|
+
end
|
99
128
|
end
|
100
129
|
|
101
130
|
describe "user account has been disabled" do
|
@@ -106,121 +135,158 @@ describe UsersController do
|
|
106
135
|
|
107
136
|
it "should set an error message" do
|
108
137
|
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
109
|
-
flash
|
138
|
+
flash[:error].should_not be_blank
|
110
139
|
end
|
111
140
|
|
112
141
|
it "should redirect to the root_path" do
|
113
142
|
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
114
143
|
response.should redirect_to(root_path)
|
115
144
|
end
|
145
|
+
|
146
|
+
it "should redirect to the root_path JAVASCRIPT" do
|
147
|
+
xhr :post, :login, :user => { :name => "mock_email", :password => "mock_password"}
|
148
|
+
response.body.should == "window.location.href = '#{root_path}';"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "GET signup_form" do
|
154
|
+
it "should render the 'signup_form' template" do
|
155
|
+
get :signup_form
|
156
|
+
response.should render_template(:signup_form)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should render 'signup_form' template for JAVASCRIPT" do
|
160
|
+
xhr :get, :signup_form
|
161
|
+
response.should render_template(:signup_form)
|
116
162
|
end
|
117
163
|
|
118
|
-
|
164
|
+
describe "already logged in" do
|
165
|
+
before(:each) do
|
166
|
+
controller.stub!(:logged_in?).and_return(true)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should set a success message if already lodded in" do
|
170
|
+
get :signup_form
|
171
|
+
flash[:success].should_not be_blank
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should redirect to the root_path" do
|
175
|
+
get :signup_form
|
176
|
+
response.should redirect_to(root_path)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should redirect to the root_path JAVASCRIPT" do
|
180
|
+
xhr :get, :signup_form
|
181
|
+
response.body.should == "window.location.href = '#{root_path}';"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "GET logout" do
|
187
|
+
describe "the user is logged in" do
|
188
|
+
it "should reset the current users remember me token" do
|
189
|
+
user = mock_model(User)
|
190
|
+
controller.stub!(:current_user).and_return(user)
|
191
|
+
controller.stub!(:logged_in?).and_return(true)
|
119
192
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
user.should_receive(:reset_remember_token)
|
128
|
-
get :logout
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should delete the auth_token cookie" do
|
193
|
+
user.should_receive(:reset_remember_token)
|
194
|
+
get :logout
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should delete the auth_token cookie" do
|
133
199
|
cookies = {:auth_token => 'mock_token'}
|
134
200
|
controller.stub!(:cookies).and_return(cookies)
|
135
201
|
get :logout
|
136
202
|
cookies[:auth_token].should be_blank
|
137
|
-
|
138
|
-
|
139
|
-
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should reset the session variables" do
|
140
206
|
controller.should_receive(:reset_session)
|
141
207
|
get :logout
|
142
|
-
|
143
|
-
|
144
|
-
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should redirec to the root page" do
|
145
211
|
get :logout
|
146
|
-
response.should redirect_to(
|
147
|
-
|
212
|
+
response.should redirect_to(root_path)
|
213
|
+
end
|
148
214
|
end
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
215
|
+
|
216
|
+
describe "GET details" do
|
217
|
+
before(:each) do
|
218
|
+
controller.stub!(:login_required)
|
219
|
+
@user = User.make
|
220
|
+
controller.stub!(:current_user).and_return(@user)
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should require the user to be logged_in" do
|
224
|
+
controller.should_receive(:login_required)
|
225
|
+
get :details
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should set the user to the current user" do
|
229
|
+
get :details
|
230
|
+
assigns[:user].should == @user
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should render the details template" do
|
168
234
|
get :details
|
169
235
|
response.should render_template(:details)
|
170
|
-
|
236
|
+
end
|
171
237
|
end
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
238
|
+
|
239
|
+
describe "GET change_form" do
|
240
|
+
before(:each) do
|
241
|
+
controller.stub!(:login_required)
|
242
|
+
@user = User.make
|
243
|
+
controller.stub!(:current_user).and_return(@user)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should require the user to be logged_in" do
|
247
|
+
controller.should_receive(:login_required)
|
248
|
+
get :change_form
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should set the user to the current user" do
|
252
|
+
get :change_form
|
253
|
+
assigns[:user].should == @user
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should render the user_change_form template" do
|
191
257
|
get :change_form
|
192
258
|
response.should render_template(:change_form)
|
193
|
-
|
259
|
+
end
|
194
260
|
end
|
195
|
-
|
261
|
+
|
196
262
|
describe "POST change" do
|
197
263
|
before do
|
198
|
-
|
199
|
-
@user =
|
264
|
+
controller.stub!(:login_required)
|
265
|
+
@user = User.make
|
200
266
|
@user.stub!(:update_attributes).and_return(true)
|
201
267
|
controller.stub!(:current_user).and_return(@user)
|
202
268
|
end
|
203
269
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
it "should not change the access level" do
|
210
|
-
@user.should_receive(:update_attributes).with({})
|
211
|
-
post :change, :user => {:access_level => 202}
|
212
|
-
end
|
213
|
-
|
214
|
-
it "should not change the password" do
|
215
|
-
@user.should_receive(:update_attributes).with({})
|
216
|
-
post :change, :user => {:password => 'new'}
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should update the user fields" do
|
220
|
-
@user.should_receive(:update_attributes).with("field_name" => 'field_value')
|
221
|
-
post :change, :user => {:field_name => 'field_value'}
|
222
|
-
end
|
270
|
+
it "should require the user to be logged_in" do
|
271
|
+
controller.should_receive(:login_required)
|
272
|
+
post :change, :user => {}
|
273
|
+
end
|
223
274
|
|
275
|
+
it "should not change the access level" do
|
276
|
+
@user.should_receive(:update_attributes).with({})
|
277
|
+
post :change, :user => {:access_level => 202}
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should not change the password" do
|
281
|
+
@user.should_receive(:update_attributes).with({})
|
282
|
+
post :change, :user => {:password => 'new'}
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should update the user fields" do
|
286
|
+
@user.should_receive(:update_attributes).with("field_name" => 'field_value')
|
287
|
+
post :change, :user => {:field_name => 'field_value'}
|
288
|
+
end
|
289
|
+
|
224
290
|
describe "update failed" do
|
225
291
|
before do
|
226
292
|
@user.stub!(:update_attributes).and_return(false)
|
@@ -244,36 +310,34 @@ describe UsersController do
|
|
244
310
|
end
|
245
311
|
end
|
246
312
|
end
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
it "should render the pswd_change_form template" do
|
313
|
+
|
314
|
+
describe "GET pswd_change_form" do
|
315
|
+
before(:each) do
|
316
|
+
controller.stub!(:login_required)
|
317
|
+
@user = User.make
|
318
|
+
controller.stub!(:current_user).and_return(@user)
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should require the user to be logged_in" do
|
322
|
+
controller.should_receive(:login_required)
|
323
|
+
get :pswd_change_form
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should set the user to the current user" do
|
327
|
+
get :pswd_change_form
|
328
|
+
assigns[:user].should == @user
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should render the pswd_change_form template" do
|
267
332
|
get :pswd_change_form
|
268
333
|
response.should render_template(:pswd_change_form)
|
269
|
-
|
334
|
+
end
|
270
335
|
end
|
271
|
-
|
272
|
-
|
336
|
+
|
273
337
|
describe "POST pswd_change" do
|
274
338
|
before do
|
275
|
-
|
276
|
-
@user =
|
339
|
+
controller.stub!(:login_required)
|
340
|
+
@user = User.make(:email => 'mock_email')
|
277
341
|
@user.stub!(:update_attributes).and_return(true)
|
278
342
|
controller.stub!(:current_user).and_return(@user)
|
279
343
|
|
@@ -282,50 +346,55 @@ describe UsersController do
|
|
282
346
|
@valid_params = {:old_password => 'old password', :password => 'new password', :password_confirmation => 'new password'}
|
283
347
|
end
|
284
348
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
349
|
+
it "should require the user to be logged_in" do
|
350
|
+
controller.should_receive(:login_required)
|
351
|
+
post :pswd_change, :user => @valid_params
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should require the old_password" do
|
355
|
+
post :pswd_change, :user => @valid_params.except(:old_password)
|
356
|
+
# flash.now[:error].should_not be_blank
|
357
|
+
response.should have_tag("div.error")
|
358
|
+
response.should render_template(:pswd_change_form)
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should require the password" do
|
362
|
+
post :pswd_change, :user => @valid_params.except(:password)
|
363
|
+
# flash.now[:error].should_not be_blank
|
364
|
+
response.should have_tag("div.error")
|
365
|
+
response.should render_template(:pswd_change_form)
|
366
|
+
end
|
367
|
+
|
368
|
+
it "should require the password confirmation" do
|
369
|
+
post :pswd_change, :user => @valid_params.except(:password_confirmation)
|
370
|
+
# flash.now[:error].should_not be_blank
|
371
|
+
response.should have_tag("div.error")
|
372
|
+
response.should render_template(:pswd_change_form)
|
373
|
+
end
|
307
374
|
|
308
375
|
it "should confirm the user's old password is correct" do
|
309
376
|
User.should_receive(:authenticate_by_email).with("mock_email", "old password")
|
310
377
|
post :pswd_change, :user => @valid_params
|
311
378
|
end
|
312
379
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
380
|
+
it "should require the old password to be correct" do
|
381
|
+
User.stub!(:authenticate_by_email).and_return(false)
|
382
|
+
post :pswd_change, :user => @valid_params
|
383
|
+
# flash.now[:error].should_not be_blank
|
384
|
+
response.should have_tag("div.error")
|
385
|
+
response.should render_template(:pswd_change_form)
|
386
|
+
end
|
319
387
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
388
|
+
it "should update the password fields only" do
|
389
|
+
@user.should_receive(:update_attributes).with(:password => "new password", :password_confirmation => "new password")
|
390
|
+
post :pswd_change, :user => @valid_params
|
391
|
+
end
|
324
392
|
|
325
393
|
it "should confirm the update of the password" do
|
326
394
|
@user.should_receive(:update_attributes).and_return(false)
|
327
395
|
post :pswd_change, :user => @valid_params
|
328
|
-
flash.now[:error].should_not be_blank
|
396
|
+
# flash.now[:error].should_not be_blank
|
397
|
+
response.should have_tag("div.error")
|
329
398
|
response.should render_template(:pswd_change_form)
|
330
399
|
end
|
331
400
|
|
@@ -336,40 +405,88 @@ describe UsersController do
|
|
336
405
|
response.should redirect_to(user_details_path)
|
337
406
|
end
|
338
407
|
end
|
339
|
-
|
340
408
|
|
341
|
-
|
342
|
-
|
409
|
+
|
410
|
+
describe "GET pswd_forgot_form" do
|
411
|
+
it "should render the pswd_forgot_form template" do
|
343
412
|
get :pswd_forgot_form
|
344
413
|
response.should render_template(:pswd_forgot_form)
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
post :pswd_forgot, :user => {:email => "mock_email"}
|
352
|
-
end
|
414
|
+
end
|
415
|
+
|
416
|
+
it "should render 'pswd_forgot_form' template for JAVASCRIPT" do
|
417
|
+
xhr :get, :pswd_forgot_form
|
418
|
+
response.should render_template(:pswd_forgot_form)
|
419
|
+
end
|
353
420
|
|
421
|
+
describe "already logged in" do
|
422
|
+
before(:each) do
|
423
|
+
controller.stub!(:logged_in?).and_return(true)
|
424
|
+
end
|
425
|
+
|
426
|
+
it "should set a success message if already lodded in" do
|
427
|
+
get :pswd_forgot_form
|
428
|
+
flash[:success].should_not be_blank
|
429
|
+
end
|
430
|
+
|
431
|
+
it "should redirect to the root_path" do
|
432
|
+
get :pswd_forgot_form
|
433
|
+
response.should redirect_to(root_path)
|
434
|
+
end
|
435
|
+
|
436
|
+
it "should redirect to the root_path JAVASCRIPT" do
|
437
|
+
xhr :get, :pswd_forgot_form
|
438
|
+
response.body.should == "window.location.href = '#{root_path}';"
|
439
|
+
end
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
|
444
|
+
describe "POST pswd_forgot" do
|
445
|
+
it "should set the reset token" do
|
446
|
+
User.should_receive(:set_reset_token).with('mock_email')
|
447
|
+
post :pswd_forgot, :user => {:email => "mock_email"}
|
448
|
+
end
|
449
|
+
|
354
450
|
describe "reset token set" do
|
355
|
-
|
451
|
+
before(:each) do
|
356
452
|
User.stub!(:set_reset_token).and_return(true)
|
453
|
+
end
|
454
|
+
|
455
|
+
it "should set a success message" do
|
357
456
|
post :pswd_forgot, :user => {:email => "mock_email"}
|
358
457
|
flash[:success].should_not be_blank
|
458
|
+
end
|
459
|
+
|
460
|
+
it "should redirect to the user login page" do
|
461
|
+
post :pswd_forgot, :user => {:email => "mock_email"}
|
359
462
|
response.should redirect_to(user_login_path)
|
360
463
|
end
|
464
|
+
|
465
|
+
it "should redirect to the user login for JAVASCRIPT" do
|
466
|
+
xhr :post, :pswd_forgot, :user => {:email => "mock_email"}
|
467
|
+
response.body.should == "window.location.href = '#{user_login_path}';"
|
468
|
+
end
|
361
469
|
end
|
362
470
|
|
363
471
|
describe "reset token not set" do
|
364
|
-
|
472
|
+
before(:each) do
|
365
473
|
User.stub!(:set_reset_token).and_return(false)
|
474
|
+
end
|
475
|
+
|
476
|
+
it "should render the pswd_forgot_form" do
|
366
477
|
post :pswd_forgot, :user => {:email => "mock_email"}
|
367
|
-
flash.now[:error].should_not be_blank
|
478
|
+
# flash.now[:error].should_not be_blank
|
479
|
+
response.should have_tag("div.error")
|
368
480
|
response.should render_template(:pswd_forgot_form)
|
369
481
|
end
|
482
|
+
|
483
|
+
it "should render the pswd_forgot_form for JAVASCRIPT" do
|
484
|
+
xhr :post, :pswd_forgot, :user => {:email => "mock_email"}
|
485
|
+
response.should render_template(:pswd_forgot_form)
|
486
|
+
end
|
370
487
|
end
|
371
488
|
end
|
372
|
-
|
489
|
+
|
373
490
|
describe "GET pswd_reset_form" do
|
374
491
|
it "should require a reset token" do
|
375
492
|
get :pswd_reset_form
|
@@ -400,10 +517,10 @@ describe UsersController do
|
|
400
517
|
response.should render_template(:pswd_reset_form)
|
401
518
|
end
|
402
519
|
end
|
403
|
-
|
520
|
+
|
404
521
|
describe "POST pswd_reset" do
|
405
522
|
before do
|
406
|
-
@user =
|
523
|
+
@user = User.make(:email => 'mock_email')
|
407
524
|
@user.stub!(:update_attributes).and_return(true)
|
408
525
|
User.stub!(:authenticate_by_reset_token).and_return(@user)
|
409
526
|
@valid_params = {:email => 'mock_email', :password => 'new password', :password_confirmation => 'new password'}
|
@@ -417,19 +534,22 @@ describe UsersController do
|
|
417
534
|
|
418
535
|
it "should require an email address" do
|
419
536
|
post :pswd_reset, :token => 'mock_token', :user => @valid_params.except(:email)
|
420
|
-
flash.now[:error].should_not be_blank
|
537
|
+
# flash.now[:error].should_not be_blank
|
538
|
+
response.should have_tag("div.error")
|
421
539
|
response.should render_template(:pswd_reset_form)
|
422
540
|
end
|
423
541
|
|
424
542
|
it "should require a password" do
|
425
543
|
post :pswd_reset, :token => 'mock_token', :user => @valid_params.except(:password)
|
426
|
-
flash.now[:error].should_not be_blank
|
544
|
+
# flash.now[:error].should_not be_blank
|
545
|
+
response.should have_tag("div.error")
|
427
546
|
response.should render_template(:pswd_reset_form)
|
428
547
|
end
|
429
548
|
|
430
549
|
it "should require a password to match the password confirmation" do
|
431
550
|
post :pswd_reset, :token => 'mock_token', :user => @valid_params.merge(:password_confirmation => 'wrong')
|
432
|
-
flash.now[:error].should_not be_blank
|
551
|
+
# flash.now[:error].should_not be_blank
|
552
|
+
response.should have_tag("div.error")
|
433
553
|
response.should render_template(:pswd_reset_form)
|
434
554
|
end
|
435
555
|
|
@@ -441,14 +561,16 @@ describe UsersController do
|
|
441
561
|
it "should require the reset token to be authenticated" do
|
442
562
|
User.stub!(:authenticate_by_reset_token).and_return(false)
|
443
563
|
post :pswd_reset, :token => 'mock_token', :user => @valid_params
|
444
|
-
flash.now[:error].should_not be_blank
|
564
|
+
# flash.now[:error].should_not be_blank
|
565
|
+
response.should have_tag("div.error")
|
445
566
|
response.should render_template(:pswd_reset_form)
|
446
567
|
end
|
447
568
|
|
448
569
|
it "should require the authenticated user to have the same email address" do
|
449
570
|
@user.stub!(:email).and_return('wrong')
|
450
571
|
post :pswd_reset, :token => 'mock_token', :user => @valid_params
|
451
|
-
flash.now[:error].should_not be_blank
|
572
|
+
# flash.now[:error].should_not be_blank
|
573
|
+
response.should have_tag("div.error")
|
452
574
|
response.should render_template(:pswd_reset_form)
|
453
575
|
end
|
454
576
|
|
@@ -460,7 +582,8 @@ describe UsersController do
|
|
460
582
|
it "should require the password update to be successfull" do
|
461
583
|
@user.stub!(:update_attributes).and_return(false)
|
462
584
|
post :pswd_reset, :token => 'mock_token', :user => @valid_params
|
463
|
-
flash.now[:error].should_not be_blank
|
585
|
+
# flash.now[:error].should_not be_blank
|
586
|
+
response.should have_tag("div.error")
|
464
587
|
response.should render_template(:pswd_reset_form)
|
465
588
|
end
|
466
589
|
|
@@ -475,7 +598,7 @@ describe UsersController do
|
|
475
598
|
response.should redirect_to(root_path)
|
476
599
|
end
|
477
600
|
end
|
478
|
-
|
601
|
+
|
479
602
|
describe "GET welcome_form" do
|
480
603
|
it "should require a reset token" do
|
481
604
|
get :welcome_form
|
@@ -500,10 +623,10 @@ describe UsersController do
|
|
500
623
|
response.should render_template(:welcome_form)
|
501
624
|
end
|
502
625
|
end
|
503
|
-
|
626
|
+
|
504
627
|
describe "POST welcome" do
|
505
628
|
before do
|
506
|
-
@user =
|
629
|
+
@user = User.make(:email => 'mock_email')
|
507
630
|
@user.stub!(:update_attributes).and_return(true)
|
508
631
|
User.stub!(:authenticate_by_reset_token).and_return(@user)
|
509
632
|
@valid_params = {:email => 'mock_email', :password => 'new password', :password_confirmation => 'new password'}
|
@@ -511,25 +634,29 @@ describe UsersController do
|
|
511
634
|
|
512
635
|
it "should require a reset token" do
|
513
636
|
post :welcome, :user => @valid_params
|
514
|
-
flash.now[:error].should_not be_blank
|
637
|
+
# flash.now[:error].should_not be_blank
|
638
|
+
response.should have_tag("div.error")
|
515
639
|
response.should render_template(:pswd_forgot_form)
|
516
640
|
end
|
517
641
|
|
518
642
|
it "should require an email address" do
|
519
643
|
post :welcome, :token => 'mock_token', :user => @valid_params.except(:email)
|
520
|
-
flash.now[:error].should_not be_blank
|
644
|
+
# flash.now[:error].should_not be_blank
|
645
|
+
response.should have_tag("div.error")
|
521
646
|
response.should render_template(:welcome_form)
|
522
647
|
end
|
523
648
|
|
524
649
|
it "should require a password" do
|
525
650
|
post :welcome, :token => 'mock_token', :user => @valid_params.except(:password)
|
526
|
-
flash.now[:error].should_not be_blank
|
651
|
+
# flash.now[:error].should_not be_blank
|
652
|
+
response.should have_tag("div.error")
|
527
653
|
response.should render_template(:welcome_form)
|
528
654
|
end
|
529
655
|
|
530
656
|
it "should require a password to match the password confirmation" do
|
531
657
|
post :welcome, :token => 'mock_token', :user => @valid_params.merge(:password_confirmation => 'wrong')
|
532
|
-
flash.now[:error].should_not be_blank
|
658
|
+
# flash.now[:error].should_not be_blank
|
659
|
+
response.should have_tag("div.error")
|
533
660
|
response.should render_template(:welcome_form)
|
534
661
|
end
|
535
662
|
|
@@ -541,14 +668,16 @@ describe UsersController do
|
|
541
668
|
it "should require the reset token to be authenticated" do
|
542
669
|
User.stub!(:authenticate_by_reset_token).and_return(false)
|
543
670
|
post :welcome, :token => 'mock_token', :user => @valid_params
|
544
|
-
flash.now[:error].should_not be_blank
|
671
|
+
# flash.now[:error].should_not be_blank
|
672
|
+
response.should have_tag("div.error")
|
545
673
|
response.should render_template(:welcome_form)
|
546
674
|
end
|
547
675
|
|
548
676
|
it "should require the authenticated user to have the same email address" do
|
549
677
|
@user.stub!(:email).and_return('wrong')
|
550
678
|
post :welcome, :token => 'mock_token', :user => @valid_params
|
551
|
-
flash.now[:error].should_not be_blank
|
679
|
+
# flash.now[:error].should_not be_blank
|
680
|
+
response.should have_tag("div.error")
|
552
681
|
response.should render_template(:welcome_form)
|
553
682
|
end
|
554
683
|
|
@@ -560,7 +689,8 @@ describe UsersController do
|
|
560
689
|
it "should require the password update to be successfull" do
|
561
690
|
@user.stub!(:update_attributes).and_return(false)
|
562
691
|
post :welcome, :token => 'mock_token', :user => @valid_params
|
563
|
-
flash.now[:error].should_not be_blank
|
692
|
+
# flash.now[:error].should_not be_blank
|
693
|
+
response.should have_tag("div.error")
|
564
694
|
response.should render_template(:welcome_form)
|
565
695
|
end
|
566
696
|
|
@@ -574,6 +704,5 @@ describe UsersController do
|
|
574
704
|
flash[:success].should_not be_blank
|
575
705
|
response.should redirect_to(root_path)
|
576
706
|
end
|
577
|
-
end
|
578
|
-
|
707
|
+
end
|
579
708
|
end
|