multi_auth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/README +36 -0
  2. data/app/controllers/application_controller.rb +11 -0
  3. data/app/controllers/auth/email_controller.rb +34 -0
  4. data/app/controllers/auth/open_id_controller.rb +43 -0
  5. data/app/controllers/auth_controller.rb +24 -0
  6. data/app/controllers/credentials/email_controller.rb +156 -0
  7. data/app/controllers/credentials/open_id_controller.rb +85 -0
  8. data/app/controllers/credentials_controller.rb +14 -0
  9. data/app/controllers/signup/email_controller.rb +132 -0
  10. data/app/controllers/signup/open_id_controller.rb +62 -0
  11. data/app/controllers/signup_controller.rb +8 -0
  12. data/app/helpers/application_helper.rb +5 -0
  13. data/app/models/activation_mailer.rb +114 -0
  14. data/app/models/email_credential.rb +89 -0
  15. data/app/models/email_credential_edit_form.rb +52 -0
  16. data/app/models/email_login_form.rb +24 -0
  17. data/app/models/email_password_edit_form.rb +36 -0
  18. data/app/models/open_id_credential.rb +33 -0
  19. data/app/models/open_id_login_form.rb +17 -0
  20. data/app/models/session.rb +19 -0
  21. data/app/models/user.rb +37 -0
  22. data/app/views/activation_mailer/complete_for_credential.erb +4 -0
  23. data/app/views/activation_mailer/complete_for_notice.erb +4 -0
  24. data/app/views/activation_mailer/complete_for_signup.erb +4 -0
  25. data/app/views/activation_mailer/request_for_credential.erb +11 -0
  26. data/app/views/activation_mailer/request_for_notice.erb +11 -0
  27. data/app/views/activation_mailer/request_for_signup.erb +11 -0
  28. data/app/views/auth/email/index.html.erb +90 -0
  29. data/app/views/auth/logged_in.html.erb +21 -0
  30. data/app/views/auth/logged_out.html.erb +21 -0
  31. data/app/views/auth/open_id/index.html.erb +16 -0
  32. data/app/views/credentials/email/activated.html.erb +4 -0
  33. data/app/views/credentials/email/activation.html.erb +15 -0
  34. data/app/views/credentials/email/created.html.erb +15 -0
  35. data/app/views/credentials/email/delete.html.erb +20 -0
  36. data/app/views/credentials/email/edit_password.html.erb +31 -0
  37. data/app/views/credentials/email/new.html.erb +36 -0
  38. data/app/views/credentials/index.html.erb +88 -0
  39. data/app/views/credentials/open_id/delete.html.erb +20 -0
  40. data/app/views/credentials/open_id/new.html.erb +26 -0
  41. data/app/views/signup/email/_progress.html.erb +14 -0
  42. data/app/views/signup/email/activated.html.erb +9 -0
  43. data/app/views/signup/email/activation.html.erb +27 -0
  44. data/app/views/signup/email/created.html.erb +14 -0
  45. data/app/views/signup/email/index.html.erb +34 -0
  46. data/app/views/signup/email/validated.html.erb +21 -0
  47. data/app/views/signup/index.html.erb +51 -0
  48. data/app/views/signup/open_id/authenticated.html.erb +15 -0
  49. data/app/views/signup/open_id/created.html.erb +6 -0
  50. data/app/views/signup/open_id/index.html.erb +16 -0
  51. data/config/boot.rb +110 -0
  52. data/config/database.yml +22 -0
  53. data/config/database.yml.sqlite3 +22 -0
  54. data/config/environment.rb +62 -0
  55. data/config/routes.rb +51 -0
  56. data/config/smtp.yml.example +8 -0
  57. data/db/development.sqlite3 +0 -0
  58. data/db/schema.rb +88 -0
  59. data/db/test.sqlite3 +0 -0
  60. data/lib/action_mailer_util.rb +15 -0
  61. data/lib/multi_auth.rb +64 -0
  62. data/lib/multi_auth_helper.rb +98 -0
  63. data/lib/notice_formatter.rb +106 -0
  64. data/lib/open_id_authentication/result.rb +12 -0
  65. data/lib/token_util.rb +18 -0
  66. data/public/404.html +92 -0
  67. data/public/422.html +91 -0
  68. data/public/500.html +92 -0
  69. data/public/503.html +92 -0
  70. data/public/favicon.ico +0 -0
  71. data/public/images/battery/cell.png +0 -0
  72. data/public/images/battery/level-green.png +0 -0
  73. data/public/images/battery/level-orange.png +0 -0
  74. data/public/images/battery/level-red.png +0 -0
  75. data/public/images/battery/level-yellow.png +0 -0
  76. data/public/images/battery/style.html +82 -0
  77. data/public/images/favicons/livedoor.png +0 -0
  78. data/public/images/favicons/mixi.png +0 -0
  79. data/public/images/favicons/yahoo.png +0 -0
  80. data/public/images/h1-back.png +0 -0
  81. data/public/images/icons/fam/add.png +0 -0
  82. data/public/images/icons/fam/bin.png +0 -0
  83. data/public/images/icons/fam/bomb.png +0 -0
  84. data/public/images/icons/fam/cog.png +0 -0
  85. data/public/images/icons/fam/delete.png +0 -0
  86. data/public/images/icons/fam/email-with-desc.png +0 -0
  87. data/public/images/icons/fam/email.png +0 -0
  88. data/public/images/icons/fam/feed.png +0 -0
  89. data/public/images/icons/fam/help.png +0 -0
  90. data/public/images/icons/fam/key-with-desc.png +0 -0
  91. data/public/images/icons/fam/key.png +0 -0
  92. data/public/images/icons/fam/lightning.png +0 -0
  93. data/public/images/icons/fam/plugin.png +0 -0
  94. data/public/images/icons/fam/stop.png +0 -0
  95. data/public/images/icons/fam/table_save.png +0 -0
  96. data/public/images/icons/fam/tick.png +0 -0
  97. data/public/images/icons/fam/user.png +0 -0
  98. data/public/images/icons/fam/vcard.png +0 -0
  99. data/public/images/icons/openid-with-desc.png +0 -0
  100. data/public/images/icons/openid.png +0 -0
  101. data/public/images/logo-back.png +0 -0
  102. data/public/images/logo.png +0 -0
  103. data/public/images/side-column-back.png +0 -0
  104. data/public/javascripts/application.js +2 -0
  105. data/public/javascripts/controls.js +963 -0
  106. data/public/javascripts/dragdrop.js +973 -0
  107. data/public/javascripts/effects.js +1128 -0
  108. data/public/javascripts/prototype.js +4320 -0
  109. data/public/robots.txt +5 -0
  110. data/public/stylesheets/application.css +365 -0
  111. data/public/stylesheets/auth.css +22 -0
  112. data/public/stylesheets/home.css +114 -0
  113. data/rails/init.rb +24 -0
  114. data/test/functional/auth/email_controller_test.rb +102 -0
  115. data/test/functional/auth/open_id_controller_test.rb +76 -0
  116. data/test/functional/auth_controller_test.rb +74 -0
  117. data/test/functional/credentials/email_controller_test.rb +488 -0
  118. data/test/functional/credentials/open_id_controller_test.rb +308 -0
  119. data/test/functional/credentials_controller_test.rb +49 -0
  120. data/test/functional/signup/email_controller_test.rb +369 -0
  121. data/test/functional/signup/open_id_controller_test.rb +44 -0
  122. data/test/functional/signup_controller_test.rb +17 -0
  123. data/test/performance/browsing_test.rb +9 -0
  124. data/test/test_helper.rb +82 -0
  125. data/test/unit/action_mailer_util_test.rb +63 -0
  126. data/test/unit/activation_mailer_test.rb +181 -0
  127. data/test/unit/email_credential_edit_form_test.rb +173 -0
  128. data/test/unit/email_credential_test.rb +324 -0
  129. data/test/unit/email_login_form_test.rb +76 -0
  130. data/test/unit/email_password_edit_form_test.rb +117 -0
  131. data/test/unit/helpers/auth_helper_test.rb +4 -0
  132. data/test/unit/helpers/credentials/email_helper_test.rb +4 -0
  133. data/test/unit/helpers/credentials/open_id_helper_test.rb +4 -0
  134. data/test/unit/helpers/credentials_helper_test.rb +4 -0
  135. data/test/unit/helpers/email_auth_helper_test.rb +4 -0
  136. data/test/unit/helpers/email_signup_helper_test.rb +4 -0
  137. data/test/unit/helpers/open_id_auth_helper_test.rb +4 -0
  138. data/test/unit/helpers/open_id_signup_helper_test.rb +4 -0
  139. data/test/unit/helpers/password_auth_helper_test.rb +4 -0
  140. data/test/unit/helpers/password_signup_helper_test.rb +4 -0
  141. data/test/unit/helpers/signup_helper_test.rb +4 -0
  142. data/test/unit/notice_formatter_test.rb +153 -0
  143. data/test/unit/open_id_credential_test.rb +108 -0
  144. data/test/unit/open_id_login_form_test.rb +57 -0
  145. data/test/unit/session_test.rb +53 -0
  146. data/test/unit/token_util_test.rb +51 -0
  147. data/test/unit/user_test.rb +177 -0
  148. metadata +220 -0
@@ -0,0 +1,369 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'test_helper'
4
+
5
+ class Signup::EmailControllerTest < ActionController::TestCase
6
+ def setup
7
+ @yuya_gmail = email_credentials(:yuya_gmail)
8
+ @yuya_nayutaya = email_credentials(:yuya_nayutaya)
9
+
10
+ @signup_form = EmailCredentialEditForm.new(
11
+ :email => "foo@example.com",
12
+ :password => "password",
13
+ :password_confirmation => "password")
14
+
15
+ ActionMailer::Base.deliveries = []
16
+ end
17
+
18
+ test "routes" do
19
+ base = {:controller => "signup/email"}
20
+
21
+ assert_routing("/signup/email", base.merge(:action => "index"))
22
+ assert_routing("/signup/email/validate", base.merge(:action => "validate"))
23
+ assert_routing("/signup/email/validated", base.merge(:action => "validated"))
24
+ assert_routing("/signup/email/create", base.merge(:action => "create"))
25
+ assert_routing("/signup/email/created", base.merge(:action => "created"))
26
+ assert_routing("/signup/email/activation/0123456789abcdef", base.merge(:action => "activation", :activation_token => "0123456789abcdef"))
27
+ assert_routing("/signup/email/activate", base.merge(:action => "activate"))
28
+ assert_routing("/signup/email/activated", base.merge(:action => "activated"))
29
+ end
30
+
31
+ test "GET index" do
32
+ get :index
33
+
34
+ assert_response(:success)
35
+ assert_template("index")
36
+ assert_flash_empty
37
+
38
+ assert_equal(
39
+ EmailCredentialEditForm.new.attributes,
40
+ assigns(:signup_form).attributes)
41
+ end
42
+
43
+ test "GET index, clean session" do
44
+ @request.session[:user_id] = :dummy
45
+ @request.session[:signup_form] = :dummy
46
+
47
+ get :index
48
+
49
+ assert_response(:success)
50
+ assert_template("index")
51
+
52
+ assert_equal(nil, @request.session[:user_id])
53
+ assert_equal(nil, @request.session[:signup_form])
54
+ end
55
+
56
+ test "POST validate" do
57
+ assert_equal(true, @signup_form.valid?)
58
+
59
+ post :validate, :signup_form => @signup_form.attributes
60
+
61
+ assert_response(:redirect)
62
+ assert_redirected_to(:controller => "email", :action => "validated")
63
+ assert_flash_empty
64
+
65
+ assert_equal(
66
+ @signup_form.attributes,
67
+ assigns(:signup_form).attributes)
68
+
69
+ assert_equal(
70
+ @signup_form.attributes,
71
+ @request.session[:signup_form])
72
+ end
73
+
74
+ test "POST validate, invalid form" do
75
+ @request.session[:signup_form] = :dummy
76
+
77
+ @signup_form.email = nil
78
+ assert_equal(false, @signup_form.valid?)
79
+
80
+ post :validate, :signup_form => @signup_form.attributes
81
+
82
+ assert_response(:success)
83
+ assert_template("index")
84
+ assert_flash_error
85
+
86
+ assert_equal(nil, @request.session[:signup_form])
87
+
88
+ assert_equal(nil, assigns(:signup_form).password)
89
+ assert_equal(nil, assigns(:signup_form).password_confirmation)
90
+ end
91
+
92
+ test "POST validate, clean session" do
93
+ @request.session[:user_id] = :dummy
94
+ @request.session[:signup_form] = :dummy
95
+
96
+ post :validate, :signup_form => @signup_form.attributes
97
+
98
+ assert_response(:redirect)
99
+ assert_redirected_to(:controller => "email", :action => "validated")
100
+
101
+ assert_equal(nil, @request.session[:user_id])
102
+ end
103
+
104
+ test "GET validate, abnormal, method not allowed" do
105
+ get :validate
106
+
107
+ assert_response(405)
108
+ assert_template(nil)
109
+ end
110
+
111
+ test "GET validated" do
112
+ assert_equal(true, @signup_form.valid?)
113
+
114
+ @request.session[:signup_form] = @signup_form.attributes
115
+
116
+ get :validated
117
+
118
+ assert_response(:success)
119
+ assert_template("validated")
120
+ assert_flash_empty
121
+
122
+ assert_equal(
123
+ @signup_form.attributes,
124
+ assigns(:signup_form).attributes)
125
+ end
126
+
127
+ test "GET validated, invalid form" do
128
+ @signup_form.email = nil
129
+ assert_equal(false, @signup_form.valid?)
130
+
131
+ get :validated
132
+
133
+ assert_response(:success)
134
+ assert_template("index")
135
+ assert_flash_error
136
+ end
137
+
138
+ test "GET validated, clean session" do
139
+ @request.session[:user_id] = :dummy
140
+ @request.session[:signup_form] = @signup_form.attributes
141
+
142
+ get :validated
143
+
144
+ assert_response(:success)
145
+ assert_template("validated")
146
+
147
+ assert_equal(nil, @request.session[:user_id])
148
+ end
149
+
150
+ test "POST create" do
151
+ assert_equal(true, @signup_form.valid?)
152
+
153
+ @request.session[:signup_form] = @signup_form.attributes
154
+
155
+ assert_difference("EmailCredential.count", +1) {
156
+ assert_difference("User.count", +1) {
157
+ post :create
158
+ }
159
+ }
160
+
161
+ assert_response(:redirect)
162
+ assert_redirected_to(:controller => "email", :action => "created")
163
+ assert_flash_empty
164
+
165
+ assert_equal(
166
+ @signup_form.attributes,
167
+ assigns(:signup_form).attributes)
168
+
169
+ assert_equal(nil, assigns(:user).nickname)
170
+
171
+ assert_equal(
172
+ assigns(:user).id,
173
+ assigns(:credential).user_id)
174
+ assert_equal(
175
+ @signup_form.email,
176
+ assigns(:credential).email)
177
+ assert_equal(
178
+ true,
179
+ EmailCredential.compare_hashed_password(@signup_form.password, assigns(:credential).hashed_password))
180
+
181
+ # MEMO: ここではurl_forが使えない
182
+ assert_equal(
183
+ root_path(:only_path => false) + "signup/email/activation/" + assigns(:credential).activation_token,
184
+ assigns(:activation_url))
185
+
186
+ assert_equal(1, ActionMailer::Base.deliveries.size)
187
+ end
188
+
189
+ test "POST create, invalid form" do
190
+ @signup_form.email = nil
191
+ assert_equal(false, @signup_form.valid?)
192
+
193
+ @request.session[:signup_form] = @signup_form.attributes
194
+
195
+ post :create
196
+
197
+ assert_response(:success)
198
+ assert_template("index")
199
+ assert_flash_error
200
+ end
201
+
202
+ test "POST create, clean session" do
203
+ @request.session[:user_id] = :dummy
204
+ @request.session[:signup_form] = @signup_form.attributes
205
+
206
+ post :create
207
+
208
+ assert_response(:redirect)
209
+ assert_redirected_to(:controller => "email", :action => "created")
210
+
211
+ assert_equal(nil, @request.session[:user_id])
212
+ end
213
+
214
+ test "GET create, abnormal, method not allowed" do
215
+ get :create
216
+
217
+ assert_response(405)
218
+ assert_template(nil)
219
+ end
220
+
221
+ test "GET created" do
222
+ @signup_form.email = @yuya_nayutaya.email
223
+ @request.session[:signup_form] = @signup_form.attributes
224
+
225
+ get :created
226
+
227
+ assert_response(:success)
228
+ assert_template("created")
229
+ assert_flash_empty
230
+
231
+ assert_equal(
232
+ @signup_form.attributes,
233
+ assigns(:signup_form).attributes)
234
+ assert_equal(
235
+ @signup_form.email,
236
+ assigns(:credential).email)
237
+ end
238
+
239
+ test "GET created, clean session" do
240
+ @request.session[:user_id] = :dummy
241
+ @request.session[:signup_form] = {:email => @yuya_nayutaya.email}
242
+
243
+ get :created
244
+
245
+ assert_response(:success)
246
+ assert_template("created")
247
+
248
+ assert_equal(nil, @request.session[:user_id])
249
+ end
250
+
251
+ test "GET activation" do
252
+ get :activation, :activation_token => @yuya_nayutaya.activation_token
253
+
254
+ assert_response(:success)
255
+ assert_template("activation")
256
+ assert_flash_empty
257
+
258
+ assert_equal(@yuya_nayutaya, assigns(:credential))
259
+ assert_equal(false, assigns(:activated))
260
+ end
261
+
262
+ test "GET activation, already activated" do
263
+ get :activation, :activation_token => @yuya_gmail.activation_token
264
+
265
+ assert_response(:success)
266
+ assert_template("activation")
267
+ assert_flash_empty
268
+
269
+ assert_equal(@yuya_gmail, assigns(:credential))
270
+ assert_equal(true, assigns(:activated))
271
+ end
272
+
273
+ test "GET activation, clean session" do
274
+ @request.session[:user_id] = :dummy
275
+ @request.session[:signup_form] = :dummy
276
+
277
+ get :activation, :activation_token => @yuya_nayutaya.activation_token
278
+
279
+ assert_response(:success)
280
+ assert_template("activation")
281
+
282
+ assert_equal(nil, @request.session[:user_id])
283
+ assert_equal(nil, @request.session[:signup_form])
284
+ end
285
+
286
+ test "GET activation, abnormal, invalid activation token" do
287
+ get :activation, :activation_token => "0"
288
+
289
+ assert_response(:success)
290
+ assert_template("activation")
291
+ assert_flash_empty
292
+
293
+ assert_equal(nil, assigns(:credential))
294
+ assert_equal(nil, assigns(:activated))
295
+ end
296
+
297
+ test "POST activate" do
298
+ time = Time.local(2010, 1, 1)
299
+
300
+ Kagemusha::DateTime.at(time) {
301
+ post :activate, :activation_token => @yuya_nayutaya.activation_token
302
+ }
303
+
304
+ assert_response(:redirect)
305
+ assert_redirected_to(:controller => "email", :action => "activated")
306
+ assert_flash_empty
307
+
308
+ assigns(:credential).reload
309
+ assert_equal(@yuya_nayutaya.email, assigns(:credential).email)
310
+ assert_equal(time, assigns(:credential).activated_at)
311
+ end
312
+
313
+ test "POST activate, already activated" do
314
+ post :activate, :activation_token => @yuya_gmail.activation_token
315
+
316
+ assert_response(:redirect)
317
+ assert_redirected_to(root_path)
318
+ assert_flash_error
319
+ end
320
+
321
+ test "POST activate, clean session" do
322
+ @request.session[:user_id] = :dummy
323
+ @request.session[:signup_form] = :dummy
324
+
325
+ post :activate, :activation_token => @yuya_nayutaya.activation_token
326
+
327
+ assert_response(:redirect)
328
+ assert_redirected_to(:controller => "email", :action => "activated")
329
+
330
+ assert_equal(nil, @request.session[:user_id])
331
+ assert_equal(nil, @request.session[:signup_form])
332
+ end
333
+
334
+ test "POST activated, abnormal, no activation token" do
335
+ post :activate, :activation_token => nil
336
+
337
+ assert_response(:redirect)
338
+ assert_redirected_to(root_path)
339
+ assert_flash_error
340
+ end
341
+
342
+ test "GET activate, abnormal, method not allowed" do
343
+ get :activate
344
+
345
+ assert_response(405)
346
+ assert_template(nil)
347
+ end
348
+
349
+ test "GET activated" do
350
+ get :activated
351
+
352
+ assert_response(:success)
353
+ assert_template("activated")
354
+ assert_flash_empty
355
+ end
356
+
357
+ test "GET activated, clean session" do
358
+ @request.session[:user_id] = :dummy
359
+ @request.session[:signup_form] = :dummy
360
+
361
+ get :activated
362
+
363
+ assert_response(:success)
364
+ assert_template("activated")
365
+
366
+ assert_equal(nil, @request.session[:user_id])
367
+ assert_equal(nil, @request.session[:signup_form])
368
+ end
369
+ end
@@ -0,0 +1,44 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'test_helper'
4
+
5
+ class Signup::OpenIdControllerTest < ActionController::TestCase
6
+ test "routes" do
7
+ base = {:controller => "signup/open_id"}
8
+
9
+ assert_routing("signup/open_id", base.merge(:action => "index"))
10
+ assert_routing("signup/open_id/authenticate", base.merge(:action => "authenticate"))
11
+ assert_routing("signup/open_id/authenticated", base.merge(:action => "authenticated"))
12
+ assert_routing("signup/open_id/create", base.merge(:action => "create"))
13
+ assert_routing("signup/open_id/created", base.merge(:action => "created"))
14
+ end
15
+
16
+ test "GET index" do
17
+ get :index
18
+
19
+ assert_response(:success)
20
+ assert_template("index")
21
+ end
22
+
23
+ test "POST authenticate, first step" do
24
+ post :authenticate, :openid_url => "livedoor.com"
25
+
26
+ assert_response(:redirect)
27
+ # FXIME 検証を追加する?
28
+ # FIXME 毎回リクエストが外に飛んでいるのをなんとかする
29
+ end
30
+
31
+ test "GET authenticate, second step" do
32
+ get :authenticate, :openid_url => nil
33
+ # TODO: 必要があれば検証を追加する
34
+ end
35
+
36
+ test "POST create" do
37
+ @request.session[:identity_url] = "http://example.com/"
38
+
39
+ post :create
40
+
41
+ assert_response(:redirect)
42
+ assert_redirected_to(:action => "created")
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+
2
+ require 'test_helper'
3
+
4
+ class SignupControllerTest < ActionController::TestCase
5
+ test "routes" do
6
+ base = {:controller => "signup"}
7
+
8
+ assert_routing("/signup", base.merge(:action => "index"))
9
+ end
10
+
11
+ test "GET index" do
12
+ get :index
13
+
14
+ assert_response(:success)
15
+ assert_template("index")
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,82 @@
1
+
2
+ ENV["RAILS_ENV"] = "test"
3
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
4
+ require 'test_help'
5
+
6
+ require "kagemusha/datetime"
7
+
8
+ begin
9
+ require 'redgreen'
10
+ rescue LoadError
11
+ # do nothing
12
+ end
13
+
14
+ class ActiveSupport::TestCase
15
+ # Transactional fixtures accelerate your tests by wrapping each test method
16
+ # in a transaction that's rolled back on completion. This ensures that the
17
+ # test database remains unchanged so your fixtures don't have to be reloaded
18
+ # between every test method. Fewer database queries means faster tests.
19
+ #
20
+ # Read Mike Clark's excellent walkthrough at
21
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
22
+ #
23
+ # Every Active Record database supports transactions except MyISAM tables
24
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
25
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
26
+ # is recommended.
27
+ #
28
+ # The only drawback to using transactional fixtures is when you actually
29
+ # need to test transactions. Since your test is bracketed by a transaction,
30
+ # any transactions started in your code will be automatically rolled back.
31
+ self.use_transactional_fixtures = true
32
+
33
+ # Instantiated fixtures are slow, but give you @david where otherwise you
34
+ # would need people(:david). If you don't want to migrate your existing
35
+ # test cases which use the @david style and don't mind the speed hit (each
36
+ # instantiated fixtures translates to a database query per test method),
37
+ # then set this back to true.
38
+ self.use_instantiated_fixtures = false
39
+
40
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
41
+ #
42
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
43
+ # -- they do not yet inherit this setting
44
+ fixtures :all
45
+
46
+ # Add more helper methods to be used by all tests here...
47
+
48
+ private
49
+
50
+ def assert_logged_in(user)
51
+ assert_equal(user.id, @request.session[:user_id])
52
+ assert_equal(user, assigns(:login_user))
53
+ end
54
+
55
+ def assert_not_logged_in
56
+ assert_equal(nil, @request.session[:user_id])
57
+ assert_equal(nil, assigns(:login_user))
58
+ end
59
+
60
+ def session_login(user)
61
+ @request.session[:user_id] = user.id
62
+ end
63
+
64
+ def session_logout
65
+ @request.session[:user_id] = nil
66
+ end
67
+
68
+ def assert_flash_empty
69
+ assert_nil(assigns(:flash_notice))
70
+ assert_nil(assigns(:flash_error))
71
+ end
72
+
73
+ def assert_flash_notice
74
+ assert_not_nil(assigns(:flash_notice))
75
+ assert_nil(assigns(:flash_error))
76
+ end
77
+
78
+ def assert_flash_error
79
+ assert_nil(assigns(:flash_notice))
80
+ assert_not_nil(assigns(:flash_error))
81
+ end
82
+ end
@@ -0,0 +1,63 @@
1
+
2
+ require 'test_helper'
3
+
4
+ class ActionMailerUtilTest < ActiveSupport::TestCase
5
+ def setup
6
+ @module = ActionMailerUtil
7
+ @instance = Class.new.module_eval { include(ActionMailerUtil); self }.new
8
+ @musha = Kagemusha.new(@instance.class)
9
+ end
10
+
11
+ test "build_message" do
12
+ time = Time.local(2010, 1, 1)
13
+ options = {
14
+ :subject => "SUBJECT",
15
+ :from => "FROM",
16
+ :recipients => "RECIPIENTS",
17
+ :body => {:KEY => :VALUE},
18
+ }
19
+
20
+ called = []
21
+ @musha.def(:sent_on) { |value| called << [:sent_on, value] }
22
+ @musha.def(:subject) { |value| called << [:subject, value] }
23
+ @musha.def(:from) { |value| called << [:from, value] }
24
+ @musha.def(:recipients) { |value| called << [:recipients, value] }
25
+ @musha.def(:body) { |value| called << [:body, value] }
26
+ @musha.swap {
27
+ Kagemusha::DateTime.at(time) {
28
+ assert_equal(nil, @instance.__send__(:build_message, options))
29
+ }
30
+ }
31
+
32
+ expected = [
33
+ [:sent_on, time],
34
+ [:subject, "SUBJECT"],
35
+ [:from, "FROM"],
36
+ [:recipients, "RECIPIENTS"],
37
+ [:body, {:KEY => :VALUE}],
38
+ ]
39
+ assert_equal(expected, called)
40
+ end
41
+
42
+ test "build_message, deficient parameter" do
43
+ options = {
44
+ :subject => "SUBJECT",
45
+ :from => "FROM",
46
+ :recipients => "RECIPIENTS",
47
+ :body => {:KEY => :VALUE},
48
+ }
49
+
50
+ @musha.def(:sent_on) { }
51
+ @musha.def(:subject) { }
52
+ @musha.def(:from) { }
53
+ @musha.def(:recipients) { }
54
+ @musha.def(:body) { }
55
+ @musha.swap {
56
+ assert_nothing_raised { @instance.__send__(:build_message, options) }
57
+ assert_raise(ArgumentError) { @instance.__send__(:build_message, options.merge(:subject => nil)) }
58
+ assert_raise(ArgumentError) { @instance.__send__(:build_message, options.merge(:from => nil)) }
59
+ assert_raise(ArgumentError) { @instance.__send__(:build_message, options.merge(:recipients => nil)) }
60
+ assert_raise(ArgumentError) { @instance.__send__(:build_message, options.merge(:body => nil)) }
61
+ }
62
+ end
63
+ end