3 class UserCreationTest < ActionDispatch::IntegrationTest
9 OmniAuth.config.test_mode = true
11 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
17 OmniAuth.config.mock_auth[:openid] = nil
18 OmniAuth.config.mock_auth[:google] = nil
19 OmniAuth.config.mock_auth[:facebook] = nil
20 OmniAuth.config.mock_auth[:windowslive] = nil
21 OmniAuth.config.mock_auth[:github] = nil
22 OmniAuth.config.mock_auth[:wikipedia] = nil
23 OmniAuth.config.test_mode = false
26 def test_create_user_form
27 I18n.available_locales.each do |locale|
28 get_via_redirect "/user/new", {}, { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
29 assert_response :success
30 assert_template "user/new"
34 def test_user_create_submit_duplicate_email
35 I18n.available_locales.each do |locale|
36 dup_email = users(:public_user).email
37 display_name = "#{locale}_new_tester"
38 assert_difference("User.count", 0) do
39 assert_difference("ActionMailer::Base.deliveries.size", 0) do
41 { :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
42 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
45 assert_response :success
46 assert_template "user/new"
47 assert_equal locale.to_s, response.headers["Content-Language"] unless locale == :root
48 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
49 assert_no_missing_translations
53 def test_user_create_submit_duplicate_username
54 I18n.available_locales.each do |locale|
55 dup_display_name = users(:public_user).display_name
56 email = "#{locale}_new_tester"
57 assert_difference("User.count", 0) do
58 assert_difference("ActionMailer::Base.deliveries.size", 0) do
60 { :user => { :email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
61 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
64 assert_response :success
65 assert_template "user/new"
66 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
67 assert_no_missing_translations
71 def test_user_create_success
72 I18n.available_locales.each do |locale|
73 new_email = "#{locale}newtester@osm.org"
74 display_name = "#{locale}_new_tester"
76 assert_difference("User.count", 0) do
77 assert_difference("ActionMailer::Base.deliveries.size", 0) do
79 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
83 assert_redirected_to "/user/terms"
85 assert_difference("User.count") do
86 assert_difference("ActionMailer::Base.deliveries.size", 1) do
87 post_via_redirect "/user/save", {},
88 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
93 register_email = ActionMailer::Base.deliveries.first
95 assert_equal register_email.to.first, new_email
96 # Check that the confirm account url is correct
97 assert_match /#{@url}/, register_email.body.to_s
100 assert_response :success
101 assert_template "user/confirm"
103 ActionMailer::Base.deliveries.clear
107 # Check that the user can successfully recover their password
108 def lost_password_recovery_success
109 # Open the lost password form
110 # Submit the lost password form
112 # Submit the reset password token
113 # Check that the password has changed, and the user can login
116 def test_user_create_redirect
117 new_email = "redirect_tester@osm.org"
118 display_name = "redirect_tester"
119 password = "testtest"
120 # nothing special about this page, just need a protected page to redirect back to.
121 referer = "/traces/mine"
122 assert_difference("User.count") do
123 assert_difference("ActionMailer::Base.deliveries.size", 1) do
125 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }, :referer => referer
126 assert_redirected_to "/user/terms"
127 post_via_redirect "/user/save",
128 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }
133 register_email = ActionMailer::Base.deliveries.first
135 assert_equal register_email.to.first, new_email
136 # Check that the confirm account url is correct
137 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
138 email_text_parts(register_email).each do |part|
139 assert_match confirm_regex, part.body.to_s
141 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
144 assert_response :success
145 assert_template "user/confirm"
147 ActionMailer::Base.deliveries.clear
149 # Go to the confirmation page
150 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
151 assert_response :success
152 assert_template "user/confirm"
154 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
155 assert_response :redirect
157 assert_response :success
158 assert_template "site/welcome"
161 def test_user_create_openid_success
162 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
164 new_email = "newtester-openid@osm.org"
165 display_name = "new_tester-openid"
166 password = "testtest"
167 assert_difference("User.count") do
168 assert_difference("ActionMailer::Base.deliveries.size", 1) do
170 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "", :pass_crypt_confirmation => "" }
171 assert_response :redirect
172 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
174 assert_response :redirect
175 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
177 assert_response :redirect
178 assert_redirected_to "/user/terms"
180 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => password, :pass_crypt_confirmation => password }
181 assert_response :redirect
187 assert_response :success
188 assert_template "user/confirm"
190 ActionMailer::Base.deliveries.clear
193 def test_user_create_openid_failure
194 OmniAuth.config.mock_auth[:openid] = :connection_failed
196 new_email = "newtester-openid2@osm.org"
197 display_name = "new_tester-openid2"
198 assert_difference("User.count", 0) do
199 assert_difference("ActionMailer::Base.deliveries.size", 0) do
201 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "", :pass_crypt_confirmation => "" }
202 assert_response :redirect
203 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
205 assert_response :redirect
206 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
208 assert_response :redirect
209 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
211 assert_response :redirect
213 assert_response :success
214 assert_template "user/new"
218 ActionMailer::Base.deliveries.clear
221 def test_user_create_openid_redirect
222 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
224 new_email = "redirect_tester_openid@osm.org"
225 display_name = "redirect_tester_openid"
226 # nothing special about this page, just need a protected page to redirect back to.
227 referer = "/traces/mine"
228 assert_difference("User.count") do
229 assert_difference("ActionMailer::Base.deliveries.size", 1) do
231 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
232 assert_response :redirect
233 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
235 assert_response :redirect
236 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
238 assert_response :redirect
239 assert_redirected_to "/user/terms"
240 post_via_redirect "/user/save",
241 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
246 register_email = ActionMailer::Base.deliveries.first
248 assert_equal register_email.to.first, new_email
249 # Check that the confirm account url is correct
250 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
251 email_text_parts(register_email).each do |part|
252 assert_match confirm_regex, part.body.to_s
254 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
257 assert_response :success
258 assert_template "user/confirm"
260 ActionMailer::Base.deliveries.clear
262 # Go to the confirmation page
263 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
264 assert_response :success
265 assert_template "user/confirm"
267 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
268 assert_response :redirect
270 assert_response :success
271 assert_template "site/welcome"
274 def test_user_create_google_success
275 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
276 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
279 new_email = "newtester-google@osm.org"
280 display_name = "new_tester-google"
281 password = "testtest"
282 assert_difference("User.count") do
283 assert_difference("ActionMailer::Base.deliveries.size", 1) do
285 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }
286 assert_response :redirect
287 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
289 assert_response :redirect
290 assert_redirected_to auth_success_path(:provider => "google")
292 assert_response :redirect
293 assert_redirected_to "/user/terms"
295 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }
296 assert_response :redirect
302 assert_response :success
303 assert_template "user/confirm"
305 ActionMailer::Base.deliveries.clear
308 def test_user_create_google_failure
309 OmniAuth.config.mock_auth[:google] = :connection_failed
311 new_email = "newtester-google2@osm.org"
312 display_name = "new_tester-google2"
313 assert_difference("User.count", 0) do
314 assert_difference("ActionMailer::Base.deliveries.size", 0) do
316 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }
317 assert_response :redirect
318 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
320 assert_response :redirect
321 assert_redirected_to auth_success_path(:provider => "google")
323 assert_response :redirect
324 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
326 assert_response :redirect
328 assert_response :success
329 assert_template "user/new"
333 ActionMailer::Base.deliveries.clear
336 def test_user_create_google_redirect
337 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
338 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
341 new_email = "redirect_tester_google@osm.org"
342 display_name = "redirect_tester_google"
343 # nothing special about this page, just need a protected page to redirect back to.
344 referer = "/traces/mine"
345 assert_difference("User.count") do
346 assert_difference("ActionMailer::Base.deliveries.size", 1) do
348 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
349 assert_response :redirect
350 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
352 assert_response :redirect
353 assert_redirected_to auth_success_path(:provider => "google")
355 assert_response :redirect
356 assert_redirected_to "/user/terms"
357 post_via_redirect "/user/save",
358 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
363 register_email = ActionMailer::Base.deliveries.first
365 assert_equal register_email.to.first, new_email
366 # Check that the confirm account url is correct
367 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
368 email_text_parts(register_email).each do |part|
369 assert_match confirm_regex, part.body.to_s
371 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
374 assert_response :success
375 assert_template "user/confirm"
377 ActionMailer::Base.deliveries.clear
379 # Go to the confirmation page
380 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
381 assert_response :success
382 assert_template "user/confirm"
384 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
385 assert_response :redirect
387 assert_response :success
388 assert_template "site/welcome"
391 def test_user_create_facebook_success
392 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
394 new_email = "newtester-facebook@osm.org"
395 display_name = "new_tester-facebook"
396 password = "testtest"
397 assert_difference("User.count") do
398 assert_difference("ActionMailer::Base.deliveries.size", 1) do
400 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }
401 assert_response :redirect
402 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
404 assert_response :redirect
405 assert_redirected_to auth_success_path(:provider => "facebook")
407 assert_response :redirect
408 assert_redirected_to "/user/terms"
410 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }
411 assert_response :redirect
417 assert_response :success
418 assert_template "user/confirm"
420 ActionMailer::Base.deliveries.clear
423 def test_user_create_facebook_failure
424 OmniAuth.config.mock_auth[:facebook] = :connection_failed
426 new_email = "newtester-facebook2@osm.org"
427 display_name = "new_tester-facebook2"
428 assert_difference("User.count", 0) do
429 assert_difference("ActionMailer::Base.deliveries.size", 0) do
431 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }
432 assert_response :redirect
433 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
435 assert_response :redirect
436 assert_redirected_to auth_success_path(:provider => "facebook")
438 assert_response :redirect
439 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
441 assert_response :redirect
443 assert_response :success
444 assert_template "user/new"
448 ActionMailer::Base.deliveries.clear
451 def test_user_create_facebook_redirect
452 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
454 new_email = "redirect_tester_facebook@osm.org"
455 display_name = "redirect_tester_facebook"
456 # nothing special about this page, just need a protected page to redirect back to.
457 referer = "/traces/mine"
458 assert_difference("User.count") do
459 assert_difference("ActionMailer::Base.deliveries.size", 1) do
461 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
462 assert_response :redirect
463 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
465 assert_response :redirect
466 assert_redirected_to auth_success_path(:provider => "facebook")
468 assert_response :redirect
469 assert_redirected_to "/user/terms"
470 post_via_redirect "/user/save",
471 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
476 register_email = ActionMailer::Base.deliveries.first
478 assert_equal register_email.to.first, new_email
479 # Check that the confirm account url is correct
480 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
481 email_text_parts(register_email).each do |part|
482 assert_match confirm_regex, part.body.to_s
484 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
487 assert_response :success
488 assert_template "user/confirm"
490 ActionMailer::Base.deliveries.clear
492 # Go to the confirmation page
493 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
494 assert_response :success
495 assert_template "user/confirm"
497 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
498 assert_response :redirect
500 assert_response :success
501 assert_template "site/welcome"
504 def test_user_create_windowslive_success
505 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
507 new_email = "newtester-windowslive@osm.org"
508 display_name = "new_tester-windowslive"
509 password = "testtest"
510 assert_difference("User.count") do
511 assert_difference("ActionMailer::Base.deliveries.size", 1) do
513 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }
514 assert_response :redirect
515 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
517 assert_response :redirect
518 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/user/new")
520 assert_response :redirect
521 assert_redirected_to "/user/terms"
523 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }
524 assert_response :redirect
530 assert_response :success
531 assert_template "user/confirm"
533 ActionMailer::Base.deliveries.clear
536 def test_user_create_windowslive_failure
537 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
539 new_email = "newtester-windowslive2@osm.org"
540 display_name = "new_tester-windowslive2"
541 assert_difference("User.count", 0) do
542 assert_difference("ActionMailer::Base.deliveries.size", 0) do
544 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }
545 assert_response :redirect
546 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
548 assert_response :redirect
549 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/user/new")
551 assert_response :redirect
552 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/user/new")
554 assert_response :redirect
556 assert_response :success
557 assert_template "user/new"
561 ActionMailer::Base.deliveries.clear
564 def test_user_create_windowslive_redirect
565 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
567 new_email = "redirect_tester_windowslive@osm.org"
568 display_name = "redirect_tester_windowslive"
569 # nothing special about this page, just need a protected page to redirect back to.
570 referer = "/traces/mine"
571 assert_difference("User.count") do
572 assert_difference("ActionMailer::Base.deliveries.size", 1) do
574 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
575 assert_response :redirect
576 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
578 assert_response :redirect
579 assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/user/new")
581 assert_response :redirect
582 assert_redirected_to "/user/terms"
583 post_via_redirect "/user/save",
584 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
589 register_email = ActionMailer::Base.deliveries.first
591 assert_equal register_email.to.first, new_email
592 # Check that the confirm account url is correct
593 confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
594 email_text_parts(register_email).each do |part|
595 assert_match confirm_regex, part.body.to_s
597 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
600 assert_response :success
601 assert_template "user/confirm"
603 ActionMailer::Base.deliveries.clear
605 # Go to the confirmation page
606 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
607 assert_response :success
608 assert_template "user/confirm"
610 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
611 assert_response :redirect
613 assert_response :success
614 assert_template "site/welcome"
617 def test_user_create_github_success
618 OmniAuth.config.add_mock(:github, :uid => "123454321")
620 new_email = "newtester-github@osm.org"
621 display_name = "new_tester-github"
622 password = "testtest"
623 assert_difference("User.count") do
624 assert_difference("ActionMailer::Base.deliveries.size", 1) do
626 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" }
627 assert_response :redirect
628 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
630 assert_response :redirect
631 assert_redirected_to auth_success_path(:provider => "github", :origin => "/user/new")
633 assert_response :redirect
634 assert_redirected_to "/user/terms"
636 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }
637 assert_response :redirect
643 assert_response :success
644 assert_template "user/confirm"
646 ActionMailer::Base.deliveries.clear
649 def test_user_create_github_failure
650 OmniAuth.config.mock_auth[:github] = :connection_failed
652 new_email = "newtester-github2@osm.org"
653 display_name = "new_tester-github2"
654 assert_difference("User.count", 0) do
655 assert_difference("ActionMailer::Base.deliveries.size", 0) do
657 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" }
658 assert_response :redirect
659 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
661 assert_response :redirect
662 assert_redirected_to auth_success_path(:provider => "github", :origin => "/user/new")
664 assert_response :redirect
665 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
667 assert_response :redirect
669 assert_response :success
670 assert_template "user/new"
674 ActionMailer::Base.deliveries.clear
677 def test_user_create_github_redirect
678 OmniAuth.config.add_mock(:github, :uid => "123454321")
680 new_email = "redirect_tester_github@osm.org"
681 display_name = "redirect_tester_github"
682 # nothing special about this page, just need a protected page to redirect back to.
683 referer = "/traces/mine"
684 assert_difference("User.count") do
685 assert_difference("ActionMailer::Base.deliveries.size", 1) do
687 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
688 assert_response :redirect
689 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
691 assert_response :redirect
692 assert_redirected_to auth_success_path(:provider => "github", :origin => "/user/new")
694 assert_response :redirect
695 assert_redirected_to "/user/terms"
696 post_via_redirect "/user/save",
697 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
702 register_email = ActionMailer::Base.deliveries.first
704 assert_equal register_email.to.first, new_email
705 # Check that the confirm account url is correct
706 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
707 email_text_parts(register_email).each do |part|
708 assert_match confirm_regex, part.body.to_s
710 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
713 assert_response :success
714 assert_template "user/confirm"
716 ActionMailer::Base.deliveries.clear
718 # Go to the confirmation page
719 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
720 assert_response :success
721 assert_template "user/confirm"
723 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
724 assert_response :redirect
726 assert_response :success
727 assert_template "site/welcome"
730 def test_user_create_wikipedia_success
731 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
733 new_email = "newtester-wikipedia@osm.org"
734 display_name = "new_tester-wikipedia"
735 password = "testtest"
736 assert_difference("User.count") do
737 assert_difference("ActionMailer::Base.deliveries.size", 1) do
739 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" }
740 assert_response :redirect
741 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
743 assert_response :redirect
744 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
746 assert_response :redirect
747 assert_redirected_to "/user/terms"
749 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }
750 assert_response :redirect
756 assert_response :success
757 assert_template "user/confirm"
759 ActionMailer::Base.deliveries.clear
762 def test_user_create_wikipedia_failure
763 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
765 new_email = "newtester-wikipedia2@osm.org"
766 display_name = "new_tester-wikipedia2"
767 assert_difference("User.count", 0) do
768 assert_difference("ActionMailer::Base.deliveries.size", 0) do
770 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" }
771 assert_response :redirect
772 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
774 assert_response :redirect
775 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
777 assert_response :redirect
778 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
780 assert_response :redirect
782 assert_response :success
783 assert_template "user/new"
787 ActionMailer::Base.deliveries.clear
790 def test_user_create_wikipedia_redirect
791 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
793 new_email = "redirect_tester_wikipedia@osm.org"
794 display_name = "redirect_tester_wikipedia"
795 # nothing special about this page, just need a protected page to redirect back to.
796 referer = "/traces/mine"
797 assert_difference("User.count") do
798 assert_difference("ActionMailer::Base.deliveries.size", 1) do
800 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
801 assert_response :redirect
802 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
804 assert_response :redirect
805 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
807 assert_response :redirect
808 assert_redirected_to "/user/terms"
809 post_via_redirect "/user/save",
810 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
815 register_email = ActionMailer::Base.deliveries.first
817 assert_equal register_email.to.first, new_email
818 # Check that the confirm account url is correct
819 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
820 email_text_parts(register_email).each do |part|
821 assert_match confirm_regex, part.body.to_s
823 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
826 assert_response :success
827 assert_template "user/confirm"
829 ActionMailer::Base.deliveries.clear
831 # Go to the confirmation page
832 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
833 assert_response :success
834 assert_template "user/confirm"
836 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
837 assert_response :redirect
839 assert_response :success
840 assert_template "site/welcome"