rules_engine_users 0.0.1
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/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/rules_engine/controller_user_mail.rb +29 -0
- data/lib/rules_engine/controller_users.rb +170 -0
- data/lib/rules_engine_users.rb +4 -0
- data/rails_generators/USAGE +97 -0
- data/rails_generators/manifests/rules_engine_users.rb +79 -0
- data/rails_generators/manifests/rules_engine_users.yml +32 -0
- data/rails_generators/rules_engine_users_generator.rb +21 -0
- data/rails_generators/templates/app/controllers/admin/users_controller.rb +64 -0
- data/rails_generators/templates/app/controllers/users_controller.rb +215 -0
- data/rails_generators/templates/app/models/user.rb +113 -0
- data/rails_generators/templates/app/models/user_mailer.rb +26 -0
- data/rails_generators/templates/app/models/user_observer.rb +19 -0
- data/rails_generators/templates/app/views/admin/users/_form.html.erb +6 -0
- data/rails_generators/templates/app/views/admin/users/edit.html.erb +18 -0
- data/rails_generators/templates/app/views/admin/users/index.html.erb +52 -0
- data/rails_generators/templates/app/views/admin/users/new.html.erb +17 -0
- data/rails_generators/templates/app/views/admin/users/show.html.erb +15 -0
- data/rails_generators/templates/app/views/user_mailer/forgot_password.html.erb +11 -0
- data/rails_generators/templates/app/views/user_mailer/welcome_message.html.erb +11 -0
- data/rails_generators/templates/app/views/users/change_form.html.erb +22 -0
- data/rails_generators/templates/app/views/users/details.html.erb +11 -0
- data/rails_generators/templates/app/views/users/login_form.html.erb +35 -0
- data/rails_generators/templates/app/views/users/pswd_change_form.html.erb +20 -0
- data/rails_generators/templates/app/views/users/pswd_forgot_form.html.erb +18 -0
- data/rails_generators/templates/app/views/users/pswd_reset_form.html.erb +22 -0
- data/rails_generators/templates/app/views/users/welcome_form.html.erb +21 -0
- data/rails_generators/templates/db/migrate/20100104014507_create_users.rb +41 -0
- data/rails_generators/templates/doc/README.rules_engine_users +122 -0
- data/rails_generators/templates/doc/README.rules_engine_users_paths +12 -0
- data/rails_generators/templates/features/admin/user/edit.feature +46 -0
- data/rails_generators/templates/features/admin/user/index.feature +78 -0
- data/rails_generators/templates/features/admin/user/new.feature +26 -0
- data/rails_generators/templates/features/admin/user/show.feature +22 -0
- data/rails_generators/templates/features/admin/user/step_definitions/edit_steps.rb +3 -0
- data/rails_generators/templates/features/admin/user/step_definitions/index_steps.rb +13 -0
- data/rails_generators/templates/features/admin/user/step_definitions/show_steps.rb +3 -0
- data/rails_generators/templates/features/support/blueprint_users.rb +14 -0
- data/rails_generators/templates/features/user/change.feature +37 -0
- data/rails_generators/templates/features/user/details.feature +15 -0
- data/rails_generators/templates/features/user/login.feature +65 -0
- data/rails_generators/templates/features/user/pswd_change.feature +46 -0
- data/rails_generators/templates/features/user/pswd_forgot.feature +32 -0
- data/rails_generators/templates/features/user/pswd_reset.feature +52 -0
- data/rails_generators/templates/features/user/step_definitions/login_steps.rb +46 -0
- data/rails_generators/templates/features/user/step_definitions/pswd_reset_steps.rb +15 -0
- data/rails_generators/templates/features/user/step_definitions/welcome_steps.rb +15 -0
- data/rails_generators/templates/features/user/welcome.feature +52 -0
- data/rails_generators/templates/spec/controllers/admin/users_controller_spec.rb +191 -0
- data/rails_generators/templates/spec/controllers/users_controller_spec.rb +579 -0
- data/rails_generators/templates/spec/models/user_mailer_spec.rb +39 -0
- data/rails_generators/templates/spec/models/user_observer_spec.rb +56 -0
- data/rails_generators/templates/spec/models/user_spec.rb +253 -0
- data/rails_generators/templates/spec/support/rules_engine_macros.rb +16 -0
- data/rules_engine_users.gemspec +141 -0
- data/spec/railsenv/app/controllers/application_controller.rb +10 -0
- data/spec/railsenv/config/boot.rb +110 -0
- data/spec/railsenv/config/database.yml +22 -0
- data/spec/railsenv/config/environment.rb +41 -0
- data/spec/railsenv/config/environments/development.rb +17 -0
- data/spec/railsenv/config/environments/production.rb +28 -0
- data/spec/railsenv/config/environments/test.rb +28 -0
- data/spec/railsenv/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/railsenv/config/initializers/inflections.rb +10 -0
- data/spec/railsenv/config/initializers/mime_types.rb +5 -0
- data/spec/railsenv/config/initializers/new_rails_defaults.rb +19 -0
- data/spec/railsenv/config/initializers/session_store.rb +15 -0
- data/spec/railsenv/config/locales/en.yml +5 -0
- data/spec/railsenv/config/routes.rb +43 -0
- data/spec/railsenv/db/test.sqlite3 +1 -0
- data/spec/railsenv/log/debug.log +1 -0
- data/spec/railsenv/log/test.log +1 -0
- data/spec/rcov.opts +3 -0
- data/spec/rules_engine/controller_user_mail_spec.rb +43 -0
- data/spec/rules_engine/controller_users_spec.rb +337 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +30 -0
- data/tasks/rspec.rake +18 -0
- metadata +180 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe UsersController do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
controller.instance_eval { flash.stub!(:sweep) }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe "GET login_form" do
|
|
10
|
+
it "should render the 'login_form' template" do
|
|
11
|
+
get :login_form
|
|
12
|
+
response.should render_template(:login_form)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "already logged in" do
|
|
16
|
+
before(:each) do
|
|
17
|
+
controller.stub!(:logged_in?).and_return(true)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should set a success message if already lodded in" do
|
|
21
|
+
get :login_form
|
|
22
|
+
flash[:success].should_not be_blank
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should redirect to the root_path" do
|
|
26
|
+
get :login_form
|
|
27
|
+
response.should redirect_to(root_path)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "POST login" do
|
|
33
|
+
before do
|
|
34
|
+
# User.stub!(:new).and_return @user = mock_model(User)
|
|
35
|
+
@user = mock_model(User, :access_level => User::ACCESS_LEVEL_ADMIN )
|
|
36
|
+
User.stub!(:authenticate_by_email).and_return(@user)
|
|
37
|
+
@user.stub(:remember_token).and_return('mock_remember_token')
|
|
38
|
+
@user.stub(:remember_token_expires_at).and_return(Time.now)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should authenticate by email" do
|
|
42
|
+
User.should_receive(:authenticate_by_email).with("mock_email", "mock_password")
|
|
43
|
+
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should set the current user to the authenticated user" do
|
|
47
|
+
controller.should_receive(:current_user=).with(@user)
|
|
48
|
+
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "authentication passed" do
|
|
52
|
+
before(:each) do
|
|
53
|
+
controller.stub!(:logged_in?).and_return(true)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should redirect to the root_path" do
|
|
57
|
+
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
|
58
|
+
response.should redirect_to(root_path)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should redirect to the session[:return_to] path" do
|
|
62
|
+
controller.stub(:session).and_return(:return_to => '/mock_return_to')
|
|
63
|
+
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
|
64
|
+
response.should redirect_to('/mock_return_to')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
describe ":remember me set" do
|
|
68
|
+
it "should set the remember me token" do
|
|
69
|
+
@user.should_receive(:set_remember_token)
|
|
70
|
+
post :login, :user => { :name => "mock_email", :password => "mock_password"}, :remember_me => "1"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should set the auth_token cookie" do
|
|
74
|
+
cookies = {}
|
|
75
|
+
controller.stub(:cookies).and_return(cookies)
|
|
76
|
+
@user.should_receive(:set_remember_token)
|
|
77
|
+
post :login, :user => { :name => "mock_email", :password => "mock_password"}, :remember_me => "1"
|
|
78
|
+
|
|
79
|
+
cookies[:auth_token][:value].should_not be_blank
|
|
80
|
+
cookies[:auth_token][:expires].should_not be_blank
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe "authentication failed" do
|
|
86
|
+
before(:each) do
|
|
87
|
+
User.stub!(:authenticate_by_email).and_return(nil)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should set an error message" do
|
|
91
|
+
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
|
92
|
+
flash.now[:error].should_not be_blank
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "should render the login form" do
|
|
96
|
+
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
|
97
|
+
response.should render_template(:login_form)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe "user account has been disabled" do
|
|
102
|
+
before(:each) do
|
|
103
|
+
@user.stub!(:access_level).and_return(User::ACCESS_LEVEL_DISABLED)
|
|
104
|
+
User.stub!(:authenticate_by_email).and_return(@user)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should set an error message" do
|
|
108
|
+
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
|
109
|
+
flash.now[:error].should_not be_blank
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "should redirect to the root_path" do
|
|
113
|
+
post :login, :user => { :name => "mock_email", :password => "mock_password"}
|
|
114
|
+
response.should redirect_to(root_path)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe "GET logout" do
|
|
121
|
+
describe "the user is logged in" do
|
|
122
|
+
it "should reset the current users remember me token" do
|
|
123
|
+
user = mock_model(User)
|
|
124
|
+
controller.stub!(:current_user).and_return(user)
|
|
125
|
+
controller.stub!(:logged_in?).and_return(true)
|
|
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
|
|
133
|
+
cookies = {:auth_token => 'mock_token'}
|
|
134
|
+
controller.stub!(:cookies).and_return(cookies)
|
|
135
|
+
get :logout
|
|
136
|
+
cookies[:auth_token].should be_blank
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "should reset the session variables" do
|
|
140
|
+
controller.should_receive(:reset_session)
|
|
141
|
+
get :logout
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "should redirec to the login page" do
|
|
145
|
+
get :logout
|
|
146
|
+
response.should redirect_to(user_login_path)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
describe "GET details" do
|
|
151
|
+
before(:each) do
|
|
152
|
+
controller.stub!(:login_required)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it "should require the user to be logged_in" do
|
|
156
|
+
controller.should_receive(:login_required)
|
|
157
|
+
get :details
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it "should set the user to the current user" do
|
|
161
|
+
user = mock_model(User)
|
|
162
|
+
controller.stub!(:current_user).and_return(user)
|
|
163
|
+
get :details
|
|
164
|
+
assigns[:user].should == user
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "should render the details template" do
|
|
168
|
+
get :details
|
|
169
|
+
response.should render_template(:details)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
describe "GET change_form" do
|
|
174
|
+
before(:each) do
|
|
175
|
+
controller.stub!(:login_required)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
it "should require the user to be logged_in" do
|
|
179
|
+
controller.should_receive(:login_required)
|
|
180
|
+
get :change_form
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "should set the user to the current user" do
|
|
184
|
+
user = mock_model(User)
|
|
185
|
+
controller.stub!(:current_user).and_return(user)
|
|
186
|
+
get :change_form
|
|
187
|
+
assigns[:user].should == user
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it "should render the user_change_form template" do
|
|
191
|
+
get :change_form
|
|
192
|
+
response.should render_template(:change_form)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
describe "POST change" do
|
|
197
|
+
before do
|
|
198
|
+
controller.stub!(:login_required)
|
|
199
|
+
@user = mock_model(User)
|
|
200
|
+
@user.stub!(:update_attributes).and_return(true)
|
|
201
|
+
controller.stub!(:current_user).and_return(@user)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it "should require the user to be logged_in" do
|
|
205
|
+
controller.should_receive(:login_required)
|
|
206
|
+
post :change, :user => {}
|
|
207
|
+
end
|
|
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
|
|
223
|
+
|
|
224
|
+
describe "update failed" do
|
|
225
|
+
before do
|
|
226
|
+
@user.stub!(:update_attributes).and_return(false)
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it "should render the 'user_change_form' template" do
|
|
230
|
+
post :change, :user => { :name => "value" }
|
|
231
|
+
response.should render_template(:change_form)
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
describe "user updated" do
|
|
236
|
+
it "should redirect to the user_details path" do
|
|
237
|
+
post :change, :user => { :name => "value" }
|
|
238
|
+
response.should redirect_to(user_details_path)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
it "should have a success flash message" do
|
|
242
|
+
post :change, :user => { :name => "value" }
|
|
243
|
+
flash[:success].should_not be_blank
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
describe "GET pswd_change_form" do
|
|
250
|
+
before(:each) do
|
|
251
|
+
controller.stub!(:login_required)
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
it "should require the user to be logged_in" do
|
|
255
|
+
controller.should_receive(:login_required)
|
|
256
|
+
get :pswd_change_form
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "should set the user to the current user" do
|
|
260
|
+
user = mock_model(User)
|
|
261
|
+
controller.stub!(:current_user).and_return(user)
|
|
262
|
+
get :pswd_change_form
|
|
263
|
+
assigns[:user].should == user
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
it "should render the pswd_change_form template" do
|
|
267
|
+
get :pswd_change_form
|
|
268
|
+
response.should render_template(:pswd_change_form)
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
describe "POST pswd_change" do
|
|
274
|
+
before do
|
|
275
|
+
controller.stub!(:login_required)
|
|
276
|
+
@user = mock_model(User, :email => 'mock_email')
|
|
277
|
+
@user.stub!(:update_attributes).and_return(true)
|
|
278
|
+
controller.stub!(:current_user).and_return(@user)
|
|
279
|
+
|
|
280
|
+
User.stub!(:authenticate_by_email).and_return(true)
|
|
281
|
+
|
|
282
|
+
@valid_params = {:old_password => 'old password', :password => 'new password', :password_confirmation => 'new password'}
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
it "should require the user to be logged_in" do
|
|
286
|
+
controller.should_receive(:login_required)
|
|
287
|
+
post :pswd_change, :user => @valid_params
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
it "should require the old_password" do
|
|
291
|
+
post :pswd_change, :user => @valid_params.except(:old_password)
|
|
292
|
+
flash.now[:error].should_not be_blank
|
|
293
|
+
response.should render_template(:pswd_change_form)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
it "should require the password" do
|
|
297
|
+
post :pswd_change, :user => @valid_params.except(:password)
|
|
298
|
+
flash.now[:error].should_not be_blank
|
|
299
|
+
response.should render_template(:pswd_change_form)
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
it "should require the password confirmation" do
|
|
303
|
+
post :pswd_change, :user => @valid_params.except(:password_confirmation)
|
|
304
|
+
flash.now[:error].should_not be_blank
|
|
305
|
+
response.should render_template(:pswd_change_form)
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
it "should confirm the user's old password is correct" do
|
|
309
|
+
User.should_receive(:authenticate_by_email).with("mock_email", "old password")
|
|
310
|
+
post :pswd_change, :user => @valid_params
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
it "should require the old password to be correct" do
|
|
314
|
+
User.stub!(:authenticate_by_email).and_return(false)
|
|
315
|
+
post :pswd_change, :user => @valid_params
|
|
316
|
+
flash.now[:error].should_not be_blank
|
|
317
|
+
response.should render_template(:pswd_change_form)
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
it "should update the password fields only" do
|
|
321
|
+
@user.should_receive(:update_attributes).with(:password => "new password", :password_confirmation => "new password")
|
|
322
|
+
post :pswd_change, :user => @valid_params
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
it "should confirm the update of the password" do
|
|
326
|
+
@user.should_receive(:update_attributes).and_return(false)
|
|
327
|
+
post :pswd_change, :user => @valid_params
|
|
328
|
+
flash.now[:error].should_not be_blank
|
|
329
|
+
response.should render_template(:pswd_change_form)
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
it "should redirect to the user_details_path" do
|
|
333
|
+
@user.should_receive(:update_attributes).and_return(true)
|
|
334
|
+
post :pswd_change, :user => @valid_params
|
|
335
|
+
flash[:success].should_not be_blank
|
|
336
|
+
response.should redirect_to(user_details_path)
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
describe "GET pswd_forgot_form" do
|
|
342
|
+
it "should render the pswd_forgot_form template" do
|
|
343
|
+
get :pswd_forgot_form
|
|
344
|
+
response.should render_template(:pswd_forgot_form)
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
describe "POST pswd_forgot" do
|
|
349
|
+
it "should set the reset token" do
|
|
350
|
+
User.should_receive(:set_reset_token).with('mock_email')
|
|
351
|
+
post :pswd_forgot, :user => {:email => "mock_email"}
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
describe "reset token set" do
|
|
355
|
+
it "should redirect to the user login page" do
|
|
356
|
+
User.stub!(:set_reset_token).and_return(true)
|
|
357
|
+
post :pswd_forgot, :user => {:email => "mock_email"}
|
|
358
|
+
flash[:success].should_not be_blank
|
|
359
|
+
response.should redirect_to(user_login_path)
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
describe "reset token not set" do
|
|
364
|
+
it "should render the pswd_forgot_form" do
|
|
365
|
+
User.stub!(:set_reset_token).and_return(false)
|
|
366
|
+
post :pswd_forgot, :user => {:email => "mock_email"}
|
|
367
|
+
flash.now[:error].should_not be_blank
|
|
368
|
+
response.should render_template(:pswd_forgot_form)
|
|
369
|
+
end
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
describe "GET pswd_reset_form" do
|
|
374
|
+
it "should require a reset token" do
|
|
375
|
+
get :pswd_reset_form
|
|
376
|
+
# flash[:error].should_not be_blank
|
|
377
|
+
response.should redirect_to(user_pswd_forgot_path)
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
it "should authenticate the reset token" do
|
|
381
|
+
User.should_receive(:authenticate_by_reset_token).with('mock_token')
|
|
382
|
+
get :pswd_reset_form, :token => "mock_token"
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
it "should assign the reset token" do
|
|
386
|
+
get :pswd_reset_form, :token => "mock_token"
|
|
387
|
+
assigns[:token].should == "mock_token"
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
it "should redirect to password forgot form if authentication failed" do
|
|
391
|
+
User.stub!(:authenticate_by_reset_token).and_return(false)
|
|
392
|
+
get :pswd_reset_form, :token => "mock_token"
|
|
393
|
+
flash[:error].should_not be_blank
|
|
394
|
+
response.should redirect_to(user_pswd_forgot_path)
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
it "should render the pswd_reset_form" do
|
|
398
|
+
User.stub!(:authenticate_by_reset_token).and_return(true)
|
|
399
|
+
get :pswd_reset_form, :token => "mock_token"
|
|
400
|
+
response.should render_template(:pswd_reset_form)
|
|
401
|
+
end
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
describe "POST pswd_reset" do
|
|
405
|
+
before do
|
|
406
|
+
@user = mock_model(User, :email => 'mock_email')
|
|
407
|
+
@user.stub!(:update_attributes).and_return(true)
|
|
408
|
+
User.stub!(:authenticate_by_reset_token).and_return(@user)
|
|
409
|
+
@valid_params = {:email => 'mock_email', :password => 'new password', :password_confirmation => 'new password'}
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
it "should require a reset token" do
|
|
413
|
+
post :pswd_reset, :user => @valid_params
|
|
414
|
+
# flash.now[:error].should_not be_blank
|
|
415
|
+
response.should render_template(:pswd_forgot_form)
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
it "should require an email address" do
|
|
419
|
+
post :pswd_reset, :token => 'mock_token', :user => @valid_params.except(:email)
|
|
420
|
+
flash.now[:error].should_not be_blank
|
|
421
|
+
response.should render_template(:pswd_reset_form)
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
it "should require a password" do
|
|
425
|
+
post :pswd_reset, :token => 'mock_token', :user => @valid_params.except(:password)
|
|
426
|
+
flash.now[:error].should_not be_blank
|
|
427
|
+
response.should render_template(:pswd_reset_form)
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
it "should require a password to match the password confirmation" do
|
|
431
|
+
post :pswd_reset, :token => 'mock_token', :user => @valid_params.merge(:password_confirmation => 'wrong')
|
|
432
|
+
flash.now[:error].should_not be_blank
|
|
433
|
+
response.should render_template(:pswd_reset_form)
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
it "should authenticate the reset token" do
|
|
437
|
+
User.should_receive(:authenticate_by_reset_token).with("mock_token")
|
|
438
|
+
post :pswd_reset, :token => 'mock_token', :user => @valid_params
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
it "should require the reset token to be authenticated" do
|
|
442
|
+
User.stub!(:authenticate_by_reset_token).and_return(false)
|
|
443
|
+
post :pswd_reset, :token => 'mock_token', :user => @valid_params
|
|
444
|
+
flash.now[:error].should_not be_blank
|
|
445
|
+
response.should render_template(:pswd_reset_form)
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
it "should require the authenticated user to have the same email address" do
|
|
449
|
+
@user.stub!(:email).and_return('wrong')
|
|
450
|
+
post :pswd_reset, :token => 'mock_token', :user => @valid_params
|
|
451
|
+
flash.now[:error].should_not be_blank
|
|
452
|
+
response.should render_template(:pswd_reset_form)
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
it "should update the user's password" do
|
|
456
|
+
@user.should_receive(:update_attributes).with(:password => 'new password', :password_confirmation => 'new password')
|
|
457
|
+
post :pswd_reset, :token => 'mock_token', :user => @valid_params
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
it "should require the password update to be successfull" do
|
|
461
|
+
@user.stub!(:update_attributes).and_return(false)
|
|
462
|
+
post :pswd_reset, :token => 'mock_token', :user => @valid_params
|
|
463
|
+
flash.now[:error].should_not be_blank
|
|
464
|
+
response.should render_template(:pswd_reset_form)
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
it "should set the authenticated user to the current user" do
|
|
468
|
+
post :pswd_reset, :token => 'mock_token', :user => @valid_params
|
|
469
|
+
controller.current_user.should == @user
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
it "should redirect to the root_page" do
|
|
473
|
+
post :pswd_reset, :token => 'mock_token', :user => @valid_params
|
|
474
|
+
flash[:success].should_not be_blank
|
|
475
|
+
response.should redirect_to(root_path)
|
|
476
|
+
end
|
|
477
|
+
end
|
|
478
|
+
|
|
479
|
+
describe "GET welcome_form" do
|
|
480
|
+
it "should require a reset token" do
|
|
481
|
+
get :welcome_form
|
|
482
|
+
response.should redirect_to(user_pswd_forgot_path)
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
it "should authenticate the reset token" do
|
|
486
|
+
User.should_receive(:authenticate_by_reset_token).with('mock_token')
|
|
487
|
+
get :welcome_form, :token => "mock_token"
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
it "should redirect to password forgot form if authentication failed" do
|
|
491
|
+
User.stub!(:authenticate_by_reset_token).and_return(false)
|
|
492
|
+
get :welcome_form, :token => "mock_token"
|
|
493
|
+
flash[:error].should_not be_blank
|
|
494
|
+
response.should redirect_to(user_pswd_forgot_path)
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
it "should render the welcome_form" do
|
|
498
|
+
User.stub!(:authenticate_by_reset_token).and_return(true)
|
|
499
|
+
get :welcome_form, :token => "mock_token"
|
|
500
|
+
response.should render_template(:welcome_form)
|
|
501
|
+
end
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
describe "POST welcome" do
|
|
505
|
+
before do
|
|
506
|
+
@user = mock_model(User, :email => 'mock_email')
|
|
507
|
+
@user.stub!(:update_attributes).and_return(true)
|
|
508
|
+
User.stub!(:authenticate_by_reset_token).and_return(@user)
|
|
509
|
+
@valid_params = {:email => 'mock_email', :password => 'new password', :password_confirmation => 'new password'}
|
|
510
|
+
end
|
|
511
|
+
|
|
512
|
+
it "should require a reset token" do
|
|
513
|
+
post :welcome, :user => @valid_params
|
|
514
|
+
flash.now[:error].should_not be_blank
|
|
515
|
+
response.should render_template(:pswd_forgot_form)
|
|
516
|
+
end
|
|
517
|
+
|
|
518
|
+
it "should require an email address" do
|
|
519
|
+
post :welcome, :token => 'mock_token', :user => @valid_params.except(:email)
|
|
520
|
+
flash.now[:error].should_not be_blank
|
|
521
|
+
response.should render_template(:welcome_form)
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
it "should require a password" do
|
|
525
|
+
post :welcome, :token => 'mock_token', :user => @valid_params.except(:password)
|
|
526
|
+
flash.now[:error].should_not be_blank
|
|
527
|
+
response.should render_template(:welcome_form)
|
|
528
|
+
end
|
|
529
|
+
|
|
530
|
+
it "should require a password to match the password confirmation" do
|
|
531
|
+
post :welcome, :token => 'mock_token', :user => @valid_params.merge(:password_confirmation => 'wrong')
|
|
532
|
+
flash.now[:error].should_not be_blank
|
|
533
|
+
response.should render_template(:welcome_form)
|
|
534
|
+
end
|
|
535
|
+
|
|
536
|
+
it "should authenticate the reset token" do
|
|
537
|
+
User.should_receive(:authenticate_by_reset_token).with("mock_token")
|
|
538
|
+
post :welcome, :token => 'mock_token', :user => @valid_params
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
it "should require the reset token to be authenticated" do
|
|
542
|
+
User.stub!(:authenticate_by_reset_token).and_return(false)
|
|
543
|
+
post :welcome, :token => 'mock_token', :user => @valid_params
|
|
544
|
+
flash.now[:error].should_not be_blank
|
|
545
|
+
response.should render_template(:welcome_form)
|
|
546
|
+
end
|
|
547
|
+
|
|
548
|
+
it "should require the authenticated user to have the same email address" do
|
|
549
|
+
@user.stub!(:email).and_return('wrong')
|
|
550
|
+
post :welcome, :token => 'mock_token', :user => @valid_params
|
|
551
|
+
flash.now[:error].should_not be_blank
|
|
552
|
+
response.should render_template(:welcome_form)
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
it "should update the user's password" do
|
|
556
|
+
@user.should_receive(:update_attributes).with(:password => 'new password', :password_confirmation => 'new password')
|
|
557
|
+
post :welcome, :token => 'mock_token', :user => @valid_params
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
it "should require the password update to be successfull" do
|
|
561
|
+
@user.stub!(:update_attributes).and_return(false)
|
|
562
|
+
post :welcome, :token => 'mock_token', :user => @valid_params
|
|
563
|
+
flash.now[:error].should_not be_blank
|
|
564
|
+
response.should render_template(:welcome_form)
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
it "should set the authenticated user to the current user" do
|
|
568
|
+
post :welcome, :token => 'mock_token', :user => @valid_params
|
|
569
|
+
controller.current_user.should == @user
|
|
570
|
+
end
|
|
571
|
+
|
|
572
|
+
it "should redirect to the root_page" do
|
|
573
|
+
post :welcome, :token => 'mock_token', :user => @valid_params
|
|
574
|
+
flash[:success].should_not be_blank
|
|
575
|
+
response.should redirect_to(root_path)
|
|
576
|
+
end
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe UserMailer do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@valid_options =
|
|
6
|
+
{
|
|
7
|
+
:to_name => 'Test User',
|
|
8
|
+
:to_email => 'Test@UserName.com',
|
|
9
|
+
:token => "test_token"
|
|
10
|
+
}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "welcome message" do
|
|
14
|
+
it "should include direct link to activate the account" do
|
|
15
|
+
mail = UserMailer.deliver_welcome_message(@valid_options)
|
|
16
|
+
mail.body.should =~ /Hello Test User,/
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should include direct link to create a password" do
|
|
20
|
+
RulesEngine::ControllerUserMail.host = "my.server.name"
|
|
21
|
+
mail = UserMailer.deliver_welcome_message(@valid_options)
|
|
22
|
+
mail.body.should =~ /http:\/\/my.server.name\/user\/pswd_reset\?token=test_token/
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "forgot password" do
|
|
28
|
+
it "should include direct link to activate the account" do
|
|
29
|
+
mail = UserMailer.deliver_forgot_password(@valid_options)
|
|
30
|
+
mail.body.should =~ /Hello Test User,/
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should include direct link to create a password" do
|
|
34
|
+
RulesEngine::ControllerUserMail.host = "my.server.name"
|
|
35
|
+
mail = UserMailer.deliver_forgot_password(@valid_options)
|
|
36
|
+
mail.body.should =~ /http:\/\/my.server.name\/user\/pswd_reset\?token=test_token/
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe UserObserver do
|
|
4
|
+
def valid_attributes
|
|
5
|
+
{
|
|
6
|
+
:full_name => 'Test User Name',
|
|
7
|
+
:email => 'Test@UserName.com',
|
|
8
|
+
:login => 'test',
|
|
9
|
+
:time_zone => "WOW",
|
|
10
|
+
|
|
11
|
+
:phone => "0408 505 1234",
|
|
12
|
+
|
|
13
|
+
:password => 'test_password',
|
|
14
|
+
:password_confirmation => 'test_password',
|
|
15
|
+
:access_level => User::ACCESS_LEVEL_DISABLED
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "after create" do
|
|
20
|
+
it "should deliver the welcome notification to the user" do
|
|
21
|
+
UserMailer.should_receive(:deliver_welcome_message)
|
|
22
|
+
User.create(valid_attributes)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should not deliver the welcome notification if deliveries are turned off" do
|
|
26
|
+
ActionMailer::Base.stub(:perform_deliveries).and_return(false)
|
|
27
|
+
UserMailer.should_not_receive(:deliver_welcome_message)
|
|
28
|
+
User.create(valid_attributes)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "after save" do
|
|
33
|
+
before do
|
|
34
|
+
@user = User.create(valid_attributes)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should not send forgot password after a regular save" do
|
|
38
|
+
UserMailer.should_not_receive :deliver_forgot_password
|
|
39
|
+
@user.stub!(:reset_token).and_return(nil)
|
|
40
|
+
|
|
41
|
+
@user.full_name = "new"
|
|
42
|
+
@user.save
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should send password reset mail after user has been requested it to be reset" do
|
|
46
|
+
UserMailer.should_receive :deliver_forgot_password
|
|
47
|
+
User.set_reset_token(@user.email)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should not send password reset mail if deliveries are turned off" do
|
|
51
|
+
ActionMailer::Base.stub(:perform_deliveries).and_return(false)
|
|
52
|
+
UserMailer.should_not_receive :deliver_forgot_password
|
|
53
|
+
User.set_reset_token(@user.email)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|