amrita2 1.9.6 → 2.0.0
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/README +112 -0
- data/init.rb +6 -0
- data/lib/amrita2/gettext.rb +116 -0
- data/lib/amrita2/macro.rb +153 -0
- data/lib/amrita2/rails_bridge.rb +172 -26
- data/lib/amrita2/template.rb +2634 -234
- data/lib/amrita2/testsupport.rb +171 -0
- data/lib/amrita2/version.rb +3 -3
- data/lib/amrita2.rb +1 -0
- data/sample/depot/app/controllers/admin_controller.rb +59 -0
- data/sample/depot/app/controllers/application.rb +20 -0
- data/sample/depot/app/controllers/info_controller.rb +19 -0
- data/sample/depot/app/controllers/login_controller.rb +85 -0
- data/sample/depot/app/controllers/store_controller.rb +68 -0
- data/sample/depot/app/helpers/admin_helper.rb +7 -0
- data/sample/depot/app/helpers/application_helper.rb +10 -0
- data/sample/depot/app/helpers/ar_form.rb +169 -0
- data/sample/depot/app/helpers/form_tag.rb +24 -0
- data/sample/depot/app/helpers/info_helper.rb +7 -0
- data/sample/depot/app/helpers/standard_form.rb +73 -0
- data/sample/depot/app/helpers/store_helper.rb +14 -0
- data/sample/depot/app/models/cart.rb +36 -0
- data/sample/depot/app/models/cart_item.rb +26 -0
- data/sample/depot/app/models/line_item.rb +34 -0
- data/sample/depot/app/models/order.rb +57 -0
- data/sample/depot/app/models/product.rb +41 -0
- data/sample/depot/app/models/user.rb +83 -0
- data/sample/depot/config/boot.rb +49 -0
- data/sample/depot/config/environment.rb +83 -0
- data/sample/depot/config/environments/development.rb +24 -0
- data/sample/depot/config/environments/production.rb +24 -0
- data/sample/depot/config/environments/test.rb +24 -0
- data/sample/depot/config/routes.rb +10 -0
- data/sample/depot/db/migrate/001_create_products.rb +18 -0
- data/sample/depot/db/migrate/002_add_price.rb +14 -0
- data/sample/depot/db/migrate/003_add_test_data.rb +68 -0
- data/sample/depot/db/migrate/004_add_sessions.rb +20 -0
- data/sample/depot/db/migrate/005_create_orders.rb +21 -0
- data/sample/depot/db/migrate/006_create_line_items.rb +27 -0
- data/sample/depot/db/migrate/007_create_users.rb +18 -0
- data/sample/depot/db/schema.rb +45 -0
- data/sample/depot/public/dispatch.rb +15 -0
- data/sample/depot/test/functional/admin_controller_test.rb +54 -0
- data/sample/depot/test/functional/info_controller_test.rb +23 -0
- data/sample/depot/test/functional/login_controller_test.rb +74 -0
- data/sample/depot/test/functional/store_controller_test.rb +57 -0
- data/sample/depot/test/integration/dsl_user_stories_test.rb +126 -0
- data/sample/depot/test/integration/user_stories_test.rb +70 -0
- data/sample/depot/test/performance/order_speed_test.rb +58 -0
- data/sample/depot/test/test_helper.rb +16 -0
- data/sample/depot/test/unit/cart_test.rb +39 -0
- data/sample/depot/test/unit/cart_test1.rb +31 -0
- data/sample/depot/test/unit/line_item_test.rb +15 -0
- data/sample/depot/test/unit/order_test.rb +15 -0
- data/sample/depot/test/unit/product_test.rb +98 -0
- data/sample/depot/vendor/plugins/amrita2/init.rb +6 -0
- data/sample/hello/hello.rb +22 -0
- data/sample/login_engine/app/controllers/application.rb +16 -0
- data/sample/login_engine/app/controllers/user_controller.rb +265 -0
- data/sample/login_engine/app/helpers/application_helper.rb +3 -0
- data/sample/login_engine/app/helpers/form_tag.rb +16 -0
- data/sample/login_engine/app/helpers/two_columns.rb +24 -0
- data/sample/login_engine/app/helpers/two_columns_form.rb +47 -0
- data/sample/login_engine/app/helpers/user_helper.rb +88 -0
- data/sample/login_engine/app/models/user.rb +7 -0
- data/sample/login_engine/app/models/user_notify.rb +75 -0
- data/sample/login_engine/config/boot.rb +45 -0
- data/sample/login_engine/config/environment.rb +140 -0
- data/sample/login_engine/config/environments/development.rb +21 -0
- data/sample/login_engine/config/environments/production.rb +18 -0
- data/sample/login_engine/config/environments/test.rb +19 -0
- data/sample/login_engine/config/routes.rb +23 -0
- data/sample/login_engine/db/migrate/001_create_users.rb +25 -0
- data/sample/login_engine/db/schema.rb +25 -0
- data/sample/login_engine/lib/config.rb +113 -0
- data/sample/login_engine/lib/hpricot_test_extension.rb +80 -0
- data/sample/login_engine/lib/login_engine/authenticated_system.rb +113 -0
- data/sample/login_engine/lib/login_engine/authenticated_user.rb +155 -0
- data/sample/login_engine/lib/login_engine.rb +62 -0
- data/sample/login_engine/public/dispatch.rb +10 -0
- data/sample/login_engine/test/functional/amrita2_test.rb +267 -0
- data/sample/login_engine/test/functional/user_controller_test.rb +544 -0
- data/sample/login_engine/test/mocks/mail.rb +14 -0
- data/sample/login_engine/test/mocks/time.rb +19 -0
- data/sample/login_engine/test/test_helper.rb +31 -0
- data/sample/login_engine/test/unit/user_test.rb +116 -0
- data/sample/login_engine/vendor/plugins/amrita2/init.rb +6 -0
- data/specs/attribute.rb +201 -0
- data/specs/datatypes.rb +231 -0
- data/specs/dictionary.rb +68 -0
- data/specs/erb_cdata.rb +187 -0
- data/specs/filters.rb +513 -0
- data/specs/gettext/erb_gettext.rb +42 -0
- data/specs/gettext/gettext_util.rb +65 -0
- data/specs/gettext/static_text.rb +103 -0
- data/specs/impl/code_generator.rb +87 -0
- data/specs/impl/dynamic_element.rb +92 -0
- data/specs/impl/hash_delegator.rb +57 -0
- data/specs/impl/parse_opt.rb +34 -0
- data/specs/impl/preprocess.rb +823 -0
- data/specs/impl/testsupport.rb +89 -0
- data/specs/inlineruby.rb +429 -0
- data/specs/intro.rb +654 -0
- data/specs/loop.rb +203 -0
- data/specs/macro.rb +532 -0
- data/specs/sample.rb +34 -0
- data/specs/sanitize.rb +110 -0
- data/specs/template.rb +189 -0
- data/specs/trace.rb +97 -0
- metadata +138 -19
- data/lib/amrita2/core.rb +0 -1897
- data/lib/amrita2/rd.rb +0 -314
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
|
+
require 'user_controller'
|
|
3
|
+
|
|
4
|
+
# Re-raise errors caught by the controller.
|
|
5
|
+
class UserController; def rescue_action(e) raise e end; end
|
|
6
|
+
|
|
7
|
+
class UserControllerTest < Test::Unit::TestCase
|
|
8
|
+
fixtures :users
|
|
9
|
+
|
|
10
|
+
def setup
|
|
11
|
+
LoginEngine::CONFIG[:salt] = "test-salt"
|
|
12
|
+
|
|
13
|
+
@controller = UserController.new
|
|
14
|
+
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
|
|
15
|
+
@request.host = "localhost"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#==========================================================================
|
|
21
|
+
#
|
|
22
|
+
# Login/Logout
|
|
23
|
+
#
|
|
24
|
+
#==========================================================================
|
|
25
|
+
|
|
26
|
+
def test_home_without_login
|
|
27
|
+
get :home
|
|
28
|
+
assert_redirected_to :action => "login"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_invalid_login
|
|
32
|
+
post :login, :user => { :login => "bob", :password => "wrong_password" }
|
|
33
|
+
assert_response :success
|
|
34
|
+
|
|
35
|
+
assert_nil session[:user]
|
|
36
|
+
assert_template "login"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_login
|
|
40
|
+
@request.session['return-to'] = "/bogus/location"
|
|
41
|
+
|
|
42
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
43
|
+
|
|
44
|
+
assert_response :redirect
|
|
45
|
+
assert(@response.has_session_object?(:user))
|
|
46
|
+
assert_equal users(:bob), session[:user]
|
|
47
|
+
|
|
48
|
+
assert_equal("http://#{@request.host}/bogus/location", @response.redirect_url)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_login_logoff
|
|
52
|
+
|
|
53
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
54
|
+
assert(@response.has_session_object?(:user))
|
|
55
|
+
|
|
56
|
+
get :logout
|
|
57
|
+
assert_nil session[:user]
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
#==========================================================================
|
|
63
|
+
#
|
|
64
|
+
# Signup
|
|
65
|
+
#
|
|
66
|
+
#==========================================================================
|
|
67
|
+
|
|
68
|
+
def test_signup
|
|
69
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
|
70
|
+
|
|
71
|
+
ActionMailer::Base.deliveries = []
|
|
72
|
+
|
|
73
|
+
@request.session['return-to'] = "/bogus/location"
|
|
74
|
+
|
|
75
|
+
assert_equal 5, User.count
|
|
76
|
+
post :signup, :user => { :login => "newbob", :password => "newpassword", :password_confirmation => "newpassword", :email => "newbob@test.com" }
|
|
77
|
+
assert_nil session[:user]
|
|
78
|
+
|
|
79
|
+
assert_redirected_to :action => "login"
|
|
80
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
81
|
+
mail = ActionMailer::Base.deliveries[0]
|
|
82
|
+
assert_equal "newbob@test.com", mail.to_addrs[0].to_s
|
|
83
|
+
assert_match /login:\s+\w+\n/, mail.encoded
|
|
84
|
+
assert_match /password:\s+\w+\n/, mail.encoded
|
|
85
|
+
#mail.encoded =~ /user_id=(.*?)&key=(.*?)"/
|
|
86
|
+
user_id = /user_id=(\d+)/.match(mail.encoded)[1]
|
|
87
|
+
key = /key=([a-z0-9]+)/.match(mail.encoded)[1]
|
|
88
|
+
|
|
89
|
+
assert_not_nil user_id
|
|
90
|
+
assert_not_nil key
|
|
91
|
+
|
|
92
|
+
user = User.find_by_email("newbob@test.com")
|
|
93
|
+
assert_not_nil user
|
|
94
|
+
assert_equal 0, user.verified
|
|
95
|
+
|
|
96
|
+
# First past the expiration.
|
|
97
|
+
Time.advance_by_days = 1
|
|
98
|
+
get :home, :user_id => "#{user_id}", :key => "#{key}"
|
|
99
|
+
Time.advance_by_days = 0
|
|
100
|
+
user = User.find_by_email("newbob@test.com")
|
|
101
|
+
assert_equal 0, user.verified
|
|
102
|
+
|
|
103
|
+
# Then a bogus key.
|
|
104
|
+
get :home, :user_id => "#{user_id}", :key => "boguskey"
|
|
105
|
+
user = User.find_by_email("newbob@test.com")
|
|
106
|
+
assert_equal 0, user.verified
|
|
107
|
+
|
|
108
|
+
# Now the real one.
|
|
109
|
+
get :home, :user_id => "#{user_id}", :key => "#{key}"
|
|
110
|
+
user = User.find_by_email("newbob@test.com")
|
|
111
|
+
assert_equal 1, user.verified
|
|
112
|
+
|
|
113
|
+
post :login, :user => { :login => "newbob", :password => "newpassword" }
|
|
114
|
+
assert(@response.has_session_object?(:user))
|
|
115
|
+
get :logout
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_signup_bad_password
|
|
120
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
|
121
|
+
ActionMailer::Base.deliveries = []
|
|
122
|
+
|
|
123
|
+
@request.session['return-to'] = "/bogus/location"
|
|
124
|
+
post :signup, :user => { :login => "newbob", :password => "bad", :password_confirmation => "bad", :email => "newbob@test.com" }
|
|
125
|
+
assert_nil session[:user]
|
|
126
|
+
#assert_invalid_column_on_record "user", "password"
|
|
127
|
+
assert assigns["user"].errors.invalid?("password")
|
|
128
|
+
|
|
129
|
+
assert_response :success
|
|
130
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_signup_bad_email
|
|
134
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
|
135
|
+
ActionMailer::Base.deliveries = []
|
|
136
|
+
|
|
137
|
+
@request.session['return-to'] = "/bogus/location"
|
|
138
|
+
|
|
139
|
+
ActionMailer::Base.inject_one_error = true
|
|
140
|
+
post :signup, :user => { :login => "newbob", :password => "newpassword", :password_confirmation => "newpassword", :email => "newbob@test.com" }
|
|
141
|
+
assert_nil session[:user]
|
|
142
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_signup_without_email
|
|
146
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
|
147
|
+
|
|
148
|
+
@request.session['return-to'] = "/bogus/location"
|
|
149
|
+
|
|
150
|
+
post :signup, :user => { :login => "newbob", :password => "newpassword", :password_confirmation => "newpassword", :email => "newbob@test.com" }
|
|
151
|
+
|
|
152
|
+
assert_redirected_to :action => "login"
|
|
153
|
+
assert_nil session[:user]
|
|
154
|
+
assert_match /Signup successful/, flash[:notice]
|
|
155
|
+
|
|
156
|
+
assert_not_nil User.find_by_login("newbob")
|
|
157
|
+
|
|
158
|
+
user = User.find_by_email("newbob@test.com")
|
|
159
|
+
assert_not_nil user
|
|
160
|
+
|
|
161
|
+
post :login, :user => { :login => "newbob", :password => "newpassword" }
|
|
162
|
+
assert(@response.has_session_object?(:user))
|
|
163
|
+
get :logout
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def test_signup_bad_details
|
|
167
|
+
@request.session['return-to'] = "/bogus/location"
|
|
168
|
+
|
|
169
|
+
# mismatched password
|
|
170
|
+
post :signup, :user => { :login => "newbob", :password => "newpassword", :password_confirmation => "wrong" }
|
|
171
|
+
#assert_invalid_column_on_record "user", "password"
|
|
172
|
+
assert assigns["user"].errors.invalid?("password")
|
|
173
|
+
assert_response :success
|
|
174
|
+
|
|
175
|
+
# login not long enough
|
|
176
|
+
post :signup, :user => { :login => "yo", :password => "newpassword", :password_confirmation => "newpassword" }
|
|
177
|
+
#assert_invalid_column_on_record "user", "login"
|
|
178
|
+
assert assigns["user"].errors.invalid?("login")
|
|
179
|
+
assert_response :success
|
|
180
|
+
|
|
181
|
+
# both
|
|
182
|
+
post :signup, :user => { :login => "yo", :password => "newpassword", :password_confirmation => "wrong" }
|
|
183
|
+
#assert_invalid_column_on_record "user", ["login", "password"]
|
|
184
|
+
assert assigns["user"].errors.invalid?("login")
|
|
185
|
+
assert assigns["user"].errors.invalid?("password")
|
|
186
|
+
assert_response :success
|
|
187
|
+
|
|
188
|
+
# existing user
|
|
189
|
+
post :signup, :user => { :login => "bob", :password => "doesnt_matter", :password_confirmation => "doesnt_matter" }
|
|
190
|
+
#assert_invalid_column_on_record "user", "login"
|
|
191
|
+
assert assigns["user"].errors.invalid?("login")
|
|
192
|
+
assert_response :success
|
|
193
|
+
|
|
194
|
+
# existing email
|
|
195
|
+
post :signup, :user => { :login => "newbob", :email => "longbob@test.com", :password => "doesnt_matter", :password_confirmation => "doesnt_matter" }
|
|
196
|
+
#assert_invalid_column_on_record "user", "email"
|
|
197
|
+
assert assigns["user"].errors.invalid?("email")
|
|
198
|
+
assert_response :success
|
|
199
|
+
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
#==========================================================================
|
|
204
|
+
#
|
|
205
|
+
# Edit
|
|
206
|
+
#
|
|
207
|
+
#==========================================================================
|
|
208
|
+
|
|
209
|
+
def test_edit
|
|
210
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
211
|
+
assert(@response.has_session_object?(:user))
|
|
212
|
+
|
|
213
|
+
post :edit, :user => { "firstname" => "Bob", "form" => "edit" }
|
|
214
|
+
assert_equal @response.session[:user].firstname, "Bob"
|
|
215
|
+
|
|
216
|
+
post :edit, :user => { "firstname" => "", "form" => "edit" }
|
|
217
|
+
assert_equal @response.session[:user].firstname, ""
|
|
218
|
+
|
|
219
|
+
get :logout
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
#==========================================================================
|
|
225
|
+
#
|
|
226
|
+
# Delete
|
|
227
|
+
#
|
|
228
|
+
#==========================================================================
|
|
229
|
+
|
|
230
|
+
def test_delete
|
|
231
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
|
232
|
+
# Immediate delete
|
|
233
|
+
post :login, :user => { :login => "deletebob1", :password => "alongtest" }
|
|
234
|
+
assert(@response.has_session_object?(:user))
|
|
235
|
+
|
|
236
|
+
LoginEngine.config :delayed_delete, false, :force
|
|
237
|
+
post :delete
|
|
238
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
239
|
+
assert_nil session[:user]
|
|
240
|
+
|
|
241
|
+
# try and login in again, we should fail.
|
|
242
|
+
post :login, :user => { :login => "deletebob1", :password => "alongtest" }
|
|
243
|
+
assert_nil session[:user]
|
|
244
|
+
#assert_template_has "login"
|
|
245
|
+
assert(@response.has_template_object?("login"))
|
|
246
|
+
|
|
247
|
+
# Now try delayed delete
|
|
248
|
+
ActionMailer::Base.deliveries = []
|
|
249
|
+
|
|
250
|
+
post :login, :user => { :login => "deletebob2", :password => "alongtest" }
|
|
251
|
+
assert(@response.has_session_object?(:user))
|
|
252
|
+
|
|
253
|
+
LoginEngine.config :delayed_delete, true, :force
|
|
254
|
+
post :delete
|
|
255
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
256
|
+
mail = ActionMailer::Base.deliveries[0]
|
|
257
|
+
user_id = /user_id=(\d+)/.match(mail.encoded)[1]
|
|
258
|
+
key = /key=([a-z0-9]+)/.match(mail.encoded)[1]
|
|
259
|
+
|
|
260
|
+
post :restore_deleted, :user_id => "#{user_id}", "key" => "badkey"
|
|
261
|
+
assert_nil session[:user]
|
|
262
|
+
|
|
263
|
+
# Advance the time past the delete date
|
|
264
|
+
Time.advance_by_days = LoginEngine.config :delayed_delete_days
|
|
265
|
+
post :restore_deleted, :user_id => "#{user_id}", "key" => "#{key}"
|
|
266
|
+
assert_nil session[:user]
|
|
267
|
+
Time.advance_by_days = 0
|
|
268
|
+
|
|
269
|
+
post :restore_deleted, :user_id => "#{user_id}", "key" => "#{key}"
|
|
270
|
+
assert(@response.has_session_object?(:user))
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def test_delete_without_email
|
|
274
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
|
275
|
+
ActionMailer::Base.deliveries = []
|
|
276
|
+
|
|
277
|
+
# Immediate delete
|
|
278
|
+
post :login, :user => { :login => "deletebob1", :password => "alongtest" }
|
|
279
|
+
assert(@response.has_session_object?(:user))
|
|
280
|
+
|
|
281
|
+
LoginEngine.config :delayed_delete, false, :force
|
|
282
|
+
post :delete
|
|
283
|
+
assert_nil session[:user]
|
|
284
|
+
assert_nil User.find_by_login("deletebob1")
|
|
285
|
+
|
|
286
|
+
# try and login in again, we should fail.
|
|
287
|
+
post :login, :user => { :login => "deletebob1", :password => "alongtest" }
|
|
288
|
+
assert_nil session[:user]
|
|
289
|
+
#assert_template_has "login"
|
|
290
|
+
assert(@response.has_template_object?("login"))
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
# Now try delayed delete
|
|
294
|
+
ActionMailer::Base.deliveries = []
|
|
295
|
+
|
|
296
|
+
post :login, :user => { :login => "deletebob2", :password => "alongtest" }
|
|
297
|
+
assert(@response.has_session_object?(:user))
|
|
298
|
+
|
|
299
|
+
# delayed delete is not really relevant currently without email.
|
|
300
|
+
LoginEngine.config :delayed_delete, true, :force
|
|
301
|
+
post :delete
|
|
302
|
+
assert_equal 1, User.find_by_login("deletebob2").deleted
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
#==========================================================================
|
|
308
|
+
#
|
|
309
|
+
# Change Password
|
|
310
|
+
#
|
|
311
|
+
#==========================================================================
|
|
312
|
+
|
|
313
|
+
def test_change_valid_password
|
|
314
|
+
|
|
315
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
|
316
|
+
|
|
317
|
+
ActionMailer::Base.deliveries = []
|
|
318
|
+
|
|
319
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
320
|
+
assert(@response.has_session_object?(:user))
|
|
321
|
+
|
|
322
|
+
post :change_password, :user => { :password => "changed_password", :password_confirmation => "changed_password" }
|
|
323
|
+
|
|
324
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
325
|
+
mail = ActionMailer::Base.deliveries[0]
|
|
326
|
+
assert_equal "bob@test.com", mail.to_addrs[0].to_s
|
|
327
|
+
assert_match /login:\s+\w+\n/, mail.encoded
|
|
328
|
+
assert_match /password:\s+\w+\n/, mail.encoded
|
|
329
|
+
|
|
330
|
+
post :login, :user => { :login => "bob", :password => "changed_password" }
|
|
331
|
+
assert(@response.has_session_object?(:user))
|
|
332
|
+
post :change_password, :user => { :password => "atest", :password_confirmation => "atest" }
|
|
333
|
+
get :logout
|
|
334
|
+
|
|
335
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
336
|
+
assert(@response.has_session_object?(:user))
|
|
337
|
+
|
|
338
|
+
get :logout
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
def test_change_valid_password_without_email
|
|
342
|
+
|
|
343
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
|
344
|
+
|
|
345
|
+
ActionMailer::Base.deliveries = []
|
|
346
|
+
|
|
347
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
348
|
+
assert(@response.has_session_object?(:user))
|
|
349
|
+
|
|
350
|
+
post :change_password, :user => { :password => "changed_password", :password_confirmation => "changed_password" }
|
|
351
|
+
|
|
352
|
+
assert_redirected_to :action => "change_password"
|
|
353
|
+
|
|
354
|
+
post :login, :user => { :login => "bob", :password => "changed_password" }
|
|
355
|
+
assert(@response.has_session_object?(:user))
|
|
356
|
+
post :change_password, :user => { :password => "atest", :password_confirmation => "atest" }
|
|
357
|
+
get :logout
|
|
358
|
+
|
|
359
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
360
|
+
assert(@response.has_session_object?(:user))
|
|
361
|
+
|
|
362
|
+
get :logout
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
def test_change_short_password
|
|
366
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
|
367
|
+
ActionMailer::Base.deliveries = []
|
|
368
|
+
|
|
369
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
370
|
+
assert(@response.has_session_object?(:user))
|
|
371
|
+
|
|
372
|
+
post :change_password, :user => { :password => "bad", :password_confirmation => "bad" }
|
|
373
|
+
#assert_invalid_column_on_record "user", "password"
|
|
374
|
+
assert assigns["user"].errors.invalid?("password")
|
|
375
|
+
assert_response :success
|
|
376
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
377
|
+
|
|
378
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
379
|
+
assert(@response.has_session_object?(:user))
|
|
380
|
+
|
|
381
|
+
get :logout
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def test_change_short_password_without_email
|
|
385
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
|
386
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
387
|
+
assert(@response.has_session_object?(:user))
|
|
388
|
+
|
|
389
|
+
post :change_password, :user => { :password => "bad", :password_confirmation => "bad" }
|
|
390
|
+
#assert_invalid_column_on_record "user", "password"
|
|
391
|
+
assert assigns["user"].errors.invalid?("password")
|
|
392
|
+
assert_response :success
|
|
393
|
+
|
|
394
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
395
|
+
assert(@response.has_session_object?(:user))
|
|
396
|
+
|
|
397
|
+
get :logout
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def test_change_password_with_bad_email
|
|
402
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
|
403
|
+
ActionMailer::Base.deliveries = []
|
|
404
|
+
|
|
405
|
+
# log in
|
|
406
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
407
|
+
assert(@response.has_session_object?(:user))
|
|
408
|
+
|
|
409
|
+
# change the password, but the email delivery will fail
|
|
410
|
+
ActionMailer::Base.inject_one_error = true
|
|
411
|
+
post :change_password, :user => { :password => "changed_password", :password_confirmation => "changed_password" }
|
|
412
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
413
|
+
assert_match /Password could not be changed/, flash[:warning]
|
|
414
|
+
|
|
415
|
+
# logout
|
|
416
|
+
get :logout
|
|
417
|
+
assert_nil session[:user]
|
|
418
|
+
|
|
419
|
+
# ensure we can log in with our original password
|
|
420
|
+
# TODO: WHY DOES THIS FAIL!! It looks like the transaction stuff in UserController#change_password isn't actually rolling back changes.
|
|
421
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
422
|
+
#################################################
|
|
423
|
+
# assert(@response.has_session_object?(:user)) #
|
|
424
|
+
#################################################
|
|
425
|
+
|
|
426
|
+
get :logout
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
#==========================================================================
|
|
433
|
+
#
|
|
434
|
+
# Forgot Password
|
|
435
|
+
#
|
|
436
|
+
#==========================================================================
|
|
437
|
+
|
|
438
|
+
def test_forgot_password
|
|
439
|
+
LoginEngine::CONFIG[:use_email_notification] = true
|
|
440
|
+
|
|
441
|
+
do_forgot_password(false, false, false)
|
|
442
|
+
do_forgot_password(false, false, true)
|
|
443
|
+
do_forgot_password(true, false, false)
|
|
444
|
+
do_forgot_password(false, true, false)
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
def do_forgot_password(bad_address, bad_email, logged_in)
|
|
448
|
+
ActionMailer::Base.deliveries = []
|
|
449
|
+
|
|
450
|
+
if logged_in
|
|
451
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
452
|
+
assert(@response.has_session_object?(:user))
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
@request.session['return-to'] = "/bogus/location"
|
|
456
|
+
if not bad_address and not bad_email
|
|
457
|
+
post :forgot_password, :user => { :email => "bob@test.com" }
|
|
458
|
+
password = "anewpassword"
|
|
459
|
+
if logged_in
|
|
460
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
461
|
+
assert_redirected_to :action => "change_password"
|
|
462
|
+
post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}" }
|
|
463
|
+
else
|
|
464
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
|
465
|
+
mail = ActionMailer::Base.deliveries[0]
|
|
466
|
+
assert_equal "bob@test.com", mail.to_addrs[0].to_s
|
|
467
|
+
user_id = /user_id=(\d+)/.match(mail.encoded)[1]
|
|
468
|
+
key = /key=([a-z0-9]+)/.match(mail.encoded)[1]
|
|
469
|
+
post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}"}, :user_id => "#{user_id}", :key => "#{key}"
|
|
470
|
+
assert(@response.has_session_object?(:user))
|
|
471
|
+
get :logout
|
|
472
|
+
end
|
|
473
|
+
elsif bad_address
|
|
474
|
+
post :forgot_password, :user => { :email => "bademail@test.com" }
|
|
475
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
476
|
+
elsif bad_email
|
|
477
|
+
ActionMailer::Base.inject_one_error = true
|
|
478
|
+
post :forgot_password, :user => { :email => "bob@test.com" }
|
|
479
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
|
480
|
+
else
|
|
481
|
+
# Invalid test case
|
|
482
|
+
assert false
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
if not bad_address and not bad_email
|
|
486
|
+
if logged_in
|
|
487
|
+
get :logout
|
|
488
|
+
else
|
|
489
|
+
assert_redirected_to :action => "login"
|
|
490
|
+
end
|
|
491
|
+
post :login, :user => { :login => "bob", :password => "#{password}" }
|
|
492
|
+
else
|
|
493
|
+
# Okay, make sure the database did not get changed
|
|
494
|
+
if logged_in
|
|
495
|
+
get :logout
|
|
496
|
+
end
|
|
497
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
498
|
+
end
|
|
499
|
+
|
|
500
|
+
assert(@response.has_session_object?(:user))
|
|
501
|
+
|
|
502
|
+
# Put the old settings back
|
|
503
|
+
if not bad_address and not bad_email
|
|
504
|
+
post :change_password, :user => { :password => "atest", :password_confirmation => "atest" }
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
get :logout
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
def test_forgot_password_without_email_and_logged_in
|
|
511
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
|
512
|
+
|
|
513
|
+
post :login, :user => { :login => "bob", :password => "atest" }
|
|
514
|
+
assert(@response.has_session_object?(:user))
|
|
515
|
+
|
|
516
|
+
@request.session['return-to'] = "/bogus/location"
|
|
517
|
+
post :forgot_password, :user => { :email => "bob@test.com" }
|
|
518
|
+
password = "anewpassword"
|
|
519
|
+
assert_redirected_to :action => "change_password"
|
|
520
|
+
post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}" }
|
|
521
|
+
|
|
522
|
+
get :logout
|
|
523
|
+
|
|
524
|
+
post :login, :user => { :login => "bob", :password => "#{password}" }
|
|
525
|
+
|
|
526
|
+
assert(@response.has_session_object?(:user))
|
|
527
|
+
|
|
528
|
+
get :logout
|
|
529
|
+
end
|
|
530
|
+
|
|
531
|
+
def forgot_password_without_email_and_not_logged_in
|
|
532
|
+
LoginEngine::CONFIG[:use_email_notification] = false
|
|
533
|
+
|
|
534
|
+
@request.session['return-to'] = "/bogus/location"
|
|
535
|
+
post :forgot_password, :user => { :email => "bob@test.com" }
|
|
536
|
+
password = "anewpassword"
|
|
537
|
+
|
|
538
|
+
# wothout email, you can't retrieve your forgotten password...
|
|
539
|
+
assert_match /Please contact the system admin/, flash[:message]
|
|
540
|
+
assert_nil session[:user]
|
|
541
|
+
|
|
542
|
+
assert_equal("http://#{@request.host}/bogus/location", @response.redirect_url)
|
|
543
|
+
end
|
|
544
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
ActionMailer::Base.class_eval {
|
|
2
|
+
@@inject_one_error = false
|
|
3
|
+
cattr_accessor :inject_one_error
|
|
4
|
+
|
|
5
|
+
private
|
|
6
|
+
def perform_delivery_test(mail)
|
|
7
|
+
if inject_one_error
|
|
8
|
+
ActionMailer::Base::inject_one_error = false
|
|
9
|
+
raise "Failed to send email" if raise_delivery_errors
|
|
10
|
+
else
|
|
11
|
+
deliveries << mail
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'time'
|
|
2
|
+
|
|
3
|
+
Time.class_eval {
|
|
4
|
+
if !respond_to? :now_old # somehow this is getting defined many times.
|
|
5
|
+
@@advance_by_days = 0
|
|
6
|
+
cattr_accessor :advance_by_days
|
|
7
|
+
|
|
8
|
+
class << Time
|
|
9
|
+
alias now_old now
|
|
10
|
+
def now
|
|
11
|
+
if Time.advance_by_days != 0
|
|
12
|
+
return Time.at(now_old.to_i + Time.advance_by_days * 60 * 60 * 24 + 1)
|
|
13
|
+
else
|
|
14
|
+
now_old
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
|
3
|
+
require 'test_help'
|
|
4
|
+
|
|
5
|
+
class Test::Unit::TestCase
|
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
|
10
|
+
#
|
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
|
13
|
+
#
|
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
|
17
|
+
# is recommended.
|
|
18
|
+
self.use_transactional_fixtures = true
|
|
19
|
+
|
|
20
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
|
21
|
+
# would need people(:david). If you don't want to migrate your existing
|
|
22
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
|
23
|
+
# instantiated fixtures translates to a database query per test method),
|
|
24
|
+
# then set this back to true.
|
|
25
|
+
self.use_instantiated_fixtures = false
|
|
26
|
+
|
|
27
|
+
# Add more helper methods to be used by all tests here...
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
require File.dirname(__FILE__) + '/mocks/time'
|
|
31
|
+
require File.dirname(__FILE__) + '/mocks/mail'
|