3 class UserCreationTest < ActionDispatch::IntegrationTest
7 OmniAuth.config.test_mode = true
9 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
15 OmniAuth.config.mock_auth[:openid] = nil
16 OmniAuth.config.mock_auth[:google] = nil
17 OmniAuth.config.mock_auth[:facebook] = nil
18 OmniAuth.config.mock_auth[:windowslive] = nil
19 OmniAuth.config.mock_auth[:github] = nil
20 OmniAuth.config.mock_auth[:wikipedia] = nil
21 OmniAuth.config.test_mode = false
24 def test_create_user_form
25 I18n.available_locales.each do |locale|
27 get "/user/new", :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
29 assert_response :success
30 assert_template "users/new"
34 def test_user_create_submit_duplicate_email
35 I18n.available_locales.each do |locale|
36 dup_email = create(:user).email
37 display_name = "#{locale}_new_tester"
38 assert_difference("User.count", 0) do
39 assert_difference("ActionMailer::Base.deliveries.size", 0) do
40 perform_enqueued_jobs do
42 :params => { :user => { :email => dup_email,
43 :email_confirmation => dup_email,
44 :display_name => display_name,
45 :pass_crypt => "testtest",
46 :pass_crypt_confirmation => "testtest" } },
47 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
51 assert_response :success
52 assert_template "users/new"
53 assert_equal locale.to_s, response.headers["Content-Language"] unless locale == :root
54 assert_select "form > fieldset > div.standard-form-row > input.field_with_errors#user_email"
55 assert_no_missing_translations
59 def test_user_create_submit_duplicate_username
60 I18n.available_locales.each do |locale|
61 dup_display_name = create(:user).display_name
62 email = "#{locale}_new_tester"
63 assert_difference("User.count", 0) do
64 assert_difference("ActionMailer::Base.deliveries.size", 0) do
65 perform_enqueued_jobs do
67 :params => { :user => { :email => email,
68 :email_confirmation => email,
69 :display_name => dup_display_name,
70 :pass_crypt => "testtest",
71 :pass_crypt_confirmation => "testtest" } },
72 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
76 assert_response :success
77 assert_template "users/new"
78 assert_select "form > fieldset > div.standard-form-row > input.field_with_errors#user_display_name"
79 assert_no_missing_translations
83 def test_user_create_success
84 I18n.available_locales.each do |locale|
85 new_email = "#{locale}newtester@osm.org"
86 display_name = "#{locale}_new_tester"
88 assert_difference("User.count", 0) do
89 assert_difference("ActionMailer::Base.deliveries.size", 0) do
90 perform_enqueued_jobs do
92 :params => { :user => { :email => new_email,
93 :email_confirmation => new_email,
94 :display_name => display_name,
95 :pass_crypt => "testtest",
96 :pass_crypt_confirmation => "testtest" } }
101 assert_redirected_to "/user/terms"
103 assert_difference("User.count") do
104 assert_difference("ActionMailer::Base.deliveries.size", 1) do
105 perform_enqueued_jobs do
107 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s },
108 :params => { :read_ct => 1, :read_tou => 1 }
115 register_email = ActionMailer::Base.deliveries.first
117 assert_equal register_email.to.first, new_email
118 # Check that the confirm account url is correct
119 assert_match(/#{@url}/, register_email.body.to_s)
122 assert_response :success
123 assert_template "users/confirm"
125 ActionMailer::Base.deliveries.clear
129 def test_user_create_no_tou_failure
130 I18n.available_locales.each do |locale|
131 new_email = "#{locale}newtester@osm.org"
132 display_name = "#{locale}_new_tester"
134 assert_difference("User.count", 0) do
135 assert_difference("ActionMailer::Base.deliveries.size", 0) do
136 perform_enqueued_jobs do
138 :params => { :user => { :email => new_email,
139 :email_confirmation => new_email,
140 :display_name => display_name,
141 :pass_crypt => "testtest",
142 :pass_crypt_confirmation => "testtest" } }
147 assert_redirected_to "/user/terms"
149 perform_enqueued_jobs do
151 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
152 assert_redirected_to "/user/terms"
155 ActionMailer::Base.deliveries.clear
159 # Check that the user can successfully recover their password
160 def lost_password_recovery_success
161 # Open the lost password form
162 # Submit the lost password form
164 # Submit the reset password token
165 # Check that the password has changed, and the user can login
168 def test_user_create_redirect
169 new_email = "redirect_tester@osm.org"
170 display_name = "redirect_tester"
171 password = "testtest"
172 # nothing special about this page, just need a protected page to redirect back to.
173 referer = "/traces/mine"
174 assert_difference("User.count") do
175 assert_difference("ActionMailer::Base.deliveries.size", 1) do
176 perform_enqueued_jobs do
178 :params => { :user => { :email => new_email,
179 :email_confirmation => new_email,
180 :display_name => display_name,
181 :pass_crypt => password,
182 :pass_crypt_confirmation => password },
183 :referer => referer }
184 assert_redirected_to "/user/terms"
186 :params => { :user => { :email => new_email,
187 :email_confirmation => new_email,
188 :display_name => display_name,
189 :pass_crypt => password,
190 :pass_crypt_confirmation => password },
191 :read_ct => 1, :read_tou => 1 }
198 register_email = ActionMailer::Base.deliveries.first
200 assert_equal register_email.to.first, new_email
201 # Check that the confirm account url is correct
202 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
203 email_text_parts(register_email).each do |part|
204 assert_match confirm_regex, part.body.to_s
206 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
209 assert_response :success
210 assert_template "users/confirm"
212 ActionMailer::Base.deliveries.clear
214 # Go to the confirmation page
215 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
216 assert_response :success
217 assert_template "users/confirm"
219 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
220 assert_response :redirect
222 assert_response :success
223 assert_template "site/welcome"
226 def test_user_create_openid_success
227 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
229 new_email = "newtester-openid@osm.org"
230 display_name = "new_tester-openid"
231 password = "testtest"
232 assert_difference("User.count") do
233 assert_difference("ActionMailer::Base.deliveries.size", 1) do
234 perform_enqueued_jobs do
236 :params => { :user => { :email => new_email,
237 :email_confirmation => new_email,
238 :display_name => display_name,
239 :auth_provider => "openid",
240 :auth_uid => "http://localhost:1123/new.tester",
242 :pass_crypt_confirmation => "" } }
243 assert_response :redirect
244 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
246 assert_response :redirect
247 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
249 assert_response :redirect
250 assert_redirected_to "/user/terms"
252 :params => { :user => { :email => new_email,
253 :email_confirmation => new_email,
254 :display_name => display_name,
255 :auth_provider => "openid",
256 :auth_uid => "http://localhost:1123/new.tester",
257 :pass_crypt => password,
258 :pass_crypt_confirmation => password },
259 :read_ct => 1, :read_tou => 1 }
260 assert_response :redirect
267 assert_response :success
268 assert_template "users/confirm"
270 ActionMailer::Base.deliveries.clear
273 def test_user_create_openid_failure
274 OmniAuth.config.mock_auth[:openid] = :connection_failed
276 new_email = "newtester-openid2@osm.org"
277 display_name = "new_tester-openid2"
278 assert_difference("User.count", 0) do
279 assert_difference("ActionMailer::Base.deliveries.size", 0) do
280 perform_enqueued_jobs do
282 :params => { :user => { :email => new_email,
283 :email_confirmation => new_email,
284 :display_name => display_name,
285 :auth_provider => "openid",
286 :auth_uid => "http://localhost:1123/new.tester",
288 :pass_crypt_confirmation => "" } }
289 assert_response :redirect
290 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
292 assert_response :redirect
293 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
295 assert_response :redirect
296 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
298 assert_response :redirect
300 assert_response :success
301 assert_template "users/new"
306 ActionMailer::Base.deliveries.clear
309 def test_user_create_openid_redirect
310 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
312 new_email = "redirect_tester_openid@osm.org"
313 display_name = "redirect_tester_openid"
314 # nothing special about this page, just need a protected page to redirect back to.
315 referer = "/traces/mine"
316 assert_difference("User.count") do
317 assert_difference("ActionMailer::Base.deliveries.size", 1) do
318 perform_enqueued_jobs do
320 :params => { :user => { :email => new_email,
321 :email_confirmation => new_email,
322 :display_name => display_name,
323 :auth_provider => "openid",
324 :auth_uid => "http://localhost:1123/new.tester",
326 :pass_crypt_confirmation => "" },
327 :referer => referer }
328 assert_response :redirect
329 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
331 assert_response :redirect
332 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
334 assert_response :redirect
335 assert_redirected_to "/user/terms"
337 :params => { :user => { :email => new_email,
338 :email_confirmation => new_email,
339 :display_name => display_name,
340 :auth_provider => "openid",
341 :auth_uid => "http://localhost:1123/new.tester",
342 :pass_crypt => "testtest",
343 :pass_crypt_confirmation => "testtest" },
344 :read_ct => 1, :read_tou => 1 }
351 register_email = ActionMailer::Base.deliveries.first
353 assert_equal register_email.to.first, new_email
354 # Check that the confirm account url is correct
355 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
356 email_text_parts(register_email).each do |part|
357 assert_match confirm_regex, part.body.to_s
359 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
362 assert_response :success
363 assert_template "users/confirm"
365 ActionMailer::Base.deliveries.clear
367 # Go to the confirmation page
368 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
369 assert_response :success
370 assert_template "users/confirm"
372 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
373 assert_response :redirect
375 assert_response :success
376 assert_template "site/welcome"
379 def test_user_create_google_success
380 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
381 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
384 new_email = "newtester-google@osm.org"
385 display_name = "new_tester-google"
386 password = "testtest"
387 assert_difference("User.count") do
388 assert_difference("ActionMailer::Base.deliveries.size", 1) do
389 perform_enqueued_jobs do
391 :params => { :user => { :email => new_email,
392 :email_confirmation => new_email,
393 :display_name => display_name,
394 :auth_provider => "google",
396 :pass_crypt_confirmation => "" } }
397 assert_response :redirect
398 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
400 assert_response :redirect
401 assert_redirected_to auth_success_path(:provider => "google")
403 assert_response :redirect
404 assert_redirected_to "/user/terms"
406 :params => { :user => { :email => new_email,
407 :email_confirmation => new_email,
408 :display_name => display_name,
409 :auth_provider => "google",
410 :auth_uid => "123454321",
411 :pass_crypt => password,
412 :pass_crypt_confirmation => password },
413 :read_ct => 1, :read_tou => 1 }
414 assert_response :redirect
421 assert_response :success
422 assert_template "users/confirm"
424 ActionMailer::Base.deliveries.clear
427 def test_user_create_google_failure
428 OmniAuth.config.mock_auth[:google] = :connection_failed
430 new_email = "newtester-google2@osm.org"
431 display_name = "new_tester-google2"
432 assert_difference("User.count", 0) do
433 assert_difference("ActionMailer::Base.deliveries.size", 0) do
434 perform_enqueued_jobs do
436 :params => { :user => { :email => new_email,
437 :email_confirmation => new_email,
438 :display_name => display_name,
439 :auth_provider => "google",
441 :pass_crypt_confirmation => "" } }
442 assert_response :redirect
443 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
445 assert_response :redirect
446 assert_redirected_to auth_success_path(:provider => "google")
448 assert_response :redirect
449 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
451 assert_response :redirect
453 assert_response :success
454 assert_template "users/new"
459 ActionMailer::Base.deliveries.clear
462 def test_user_create_google_redirect
463 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
464 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
467 new_email = "redirect_tester_google@osm.org"
468 display_name = "redirect_tester_google"
469 # nothing special about this page, just need a protected page to redirect back to.
470 referer = "/traces/mine"
471 assert_difference("User.count") do
472 assert_difference("ActionMailer::Base.deliveries.size", 1) do
473 perform_enqueued_jobs do
475 :params => { :user => { :email => new_email,
476 :email_confirmation => new_email,
477 :display_name => display_name,
478 :auth_provider => "google",
480 :pass_crypt_confirmation => "" },
481 :referer => referer }
482 assert_response :redirect
483 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
485 assert_response :redirect
486 assert_redirected_to auth_success_path(:provider => "google")
488 assert_response :redirect
489 assert_redirected_to "/user/terms"
491 :params => { :user => { :email => new_email,
492 :email_confirmation => new_email,
493 :display_name => display_name,
494 :auth_provider => "google",
495 :auth_uid => "http://localhost:1123/new.tester",
496 :pass_crypt => "testtest",
497 :pass_crypt_confirmation => "testtest" },
498 :read_ct => 1, :read_tou => 1 }
505 register_email = ActionMailer::Base.deliveries.first
507 assert_equal register_email.to.first, new_email
508 # Check that the confirm account url is correct
509 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
510 email_text_parts(register_email).each do |part|
511 assert_match confirm_regex, part.body.to_s
513 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
516 assert_response :success
517 assert_template "users/confirm"
519 ActionMailer::Base.deliveries.clear
521 # Go to the confirmation page
522 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
523 assert_response :success
524 assert_template "users/confirm"
526 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
527 assert_response :redirect
529 assert_response :success
530 assert_template "site/welcome"
533 def test_user_create_facebook_success
534 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
536 new_email = "newtester-facebook@osm.org"
537 display_name = "new_tester-facebook"
538 password = "testtest"
539 assert_difference("User.count") do
540 assert_difference("ActionMailer::Base.deliveries.size", 1) do
541 perform_enqueued_jobs do
543 :params => { :user => { :email => new_email,
544 :email_confirmation => new_email,
545 :display_name => display_name,
546 :auth_provider => "facebook",
548 :pass_crypt_confirmation => "" } }
549 assert_response :redirect
550 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
552 assert_response :redirect
553 assert_redirected_to auth_success_path(:provider => "facebook")
555 assert_response :redirect
556 assert_redirected_to "/user/terms"
558 :params => { :user => { :email => new_email,
559 :email_confirmation => new_email,
560 :display_name => display_name,
561 :auth_provider => "facebook",
562 :auth_uid => "123454321",
563 :pass_crypt => password,
564 :pass_crypt_confirmation => password },
565 :read_ct => 1, :read_tou => 1 }
566 assert_response :redirect
573 assert_response :success
574 assert_template "users/confirm"
576 ActionMailer::Base.deliveries.clear
579 def test_user_create_facebook_failure
580 OmniAuth.config.mock_auth[:facebook] = :connection_failed
582 new_email = "newtester-facebook2@osm.org"
583 display_name = "new_tester-facebook2"
584 assert_difference("User.count", 0) do
585 assert_difference("ActionMailer::Base.deliveries.size", 0) do
586 perform_enqueued_jobs do
588 :params => { :user => { :email => new_email,
589 :email_confirmation => new_email,
590 :display_name => display_name,
591 :auth_provider => "facebook",
593 :pass_crypt_confirmation => "" } }
594 assert_response :redirect
595 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
597 assert_response :redirect
598 assert_redirected_to auth_success_path(:provider => "facebook")
600 assert_response :redirect
601 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
603 assert_response :redirect
605 assert_response :success
606 assert_template "users/new"
611 ActionMailer::Base.deliveries.clear
614 def test_user_create_facebook_redirect
615 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
617 new_email = "redirect_tester_facebook@osm.org"
618 display_name = "redirect_tester_facebook"
619 # nothing special about this page, just need a protected page to redirect back to.
620 referer = "/traces/mine"
621 assert_difference("User.count") do
622 assert_difference("ActionMailer::Base.deliveries.size", 1) do
623 perform_enqueued_jobs do
625 :params => { :user => { :email => new_email,
626 :email_confirmation => new_email,
627 :display_name => display_name,
628 :auth_provider => "facebook",
630 :pass_crypt_confirmation => "" },
631 :referer => referer }
632 assert_response :redirect
633 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
635 assert_response :redirect
636 assert_redirected_to auth_success_path(:provider => "facebook")
638 assert_response :redirect
639 assert_redirected_to "/user/terms"
641 :params => { :user => { :email => new_email,
642 :email_confirmation => new_email,
643 :display_name => display_name,
644 :auth_provider => "facebook",
645 :auth_uid => "http://localhost:1123/new.tester",
646 :pass_crypt => "testtest",
647 :pass_crypt_confirmation => "testtest" },
648 :read_ct => 1, :read_tou => 1 }
655 register_email = ActionMailer::Base.deliveries.first
657 assert_equal register_email.to.first, new_email
658 # Check that the confirm account url is correct
659 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
660 email_text_parts(register_email).each do |part|
661 assert_match confirm_regex, part.body.to_s
663 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
666 assert_response :success
667 assert_template "users/confirm"
669 ActionMailer::Base.deliveries.clear
671 # Go to the confirmation page
672 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
673 assert_response :success
674 assert_template "users/confirm"
676 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
677 assert_response :redirect
679 assert_response :success
680 assert_template "site/welcome"
683 def test_user_create_windowslive_success
684 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
686 new_email = "newtester-windowslive@osm.org"
687 display_name = "new_tester-windowslive"
688 password = "testtest"
689 assert_difference("User.count") do
690 assert_difference("ActionMailer::Base.deliveries.size", 1) do
691 perform_enqueued_jobs do
693 :params => { :user => { :email => new_email,
694 :email_confirmation => new_email,
695 :display_name => display_name,
696 :auth_provider => "windowslive",
698 :pass_crypt_confirmation => "" } }
699 assert_response :redirect
700 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
702 assert_response :redirect
703 assert_redirected_to auth_success_path(:provider => "windowslive")
705 assert_response :redirect
706 assert_redirected_to "/user/terms"
708 :params => { :user => { :email => new_email,
709 :email_confirmation => new_email,
710 :display_name => display_name,
711 :auth_provider => "windowslive",
712 :auth_uid => "123454321",
713 :pass_crypt => password,
714 :pass_crypt_confirmation => password },
715 :read_ct => 1, :read_tou => 1 }
716 assert_response :redirect
723 assert_response :success
724 assert_template "users/confirm"
726 ActionMailer::Base.deliveries.clear
729 def test_user_create_windowslive_failure
730 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
732 new_email = "newtester-windowslive2@osm.org"
733 display_name = "new_tester-windowslive2"
734 assert_difference("User.count", 0) do
735 assert_difference("ActionMailer::Base.deliveries.size", 0) do
736 perform_enqueued_jobs do
738 :params => { :user => { :email => new_email,
739 :email_confirmation => new_email,
740 :display_name => display_name,
741 :auth_provider => "windowslive",
743 :pass_crypt_confirmation => "" } }
744 assert_response :redirect
745 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
747 assert_response :redirect
748 assert_redirected_to auth_success_path(:provider => "windowslive")
750 assert_response :redirect
751 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/user/new")
753 assert_response :redirect
755 assert_response :success
756 assert_template "users/new"
761 ActionMailer::Base.deliveries.clear
764 def test_user_create_windowslive_redirect
765 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
767 new_email = "redirect_tester_windowslive@osm.org"
768 display_name = "redirect_tester_windowslive"
769 # nothing special about this page, just need a protected page to redirect back to.
770 referer = "/traces/mine"
771 assert_difference("User.count") do
772 assert_difference("ActionMailer::Base.deliveries.size", 1) do
773 perform_enqueued_jobs do
775 :params => { :user => { :email => new_email,
776 :email_confirmation => new_email,
777 :display_name => display_name,
778 :auth_provider => "windowslive",
780 :pass_crypt_confirmation => "" },
781 :referer => referer }
782 assert_response :redirect
783 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
785 assert_response :redirect
786 assert_redirected_to auth_success_path(:provider => "windowslive")
788 assert_response :redirect
789 assert_redirected_to "/user/terms"
791 :params => { :user => { :email => new_email,
792 :email_confirmation => new_email,
793 :display_name => display_name,
794 :auth_provider => "windowslive",
795 :auth_uid => "http://localhost:1123/new.tester",
796 :pass_crypt => "testtest",
797 :pass_crypt_confirmation => "testtest" },
798 :read_ct => 1, :read_tou => 1 }
805 register_email = ActionMailer::Base.deliveries.first
807 assert_equal register_email.to.first, new_email
808 # Check that the confirm account url is correct
809 confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
810 email_text_parts(register_email).each do |part|
811 assert_match confirm_regex, part.body.to_s
813 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
816 assert_response :success
817 assert_template "users/confirm"
819 ActionMailer::Base.deliveries.clear
821 # Go to the confirmation page
822 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
823 assert_response :success
824 assert_template "users/confirm"
826 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
827 assert_response :redirect
829 assert_response :success
830 assert_template "site/welcome"
833 def test_user_create_github_success
834 OmniAuth.config.add_mock(:github, :uid => "123454321")
836 new_email = "newtester-github@osm.org"
837 display_name = "new_tester-github"
838 password = "testtest"
839 assert_difference("User.count") do
840 assert_difference("ActionMailer::Base.deliveries.size", 1) do
841 perform_enqueued_jobs do
843 :params => { :user => { :email => new_email,
844 :email_confirmation => new_email,
845 :display_name => display_name,
846 :auth_provider => "github",
848 :pass_crypt_confirmation => "" } }
849 assert_response :redirect
850 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
852 assert_response :redirect
853 assert_redirected_to auth_success_path(:provider => "github")
855 assert_response :redirect
856 assert_redirected_to "/user/terms"
858 :params => { :user => { :email => new_email,
859 :email_confirmation => new_email,
860 :display_name => display_name,
861 :auth_provider => "github",
862 :auth_uid => "123454321",
863 :pass_crypt => password,
864 :pass_crypt_confirmation => password },
867 assert_response :redirect
874 assert_response :success
875 assert_template "users/confirm"
877 ActionMailer::Base.deliveries.clear
880 def test_user_create_github_failure
881 OmniAuth.config.mock_auth[:github] = :connection_failed
883 new_email = "newtester-github2@osm.org"
884 display_name = "new_tester-github2"
885 assert_difference("User.count", 0) do
886 assert_difference("ActionMailer::Base.deliveries.size", 0) do
887 perform_enqueued_jobs do
889 :params => { :user => { :email => new_email,
890 :email_confirmation => new_email,
891 :display_name => display_name,
892 :auth_provider => "github",
894 :pass_crypt_confirmation => "" } }
895 assert_response :redirect
896 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
898 assert_response :redirect
899 assert_redirected_to auth_success_path(:provider => "github")
901 assert_response :redirect
902 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
904 assert_response :redirect
906 assert_response :success
907 assert_template "users/new"
912 ActionMailer::Base.deliveries.clear
915 def test_user_create_github_redirect
916 OmniAuth.config.add_mock(:github, :uid => "123454321")
918 new_email = "redirect_tester_github@osm.org"
919 display_name = "redirect_tester_github"
920 # nothing special about this page, just need a protected page to redirect back to.
921 referer = "/traces/mine"
922 assert_difference("User.count") do
923 assert_difference("ActionMailer::Base.deliveries.size", 1) do
924 perform_enqueued_jobs do
926 :params => { :user => { :email => new_email,
927 :email_confirmation => new_email,
928 :display_name => display_name,
929 :auth_provider => "github",
931 :pass_crypt_confirmation => "" },
932 :referer => referer }
933 assert_response :redirect
934 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
936 assert_response :redirect
937 assert_redirected_to auth_success_path(:provider => "github")
939 assert_response :redirect
940 assert_redirected_to "/user/terms"
942 :params => { :user => { :email => new_email,
943 :email_confirmation => new_email,
944 :display_name => display_name,
945 :auth_provider => "github",
946 :auth_uid => "http://localhost:1123/new.tester",
947 :pass_crypt => "testtest",
948 :pass_crypt_confirmation => "testtest" },
957 register_email = ActionMailer::Base.deliveries.first
959 assert_equal register_email.to.first, new_email
960 # Check that the confirm account url is correct
961 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
962 email_text_parts(register_email).each do |part|
963 assert_match confirm_regex, part.body.to_s
965 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
968 assert_response :success
969 assert_template "users/confirm"
971 ActionMailer::Base.deliveries.clear
973 # Go to the confirmation page
974 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
975 assert_response :success
976 assert_template "users/confirm"
978 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
979 assert_response :redirect
981 assert_response :success
982 assert_template "site/welcome"
985 def test_user_create_wikipedia_success
986 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
988 new_email = "newtester-wikipedia@osm.org"
989 display_name = "new_tester-wikipedia"
990 password = "testtest"
991 assert_difference("User.count") do
992 assert_difference("ActionMailer::Base.deliveries.size", 1) do
993 perform_enqueued_jobs do
995 :params => { :user => { :email => new_email,
996 :email_confirmation => new_email,
997 :display_name => display_name,
998 :auth_provider => "wikipedia",
1000 :pass_crypt_confirmation => "" } }
1001 assert_response :redirect
1002 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1004 assert_response :redirect
1005 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1007 assert_response :redirect
1008 assert_redirected_to "/user/terms"
1010 :params => { :user => { :email => new_email,
1011 :email_confirmation => new_email,
1012 :display_name => display_name,
1013 :auth_provider => "wikipedia",
1014 :auth_uid => "123454321",
1015 :pass_crypt => password,
1016 :pass_crypt_confirmation => password },
1019 assert_response :redirect
1026 assert_response :success
1027 assert_template "users/confirm"
1029 ActionMailer::Base.deliveries.clear
1032 def test_user_create_wikipedia_failure
1033 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
1035 new_email = "newtester-wikipedia2@osm.org"
1036 display_name = "new_tester-wikipedia2"
1037 assert_difference("User.count", 0) do
1038 assert_difference("ActionMailer::Base.deliveries.size", 0) do
1039 perform_enqueued_jobs do
1041 :params => { :user => { :email => new_email,
1042 :email_confirmation => new_email,
1043 :display_name => display_name,
1044 :auth_provider => "wikipedia",
1046 :pass_crypt_confirmation => "" } }
1047 assert_response :redirect
1048 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1050 assert_response :redirect
1051 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1053 assert_response :redirect
1054 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
1056 assert_response :redirect
1058 assert_response :success
1059 assert_template "users/new"
1064 ActionMailer::Base.deliveries.clear
1067 def test_user_create_wikipedia_redirect
1068 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
1070 new_email = "redirect_tester_wikipedia@osm.org"
1071 display_name = "redirect_tester_wikipedia"
1072 # nothing special about this page, just need a protected page to redirect back to.
1073 referer = "/traces/mine"
1074 assert_difference("User.count") do
1075 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1076 perform_enqueued_jobs do
1078 :params => { :user => { :email => new_email,
1079 :email_confirmation => new_email,
1080 :display_name => display_name,
1081 :auth_provider => "wikipedia",
1083 :pass_crypt_confirmation => "" },
1084 :referer => referer }
1085 assert_response :redirect
1086 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1088 assert_response :redirect
1089 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1091 assert_response :redirect
1092 assert_redirected_to "/user/terms"
1094 :params => { :user => { :email => new_email,
1095 :email_confirmation => new_email,
1096 :display_name => display_name,
1097 :auth_provider => "wikipedia",
1098 :auth_uid => "http://localhost:1123/new.tester",
1099 :pass_crypt => "testtest",
1100 :pass_crypt_confirmation => "testtest" },
1109 register_email = ActionMailer::Base.deliveries.first
1111 assert_equal register_email.to.first, new_email
1112 # Check that the confirm account url is correct
1113 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
1114 email_text_parts(register_email).each do |part|
1115 assert_match confirm_regex, part.body.to_s
1117 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
1120 assert_response :success
1121 assert_template "users/confirm"
1123 ActionMailer::Base.deliveries.clear
1125 # Go to the confirmation page
1126 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1127 assert_response :success
1128 assert_template "users/confirm"
1130 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1131 assert_response :redirect
1133 assert_response :success
1134 assert_template "site/welcome"