3 class UserCreationTest < ActionDispatch::IntegrationTest
5 OmniAuth.config.test_mode = true
7 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
11 OmniAuth.config.mock_auth[:openid] = nil
12 OmniAuth.config.mock_auth[:google] = nil
13 OmniAuth.config.mock_auth[:facebook] = nil
14 OmniAuth.config.mock_auth[:microsoft] = nil
15 OmniAuth.config.mock_auth[:github] = nil
16 OmniAuth.config.mock_auth[:wikipedia] = nil
17 OmniAuth.config.test_mode = false
20 def test_create_user_form
23 assert_response :success
24 assert_template "users/new"
27 def test_user_create_submit_duplicate_email
28 dup_email = create(:user).email
29 display_name = "new_tester"
30 assert_difference("User.count", 0) do
31 assert_difference("ActionMailer::Base.deliveries.size", 0) do
32 perform_enqueued_jobs do
34 :params => { :user => { :email => dup_email,
35 :email_confirmation => dup_email,
36 :display_name => display_name,
37 :pass_crypt => "testtest",
38 :pass_crypt_confirmation => "testtest" } }
42 assert_response :success
43 assert_template "users/new"
45 assert_select "form > div > input.is-invalid#user_email"
48 def test_user_create_submit_duplicate_username
49 dup_display_name = create(:user).display_name
51 assert_difference("User.count", 0) do
52 assert_difference("ActionMailer::Base.deliveries.size", 0) do
53 perform_enqueued_jobs do
55 :params => { :user => { :email => email,
56 :email_confirmation => email,
57 :display_name => dup_display_name,
58 :pass_crypt => "testtest",
59 :pass_crypt_confirmation => "testtest" } }
63 assert_response :success
64 assert_template "users/new"
65 assert_select "form > div > input.is-invalid#user_display_name"
68 def test_user_create_success
69 new_email = "newtester@osm.org"
70 display_name = "new_tester"
72 assert_difference("User.count", 0) do
73 assert_difference("ActionMailer::Base.deliveries.size", 0) do
74 perform_enqueued_jobs do
76 :params => { :user => { :email => new_email,
77 :email_confirmation => new_email,
78 :display_name => display_name,
79 :pass_crypt => "testtest",
80 :pass_crypt_confirmation => "testtest" } }
85 assert_redirected_to "/user/terms"
87 assert_difference("User.count") do
88 assert_difference("ActionMailer::Base.deliveries.size", 1) do
89 perform_enqueued_jobs do
91 :params => { :read_ct => 1, :read_tou => 1 }
98 register_email = ActionMailer::Base.deliveries.first
100 assert_equal register_email.to.first, new_email
101 # Check that the confirm account url is correct
102 assert_match(/#{@url}/, register_email.body.to_s)
105 assert_response :success
106 assert_template "confirmations/confirm"
108 ActionMailer::Base.deliveries.clear
111 def test_user_create_no_tou_failure
112 new_email = "#newtester@osm.org"
113 display_name = "new_tester"
115 assert_difference("User.count", 0) do
116 assert_difference("ActionMailer::Base.deliveries.size", 0) do
117 perform_enqueued_jobs do
119 :params => { :user => { :email => new_email,
120 :email_confirmation => new_email,
121 :display_name => display_name,
122 :pass_crypt => "testtest",
123 :pass_crypt_confirmation => "testtest" } }
128 assert_redirected_to "/user/terms"
130 perform_enqueued_jobs do
132 assert_redirected_to "/user/terms"
135 ActionMailer::Base.deliveries.clear
138 # Check that the user can successfully recover their password
139 def test_lost_password_recovery_success
140 # Open the lost password form
141 # Submit the lost password form
143 # Submit the reset password token
144 # Check that the password has changed, and the user can login
147 def test_user_create_redirect
148 new_email = "redirect_tester@osm.org"
149 display_name = "redirect_tester"
150 password = "testtest"
151 # nothing special about this page, just need a protected page to redirect back to.
152 referer = "/traces/mine"
153 assert_difference("User.count") do
154 assert_difference("ActionMailer::Base.deliveries.size", 1) do
155 perform_enqueued_jobs do
157 :params => { :user => { :email => new_email,
158 :email_confirmation => new_email,
159 :display_name => display_name,
160 :pass_crypt => password,
161 :pass_crypt_confirmation => password },
162 :referer => referer }
163 assert_redirected_to "/user/terms"
165 :params => { :user => { :email => new_email,
166 :email_confirmation => new_email,
167 :display_name => display_name,
168 :pass_crypt => password,
169 :pass_crypt_confirmation => password },
170 :read_ct => 1, :read_tou => 1 }
177 register_email = ActionMailer::Base.deliveries.first
179 assert_equal register_email.to.first, new_email
180 # Check that the confirm account url is correct
181 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
182 email_text_parts(register_email).each do |part|
183 assert_match confirm_regex, part.body.to_s
185 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
188 assert_response :success
189 assert_template "confirmations/confirm"
191 ActionMailer::Base.deliveries.clear
193 # Go to the confirmation page
194 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
195 assert_response :success
196 assert_template "confirmations/confirm"
198 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
199 assert_response :redirect
201 assert_response :success
202 assert_template "site/welcome"
205 def test_user_create_openid_success
206 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
208 new_email = "newtester-openid@osm.org"
209 display_name = "new_tester-openid"
210 password = "testtest"
211 assert_difference("User.count") do
212 assert_difference("ActionMailer::Base.deliveries.size", 1) do
213 perform_enqueued_jobs do
215 :params => { :user => { :email => new_email,
216 :email_confirmation => new_email,
217 :display_name => display_name,
218 :auth_provider => "openid",
219 :auth_uid => "http://localhost:1123/new.tester",
221 :pass_crypt_confirmation => "" } }
222 assert_response :redirect
223 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
224 post response.location
225 assert_response :redirect
226 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
228 assert_response :redirect
229 assert_redirected_to "/user/terms"
231 :params => { :user => { :email => new_email,
232 :email_confirmation => new_email,
233 :display_name => display_name,
234 :auth_provider => "openid",
235 :auth_uid => "http://localhost:1123/new.tester",
236 :pass_crypt => password,
237 :pass_crypt_confirmation => password },
238 :read_ct => 1, :read_tou => 1 }
239 assert_response :redirect
246 assert_response :success
247 assert_template "confirmations/confirm"
249 ActionMailer::Base.deliveries.clear
252 def test_user_create_openid_failure
253 OmniAuth.config.mock_auth[:openid] = :connection_failed
255 new_email = "newtester-openid2@osm.org"
256 display_name = "new_tester-openid2"
257 assert_difference("User.count", 0) do
258 assert_difference("ActionMailer::Base.deliveries.size", 0) do
259 perform_enqueued_jobs do
261 :params => { :user => { :email => new_email,
262 :email_confirmation => new_email,
263 :display_name => display_name,
264 :auth_provider => "openid",
265 :auth_uid => "http://localhost:1123/new.tester",
267 :pass_crypt_confirmation => "" } }
268 assert_response :redirect
269 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
270 post response.location
271 assert_response :redirect
272 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
274 assert_response :redirect
275 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
277 assert_response :redirect
279 assert_response :success
280 assert_template "users/new"
285 ActionMailer::Base.deliveries.clear
288 def test_user_create_openid_redirect
289 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
291 new_email = "redirect_tester_openid@osm.org"
292 display_name = "redirect_tester_openid"
293 # nothing special about this page, just need a protected page to redirect back to.
294 referer = "/traces/mine"
295 assert_difference("User.count") do
296 assert_difference("ActionMailer::Base.deliveries.size", 1) do
297 perform_enqueued_jobs do
299 :params => { :user => { :email => new_email,
300 :email_confirmation => new_email,
301 :display_name => display_name,
302 :auth_provider => "openid",
303 :auth_uid => "http://localhost:1123/new.tester",
305 :pass_crypt_confirmation => "" },
306 :referer => referer }
307 assert_response :redirect
308 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
309 post response.location
310 assert_response :redirect
311 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
313 assert_response :redirect
314 assert_redirected_to "/user/terms"
316 :params => { :user => { :email => new_email,
317 :email_confirmation => new_email,
318 :display_name => display_name,
319 :auth_provider => "openid",
320 :auth_uid => "http://localhost:1123/new.tester",
321 :pass_crypt => "testtest",
322 :pass_crypt_confirmation => "testtest" },
323 :read_ct => 1, :read_tou => 1 }
330 register_email = ActionMailer::Base.deliveries.first
332 assert_equal register_email.to.first, new_email
333 # Check that the confirm account url is correct
334 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
335 email_text_parts(register_email).each do |part|
336 assert_match confirm_regex, part.body.to_s
338 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
341 assert_response :success
342 assert_template "confirmations/confirm"
344 ActionMailer::Base.deliveries.clear
346 # Go to the confirmation page
347 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
348 assert_response :success
349 assert_template "confirmations/confirm"
351 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
352 assert_response :redirect
354 assert_response :success
355 assert_template "site/welcome"
358 def test_user_create_google_success
359 new_email = "newtester-google@osm.org"
360 display_name = "new_tester-google"
361 password = "testtest"
363 OmniAuth.config.add_mock(:google, :uid => "123454321", :info => { "email" => new_email })
365 assert_difference("User.count") do
366 assert_no_difference("ActionMailer::Base.deliveries.size") do
367 perform_enqueued_jobs do
369 :params => { :user => { :email => new_email,
370 :email_confirmation => new_email,
371 :display_name => display_name,
372 :auth_provider => "google",
374 :pass_crypt_confirmation => "" } }
375 assert_response :redirect
376 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
377 post response.location
378 assert_response :redirect
379 assert_redirected_to auth_success_path(:provider => "google")
381 assert_response :redirect
382 assert_redirected_to "/user/terms"
384 :params => { :user => { :email => new_email,
385 :email_confirmation => new_email,
386 :display_name => display_name,
387 :auth_provider => "google",
388 :auth_uid => "123454321",
389 :pass_crypt => password,
390 :pass_crypt_confirmation => password },
391 :read_ct => 1, :read_tou => 1 }
392 assert_response :redirect
393 assert_redirected_to welcome_path
400 assert_response :success
401 assert_template "site/welcome"
403 ActionMailer::Base.deliveries.clear
406 def test_user_create_google_failure
407 OmniAuth.config.mock_auth[:google] = :connection_failed
409 new_email = "newtester-google2@osm.org"
410 display_name = "new_tester-google2"
411 assert_difference("User.count", 0) do
412 assert_difference("ActionMailer::Base.deliveries.size", 0) do
413 perform_enqueued_jobs do
415 :params => { :user => { :email => new_email,
416 :email_confirmation => new_email,
417 :display_name => display_name,
418 :auth_provider => "google",
420 :pass_crypt_confirmation => "" } }
421 assert_response :redirect
422 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
423 post response.location
424 assert_response :redirect
425 assert_redirected_to auth_success_path(:provider => "google")
427 assert_response :redirect
428 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
430 assert_response :redirect
432 assert_response :success
433 assert_template "users/new"
438 ActionMailer::Base.deliveries.clear
441 def test_user_create_google_redirect
442 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
443 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
446 new_email = "redirect_tester_google@osm.org"
447 display_name = "redirect_tester_google"
448 # nothing special about this page, just need a protected page to redirect back to.
449 referer = "/traces/mine"
450 assert_difference("User.count") do
451 assert_difference("ActionMailer::Base.deliveries.size", 1) do
452 perform_enqueued_jobs do
454 :params => { :user => { :email => new_email,
455 :email_confirmation => new_email,
456 :display_name => display_name,
457 :auth_provider => "google",
459 :pass_crypt_confirmation => "" },
460 :referer => referer }
461 assert_response :redirect
462 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
463 post response.location
464 assert_response :redirect
465 assert_redirected_to auth_success_path(:provider => "google")
467 assert_response :redirect
468 assert_redirected_to "/user/terms"
470 :params => { :user => { :email => new_email,
471 :email_confirmation => new_email,
472 :display_name => display_name,
473 :auth_provider => "google",
474 :auth_uid => "http://localhost:1123/new.tester",
475 :pass_crypt => "testtest",
476 :pass_crypt_confirmation => "testtest" },
477 :read_ct => 1, :read_tou => 1 }
484 register_email = ActionMailer::Base.deliveries.first
486 assert_equal register_email.to.first, new_email
487 # Check that the confirm account url is correct
488 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
489 email_text_parts(register_email).each do |part|
490 assert_match confirm_regex, part.body.to_s
492 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
495 assert_response :success
496 assert_template "confirmations/confirm"
498 ActionMailer::Base.deliveries.clear
500 # Go to the confirmation page
501 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
502 assert_response :success
503 assert_template "confirmations/confirm"
505 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
506 assert_response :redirect
508 assert_response :success
509 assert_template "site/welcome"
512 def test_user_create_facebook_success
513 new_email = "newtester-facebook@osm.org"
514 display_name = "new_tester-facebook"
515 password = "testtest"
517 OmniAuth.config.add_mock(:facebook, :uid => "123454321", :info => { "email" => new_email })
519 assert_difference("User.count") do
520 assert_no_difference("ActionMailer::Base.deliveries.size") do
521 perform_enqueued_jobs do
523 :params => { :user => { :email => new_email,
524 :email_confirmation => new_email,
525 :display_name => display_name,
526 :auth_provider => "facebook",
528 :pass_crypt_confirmation => "" } }
529 assert_response :redirect
530 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
531 post response.location
532 assert_response :redirect
533 assert_redirected_to auth_success_path(:provider => "facebook")
535 assert_response :redirect
536 assert_redirected_to "/user/terms"
538 :params => { :user => { :email => new_email,
539 :email_confirmation => new_email,
540 :display_name => display_name,
541 :auth_provider => "facebook",
542 :auth_uid => "123454321",
543 :pass_crypt => password,
544 :pass_crypt_confirmation => password },
545 :read_ct => 1, :read_tou => 1 }
546 assert_response :redirect
547 assert_redirected_to welcome_path
554 assert_response :success
555 assert_template "site/welcome"
557 ActionMailer::Base.deliveries.clear
560 def test_user_create_facebook_failure
561 OmniAuth.config.mock_auth[:facebook] = :connection_failed
563 new_email = "newtester-facebook2@osm.org"
564 display_name = "new_tester-facebook2"
565 assert_difference("User.count", 0) do
566 assert_difference("ActionMailer::Base.deliveries.size", 0) do
567 perform_enqueued_jobs do
569 :params => { :user => { :email => new_email,
570 :email_confirmation => new_email,
571 :display_name => display_name,
572 :auth_provider => "facebook",
574 :pass_crypt_confirmation => "" } }
575 assert_response :redirect
576 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
577 post response.location
578 assert_response :redirect
579 assert_redirected_to auth_success_path(:provider => "facebook")
581 assert_response :redirect
582 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
584 assert_response :redirect
586 assert_response :success
587 assert_template "users/new"
592 ActionMailer::Base.deliveries.clear
595 def test_user_create_facebook_redirect
596 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
598 new_email = "redirect_tester_facebook@osm.org"
599 display_name = "redirect_tester_facebook"
600 # nothing special about this page, just need a protected page to redirect back to.
601 referer = "/traces/mine"
602 assert_difference("User.count") do
603 assert_difference("ActionMailer::Base.deliveries.size", 1) do
604 perform_enqueued_jobs do
606 :params => { :user => { :email => new_email,
607 :email_confirmation => new_email,
608 :display_name => display_name,
609 :auth_provider => "facebook",
611 :pass_crypt_confirmation => "" },
612 :referer => referer }
613 assert_response :redirect
614 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
615 post response.location
616 assert_response :redirect
617 assert_redirected_to auth_success_path(:provider => "facebook")
619 assert_response :redirect
620 assert_redirected_to "/user/terms"
622 :params => { :user => { :email => new_email,
623 :email_confirmation => new_email,
624 :display_name => display_name,
625 :auth_provider => "facebook",
626 :auth_uid => "http://localhost:1123/new.tester",
627 :pass_crypt => "testtest",
628 :pass_crypt_confirmation => "testtest" },
629 :read_ct => 1, :read_tou => 1 }
636 register_email = ActionMailer::Base.deliveries.first
638 assert_equal register_email.to.first, new_email
639 # Check that the confirm account url is correct
640 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
641 email_text_parts(register_email).each do |part|
642 assert_match confirm_regex, part.body.to_s
644 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
647 assert_response :success
648 assert_template "confirmations/confirm"
650 ActionMailer::Base.deliveries.clear
652 # Go to the confirmation page
653 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
654 assert_response :success
655 assert_template "confirmations/confirm"
657 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
658 assert_response :redirect
660 assert_response :success
661 assert_template "site/welcome"
664 def test_user_create_microsoft_success
665 new_email = "newtester-microsoft@osm.org"
666 display_name = "new_tester-microsoft"
667 password = "testtest"
669 OmniAuth.config.add_mock(:microsoft, :uid => "123454321", :info => { "email" => new_email })
671 assert_difference("User.count") do
672 assert_difference("ActionMailer::Base.deliveries.size", 0) do
673 perform_enqueued_jobs do
675 :params => { :user => { :email => new_email,
676 :email_confirmation => new_email,
677 :display_name => display_name,
678 :auth_provider => "microsoft",
680 :pass_crypt_confirmation => "" } }
681 assert_response :redirect
682 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
683 post response.location
684 assert_response :redirect
685 assert_redirected_to auth_success_path(:provider => "microsoft")
687 assert_response :redirect
688 assert_redirected_to "/user/terms"
690 :params => { :user => { :email => new_email,
691 :email_confirmation => new_email,
692 :display_name => display_name,
693 :auth_provider => "microsoft",
694 :auth_uid => "123454321",
695 :pass_crypt => password,
696 :pass_crypt_confirmation => password },
697 :read_ct => 1, :read_tou => 1 }
698 assert_response :redirect
699 assert_redirected_to welcome_path
706 assert_response :success
707 assert_template "site/welcome"
709 ActionMailer::Base.deliveries.clear
712 def test_user_create_microsoft_failure
713 OmniAuth.config.mock_auth[:microsoft] = :connection_failed
715 new_email = "newtester-microsoft2@osm.org"
716 display_name = "new_tester-microsoft2"
717 assert_difference("User.count", 0) do
718 assert_difference("ActionMailer::Base.deliveries.size", 0) do
719 perform_enqueued_jobs do
721 :params => { :user => { :email => new_email,
722 :email_confirmation => new_email,
723 :display_name => display_name,
724 :auth_provider => "microsoft",
726 :pass_crypt_confirmation => "" } }
727 assert_response :redirect
728 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
729 post response.location
730 assert_response :redirect
731 assert_redirected_to auth_success_path(:provider => "microsoft")
733 assert_response :redirect
734 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "connection_failed", :origin => "/user/new")
736 assert_response :redirect
738 assert_response :success
739 assert_template "users/new"
744 ActionMailer::Base.deliveries.clear
747 def test_user_create_microsoft_redirect
748 OmniAuth.config.add_mock(:microsoft, :uid => "123454321")
750 new_email = "redirect_tester_microsoft@osm.org"
751 display_name = "redirect_tester_microsoft"
752 # nothing special about this page, just need a protected page to redirect back to.
753 referer = "/traces/mine"
754 assert_difference("User.count") do
755 assert_difference("ActionMailer::Base.deliveries.size", 1) do
756 perform_enqueued_jobs do
758 :params => { :user => { :email => new_email,
759 :email_confirmation => new_email,
760 :display_name => display_name,
761 :auth_provider => "microsoft",
763 :pass_crypt_confirmation => "" },
764 :referer => referer }
765 assert_response :redirect
766 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
767 post response.location
768 assert_response :redirect
769 assert_redirected_to auth_success_path(:provider => "microsoft")
771 assert_response :redirect
772 assert_redirected_to "/user/terms"
774 :params => { :user => { :email => new_email,
775 :email_confirmation => new_email,
776 :display_name => display_name,
777 :auth_provider => "microsoft",
778 :auth_uid => "http://localhost:1123/new.tester",
779 :pass_crypt => "testtest",
780 :pass_crypt_confirmation => "testtest" },
781 :read_ct => 1, :read_tou => 1 }
788 register_email = ActionMailer::Base.deliveries.first
790 assert_equal register_email.to.first, new_email
791 # Check that the confirm account url is correct
792 confirm_regex = Regexp.new("/user/redirect_tester_microsoft/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
793 email_text_parts(register_email).each do |part|
794 assert_match confirm_regex, part.body.to_s
796 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
799 assert_response :success
800 assert_template "confirmations/confirm"
802 ActionMailer::Base.deliveries.clear
804 # Go to the confirmation page
805 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
806 assert_response :success
807 assert_template "confirmations/confirm"
809 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
810 assert_response :redirect
812 assert_response :success
813 assert_template "site/welcome"
816 def test_user_create_github_success
817 new_email = "newtester-github@osm.org"
818 display_name = "new_tester-github"
819 password = "testtest"
821 OmniAuth.config.add_mock(:github, :uid => "123454321", :info => { "email" => new_email })
823 assert_difference("User.count") do
824 assert_difference("ActionMailer::Base.deliveries.size", 1) do
825 perform_enqueued_jobs do
827 :params => { :user => { :email => new_email,
828 :email_confirmation => new_email,
829 :display_name => display_name,
830 :auth_provider => "github",
832 :pass_crypt_confirmation => "" } }
833 assert_response :redirect
834 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
835 post response.location
836 assert_response :redirect
837 assert_redirected_to auth_success_path(:provider => "github")
839 assert_response :redirect
840 assert_redirected_to "/user/terms"
842 :params => { :user => { :email => new_email,
843 :email_confirmation => new_email,
844 :display_name => display_name,
845 :auth_provider => "github",
846 :auth_uid => "123454321",
847 :pass_crypt => password,
848 :pass_crypt_confirmation => password },
851 assert_response :redirect
852 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
859 assert_response :success
860 assert_template "confirmations/confirm"
862 ActionMailer::Base.deliveries.clear
865 def test_user_create_github_failure
866 OmniAuth.config.mock_auth[:github] = :connection_failed
868 new_email = "newtester-github2@osm.org"
869 display_name = "new_tester-github2"
870 assert_difference("User.count", 0) do
871 assert_difference("ActionMailer::Base.deliveries.size", 0) do
872 perform_enqueued_jobs do
874 :params => { :user => { :email => new_email,
875 :email_confirmation => new_email,
876 :display_name => display_name,
877 :auth_provider => "github",
879 :pass_crypt_confirmation => "" } }
880 assert_response :redirect
881 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
882 post response.location
883 assert_response :redirect
884 assert_redirected_to auth_success_path(:provider => "github")
886 assert_response :redirect
887 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
889 assert_response :redirect
891 assert_response :success
892 assert_template "users/new"
897 ActionMailer::Base.deliveries.clear
900 def test_user_create_github_redirect
901 OmniAuth.config.add_mock(:github, :uid => "123454321")
903 new_email = "redirect_tester_github@osm.org"
904 display_name = "redirect_tester_github"
905 # nothing special about this page, just need a protected page to redirect back to.
906 referer = "/traces/mine"
907 assert_difference("User.count") do
908 assert_difference("ActionMailer::Base.deliveries.size", 1) do
909 perform_enqueued_jobs do
911 :params => { :user => { :email => new_email,
912 :email_confirmation => new_email,
913 :display_name => display_name,
914 :auth_provider => "github",
916 :pass_crypt_confirmation => "" },
917 :referer => referer }
918 assert_response :redirect
919 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
920 post response.location
921 assert_response :redirect
922 assert_redirected_to auth_success_path(:provider => "github")
924 assert_response :redirect
925 assert_redirected_to "/user/terms"
927 :params => { :user => { :email => new_email,
928 :email_confirmation => new_email,
929 :display_name => display_name,
930 :auth_provider => "github",
931 :auth_uid => "http://localhost:1123/new.tester",
932 :pass_crypt => "testtest",
933 :pass_crypt_confirmation => "testtest" },
942 register_email = ActionMailer::Base.deliveries.first
944 assert_equal register_email.to.first, new_email
945 # Check that the confirm account url is correct
946 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
947 email_text_parts(register_email).each do |part|
948 assert_match confirm_regex, part.body.to_s
950 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
953 assert_response :success
954 assert_template "confirmations/confirm"
956 ActionMailer::Base.deliveries.clear
958 # Go to the confirmation page
959 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
960 assert_response :success
961 assert_template "confirmations/confirm"
963 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
964 assert_response :redirect
966 assert_response :success
967 assert_template "site/welcome"
970 def test_user_create_wikipedia_success
971 new_email = "newtester-wikipedia@osm.org"
972 display_name = "new_tester-wikipedia"
973 password = "testtest"
975 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321", :info => { "email" => new_email })
977 assert_difference("User.count") do
978 assert_difference("ActionMailer::Base.deliveries.size", 1) do
979 perform_enqueued_jobs do
981 :params => { :user => { :email => new_email,
982 :email_confirmation => new_email,
983 :display_name => display_name,
984 :auth_provider => "wikipedia",
986 :pass_crypt_confirmation => "" } }
987 assert_response :redirect
988 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
989 post response.location
990 assert_response :redirect
991 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
993 assert_response :redirect
994 assert_redirected_to "/user/terms"
996 :params => { :user => { :email => new_email,
997 :email_confirmation => new_email,
998 :display_name => display_name,
999 :auth_provider => "wikipedia",
1000 :auth_uid => "123454321",
1001 :pass_crypt => password,
1002 :pass_crypt_confirmation => password },
1005 assert_response :redirect
1006 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
1013 assert_response :success
1014 assert_template "confirmations/confirm"
1016 ActionMailer::Base.deliveries.clear
1019 def test_user_create_wikipedia_failure
1020 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
1022 new_email = "newtester-wikipedia2@osm.org"
1023 display_name = "new_tester-wikipedia2"
1024 assert_difference("User.count", 0) do
1025 assert_difference("ActionMailer::Base.deliveries.size", 0) do
1026 perform_enqueued_jobs do
1028 :params => { :user => { :email => new_email,
1029 :email_confirmation => new_email,
1030 :display_name => display_name,
1031 :auth_provider => "wikipedia",
1033 :pass_crypt_confirmation => "" } }
1034 assert_response :redirect
1035 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1036 post response.location
1037 assert_response :redirect
1038 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1040 assert_response :redirect
1041 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
1043 assert_response :redirect
1045 assert_response :success
1046 assert_template "users/new"
1051 ActionMailer::Base.deliveries.clear
1054 def test_user_create_wikipedia_redirect
1055 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
1057 new_email = "redirect_tester_wikipedia@osm.org"
1058 display_name = "redirect_tester_wikipedia"
1059 # nothing special about this page, just need a protected page to redirect back to.
1060 referer = "/traces/mine"
1061 assert_difference("User.count") do
1062 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1063 perform_enqueued_jobs do
1065 :params => { :user => { :email => new_email,
1066 :email_confirmation => new_email,
1067 :display_name => display_name,
1068 :auth_provider => "wikipedia",
1070 :pass_crypt_confirmation => "" },
1071 :referer => referer }
1072 assert_response :redirect
1073 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1074 post response.location
1075 assert_response :redirect
1076 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1078 assert_response :redirect
1079 assert_redirected_to "/user/terms"
1081 :params => { :user => { :email => new_email,
1082 :email_confirmation => new_email,
1083 :display_name => display_name,
1084 :auth_provider => "wikipedia",
1085 :auth_uid => "http://localhost:1123/new.tester",
1086 :pass_crypt => "testtest",
1087 :pass_crypt_confirmation => "testtest" },
1096 register_email = ActionMailer::Base.deliveries.first
1098 assert_equal register_email.to.first, new_email
1099 # Check that the confirm account url is correct
1100 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
1101 email_text_parts(register_email).each do |part|
1102 assert_match confirm_regex, part.body.to_s
1104 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
1107 assert_response :success
1108 assert_template "confirmations/confirm"
1110 ActionMailer::Base.deliveries.clear
1112 # Go to the confirmation page
1113 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1114 assert_response :success
1115 assert_template "confirmations/confirm"
1117 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1118 assert_response :redirect
1120 assert_response :success
1121 assert_template "site/welcome"