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[:windowslive] = 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
21 I18n.available_locales.each do |locale|
23 get "/user/new", :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
25 assert_response :success
26 assert_template "users/new"
30 def test_user_create_submit_duplicate_email
31 Locale.available.each do |locale|
32 dup_email = create(:user).email
33 display_name = "#{locale}_new_tester"
34 assert_difference("User.count", 0) do
35 assert_difference("ActionMailer::Base.deliveries.size", 0) do
36 perform_enqueued_jobs do
38 :params => { :user => { :email => dup_email,
39 :email_confirmation => dup_email,
40 :display_name => display_name,
41 :pass_crypt => "testtest",
42 :pass_crypt_confirmation => "testtest" } },
43 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
47 assert_response :success
48 assert_template "users/new"
49 assert_equal locale.to_s, response.headers["Content-Language"]
51 assert_select "form > div.form-group > input.is-invalid#user_email"
52 assert_no_missing_translations
56 def test_user_create_submit_duplicate_username
57 I18n.available_locales.each do |locale|
58 dup_display_name = create(:user).display_name
59 email = "#{locale}_new_tester"
60 assert_difference("User.count", 0) do
61 assert_difference("ActionMailer::Base.deliveries.size", 0) do
62 perform_enqueued_jobs do
64 :params => { :user => { :email => email,
65 :email_confirmation => email,
66 :display_name => dup_display_name,
67 :pass_crypt => "testtest",
68 :pass_crypt_confirmation => "testtest" } },
69 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
73 assert_response :success
74 assert_template "users/new"
75 assert_select "form > div.form-group > input.is-invalid#user_display_name"
76 assert_no_missing_translations
80 def test_user_create_success
81 I18n.available_locales.each do |locale|
82 new_email = "#{locale}newtester@osm.org"
83 display_name = "#{locale}_new_tester"
85 assert_difference("User.count", 0) do
86 assert_difference("ActionMailer::Base.deliveries.size", 0) do
87 perform_enqueued_jobs do
89 :params => { :user => { :email => new_email,
90 :email_confirmation => new_email,
91 :display_name => display_name,
92 :pass_crypt => "testtest",
93 :pass_crypt_confirmation => "testtest" } }
98 assert_redirected_to "/user/terms"
100 assert_difference("User.count") do
101 assert_difference("ActionMailer::Base.deliveries.size", 1) do
102 perform_enqueued_jobs do
104 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s },
105 :params => { :read_ct => 1, :read_tou => 1 }
112 register_email = ActionMailer::Base.deliveries.first
114 assert_equal register_email.to.first, new_email
115 # Check that the confirm account url is correct
116 assert_match(/#{@url}/, register_email.body.to_s)
119 assert_response :success
120 assert_template "confirmations/confirm"
122 ActionMailer::Base.deliveries.clear
126 def test_user_create_no_tou_failure
127 I18n.available_locales.each do |locale|
128 new_email = "#{locale}newtester@osm.org"
129 display_name = "#{locale}_new_tester"
131 assert_difference("User.count", 0) do
132 assert_difference("ActionMailer::Base.deliveries.size", 0) do
133 perform_enqueued_jobs do
135 :params => { :user => { :email => new_email,
136 :email_confirmation => new_email,
137 :display_name => display_name,
138 :pass_crypt => "testtest",
139 :pass_crypt_confirmation => "testtest" } }
144 assert_redirected_to "/user/terms"
146 perform_enqueued_jobs do
148 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
149 assert_redirected_to "/user/terms"
152 ActionMailer::Base.deliveries.clear
156 # Check that the user can successfully recover their password
157 def test_lost_password_recovery_success
158 # Open the lost password form
159 # Submit the lost password form
161 # Submit the reset password token
162 # Check that the password has changed, and the user can login
165 def test_user_create_redirect
166 new_email = "redirect_tester@osm.org"
167 display_name = "redirect_tester"
168 password = "testtest"
169 # nothing special about this page, just need a protected page to redirect back to.
170 referer = "/traces/mine"
171 assert_difference("User.count") do
172 assert_difference("ActionMailer::Base.deliveries.size", 1) do
173 perform_enqueued_jobs do
175 :params => { :user => { :email => new_email,
176 :email_confirmation => new_email,
177 :display_name => display_name,
178 :pass_crypt => password,
179 :pass_crypt_confirmation => password },
180 :referer => referer }
181 assert_redirected_to "/user/terms"
183 :params => { :user => { :email => new_email,
184 :email_confirmation => new_email,
185 :display_name => display_name,
186 :pass_crypt => password,
187 :pass_crypt_confirmation => password },
188 :read_ct => 1, :read_tou => 1 }
195 register_email = ActionMailer::Base.deliveries.first
197 assert_equal register_email.to.first, new_email
198 # Check that the confirm account url is correct
199 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
200 email_text_parts(register_email).each do |part|
201 assert_match confirm_regex, part.body.to_s
203 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
206 assert_response :success
207 assert_template "confirmations/confirm"
209 ActionMailer::Base.deliveries.clear
211 # Go to the confirmation page
212 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
213 assert_response :success
214 assert_template "confirmations/confirm"
216 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
217 assert_response :redirect
219 assert_response :success
220 assert_template "site/welcome"
223 def test_user_create_openid_success
224 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
226 new_email = "newtester-openid@osm.org"
227 display_name = "new_tester-openid"
228 password = "testtest"
229 assert_difference("User.count") do
230 assert_difference("ActionMailer::Base.deliveries.size", 1) do
231 perform_enqueued_jobs do
233 :params => { :user => { :email => new_email,
234 :email_confirmation => new_email,
235 :display_name => display_name,
236 :auth_provider => "openid",
237 :auth_uid => "http://localhost:1123/new.tester",
239 :pass_crypt_confirmation => "" } }
240 assert_response :redirect
241 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
242 post response.location
243 assert_response :redirect
244 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
246 assert_response :redirect
247 assert_redirected_to "/user/terms"
249 :params => { :user => { :email => new_email,
250 :email_confirmation => new_email,
251 :display_name => display_name,
252 :auth_provider => "openid",
253 :auth_uid => "http://localhost:1123/new.tester",
254 :pass_crypt => password,
255 :pass_crypt_confirmation => password },
256 :read_ct => 1, :read_tou => 1 }
257 assert_response :redirect
264 assert_response :success
265 assert_template "confirmations/confirm"
267 ActionMailer::Base.deliveries.clear
270 def test_user_create_openid_failure
271 OmniAuth.config.mock_auth[:openid] = :connection_failed
273 new_email = "newtester-openid2@osm.org"
274 display_name = "new_tester-openid2"
275 assert_difference("User.count", 0) do
276 assert_difference("ActionMailer::Base.deliveries.size", 0) do
277 perform_enqueued_jobs do
279 :params => { :user => { :email => new_email,
280 :email_confirmation => new_email,
281 :display_name => display_name,
282 :auth_provider => "openid",
283 :auth_uid => "http://localhost:1123/new.tester",
285 :pass_crypt_confirmation => "" } }
286 assert_response :redirect
287 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
288 post response.location
289 assert_response :redirect
290 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
292 assert_response :redirect
293 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
295 assert_response :redirect
297 assert_response :success
298 assert_template "users/new"
303 ActionMailer::Base.deliveries.clear
306 def test_user_create_openid_redirect
307 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
309 new_email = "redirect_tester_openid@osm.org"
310 display_name = "redirect_tester_openid"
311 # nothing special about this page, just need a protected page to redirect back to.
312 referer = "/traces/mine"
313 assert_difference("User.count") do
314 assert_difference("ActionMailer::Base.deliveries.size", 1) do
315 perform_enqueued_jobs do
317 :params => { :user => { :email => new_email,
318 :email_confirmation => new_email,
319 :display_name => display_name,
320 :auth_provider => "openid",
321 :auth_uid => "http://localhost:1123/new.tester",
323 :pass_crypt_confirmation => "" },
324 :referer => referer }
325 assert_response :redirect
326 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
327 post response.location
328 assert_response :redirect
329 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
331 assert_response :redirect
332 assert_redirected_to "/user/terms"
334 :params => { :user => { :email => new_email,
335 :email_confirmation => new_email,
336 :display_name => display_name,
337 :auth_provider => "openid",
338 :auth_uid => "http://localhost:1123/new.tester",
339 :pass_crypt => "testtest",
340 :pass_crypt_confirmation => "testtest" },
341 :read_ct => 1, :read_tou => 1 }
348 register_email = ActionMailer::Base.deliveries.first
350 assert_equal register_email.to.first, new_email
351 # Check that the confirm account url is correct
352 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
353 email_text_parts(register_email).each do |part|
354 assert_match confirm_regex, part.body.to_s
356 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
359 assert_response :success
360 assert_template "confirmations/confirm"
362 ActionMailer::Base.deliveries.clear
364 # Go to the confirmation page
365 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
366 assert_response :success
367 assert_template "confirmations/confirm"
369 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
370 assert_response :redirect
372 assert_response :success
373 assert_template "site/welcome"
376 def test_user_create_google_success
377 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
378 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
381 new_email = "newtester-google@osm.org"
382 display_name = "new_tester-google"
383 password = "testtest"
384 assert_difference("User.count") do
385 assert_difference("ActionMailer::Base.deliveries.size", 1) do
386 perform_enqueued_jobs do
388 :params => { :user => { :email => new_email,
389 :email_confirmation => new_email,
390 :display_name => display_name,
391 :auth_provider => "google",
393 :pass_crypt_confirmation => "" } }
394 assert_response :redirect
395 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
396 post response.location
397 assert_response :redirect
398 assert_redirected_to auth_success_path(:provider => "google")
400 assert_response :redirect
401 assert_redirected_to "/user/terms"
403 :params => { :user => { :email => new_email,
404 :email_confirmation => new_email,
405 :display_name => display_name,
406 :auth_provider => "google",
407 :auth_uid => "123454321",
408 :pass_crypt => password,
409 :pass_crypt_confirmation => password },
410 :read_ct => 1, :read_tou => 1 }
411 assert_response :redirect
418 assert_response :success
419 assert_template "confirmations/confirm"
421 ActionMailer::Base.deliveries.clear
424 def test_user_create_google_failure
425 OmniAuth.config.mock_auth[:google] = :connection_failed
427 new_email = "newtester-google2@osm.org"
428 display_name = "new_tester-google2"
429 assert_difference("User.count", 0) do
430 assert_difference("ActionMailer::Base.deliveries.size", 0) do
431 perform_enqueued_jobs do
433 :params => { :user => { :email => new_email,
434 :email_confirmation => new_email,
435 :display_name => display_name,
436 :auth_provider => "google",
438 :pass_crypt_confirmation => "" } }
439 assert_response :redirect
440 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
441 post response.location
442 assert_response :redirect
443 assert_redirected_to auth_success_path(:provider => "google")
445 assert_response :redirect
446 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
448 assert_response :redirect
450 assert_response :success
451 assert_template "users/new"
456 ActionMailer::Base.deliveries.clear
459 def test_user_create_google_redirect
460 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
461 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
464 new_email = "redirect_tester_google@osm.org"
465 display_name = "redirect_tester_google"
466 # nothing special about this page, just need a protected page to redirect back to.
467 referer = "/traces/mine"
468 assert_difference("User.count") do
469 assert_difference("ActionMailer::Base.deliveries.size", 1) do
470 perform_enqueued_jobs do
472 :params => { :user => { :email => new_email,
473 :email_confirmation => new_email,
474 :display_name => display_name,
475 :auth_provider => "google",
477 :pass_crypt_confirmation => "" },
478 :referer => referer }
479 assert_response :redirect
480 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
481 post response.location
482 assert_response :redirect
483 assert_redirected_to auth_success_path(:provider => "google")
485 assert_response :redirect
486 assert_redirected_to "/user/terms"
488 :params => { :user => { :email => new_email,
489 :email_confirmation => new_email,
490 :display_name => display_name,
491 :auth_provider => "google",
492 :auth_uid => "http://localhost:1123/new.tester",
493 :pass_crypt => "testtest",
494 :pass_crypt_confirmation => "testtest" },
495 :read_ct => 1, :read_tou => 1 }
502 register_email = ActionMailer::Base.deliveries.first
504 assert_equal register_email.to.first, new_email
505 # Check that the confirm account url is correct
506 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
507 email_text_parts(register_email).each do |part|
508 assert_match confirm_regex, part.body.to_s
510 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
513 assert_response :success
514 assert_template "confirmations/confirm"
516 ActionMailer::Base.deliveries.clear
518 # Go to the confirmation page
519 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
520 assert_response :success
521 assert_template "confirmations/confirm"
523 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
524 assert_response :redirect
526 assert_response :success
527 assert_template "site/welcome"
530 def test_user_create_facebook_success
531 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
533 new_email = "newtester-facebook@osm.org"
534 display_name = "new_tester-facebook"
535 password = "testtest"
536 assert_difference("User.count") do
537 assert_difference("ActionMailer::Base.deliveries.size", 1) do
538 perform_enqueued_jobs do
540 :params => { :user => { :email => new_email,
541 :email_confirmation => new_email,
542 :display_name => display_name,
543 :auth_provider => "facebook",
545 :pass_crypt_confirmation => "" } }
546 assert_response :redirect
547 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
548 post response.location
549 assert_response :redirect
550 assert_redirected_to auth_success_path(:provider => "facebook")
552 assert_response :redirect
553 assert_redirected_to "/user/terms"
555 :params => { :user => { :email => new_email,
556 :email_confirmation => new_email,
557 :display_name => display_name,
558 :auth_provider => "facebook",
559 :auth_uid => "123454321",
560 :pass_crypt => password,
561 :pass_crypt_confirmation => password },
562 :read_ct => 1, :read_tou => 1 }
563 assert_response :redirect
570 assert_response :success
571 assert_template "confirmations/confirm"
573 ActionMailer::Base.deliveries.clear
576 def test_user_create_facebook_failure
577 OmniAuth.config.mock_auth[:facebook] = :connection_failed
579 new_email = "newtester-facebook2@osm.org"
580 display_name = "new_tester-facebook2"
581 assert_difference("User.count", 0) do
582 assert_difference("ActionMailer::Base.deliveries.size", 0) do
583 perform_enqueued_jobs do
585 :params => { :user => { :email => new_email,
586 :email_confirmation => new_email,
587 :display_name => display_name,
588 :auth_provider => "facebook",
590 :pass_crypt_confirmation => "" } }
591 assert_response :redirect
592 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
593 post response.location
594 assert_response :redirect
595 assert_redirected_to auth_success_path(:provider => "facebook")
597 assert_response :redirect
598 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
600 assert_response :redirect
602 assert_response :success
603 assert_template "users/new"
608 ActionMailer::Base.deliveries.clear
611 def test_user_create_facebook_redirect
612 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
614 new_email = "redirect_tester_facebook@osm.org"
615 display_name = "redirect_tester_facebook"
616 # nothing special about this page, just need a protected page to redirect back to.
617 referer = "/traces/mine"
618 assert_difference("User.count") do
619 assert_difference("ActionMailer::Base.deliveries.size", 1) do
620 perform_enqueued_jobs do
622 :params => { :user => { :email => new_email,
623 :email_confirmation => new_email,
624 :display_name => display_name,
625 :auth_provider => "facebook",
627 :pass_crypt_confirmation => "" },
628 :referer => referer }
629 assert_response :redirect
630 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
631 post response.location
632 assert_response :redirect
633 assert_redirected_to auth_success_path(:provider => "facebook")
635 assert_response :redirect
636 assert_redirected_to "/user/terms"
638 :params => { :user => { :email => new_email,
639 :email_confirmation => new_email,
640 :display_name => display_name,
641 :auth_provider => "facebook",
642 :auth_uid => "http://localhost:1123/new.tester",
643 :pass_crypt => "testtest",
644 :pass_crypt_confirmation => "testtest" },
645 :read_ct => 1, :read_tou => 1 }
652 register_email = ActionMailer::Base.deliveries.first
654 assert_equal register_email.to.first, new_email
655 # Check that the confirm account url is correct
656 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
657 email_text_parts(register_email).each do |part|
658 assert_match confirm_regex, part.body.to_s
660 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
663 assert_response :success
664 assert_template "confirmations/confirm"
666 ActionMailer::Base.deliveries.clear
668 # Go to the confirmation page
669 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
670 assert_response :success
671 assert_template "confirmations/confirm"
673 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
674 assert_response :redirect
676 assert_response :success
677 assert_template "site/welcome"
680 def test_user_create_windowslive_success
681 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
683 new_email = "newtester-windowslive@osm.org"
684 display_name = "new_tester-windowslive"
685 password = "testtest"
686 assert_difference("User.count") do
687 assert_difference("ActionMailer::Base.deliveries.size", 1) do
688 perform_enqueued_jobs do
690 :params => { :user => { :email => new_email,
691 :email_confirmation => new_email,
692 :display_name => display_name,
693 :auth_provider => "windowslive",
695 :pass_crypt_confirmation => "" } }
696 assert_response :redirect
697 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
698 post response.location
699 assert_response :redirect
700 assert_redirected_to auth_success_path(:provider => "windowslive")
702 assert_response :redirect
703 assert_redirected_to "/user/terms"
705 :params => { :user => { :email => new_email,
706 :email_confirmation => new_email,
707 :display_name => display_name,
708 :auth_provider => "windowslive",
709 :auth_uid => "123454321",
710 :pass_crypt => password,
711 :pass_crypt_confirmation => password },
712 :read_ct => 1, :read_tou => 1 }
713 assert_response :redirect
720 assert_response :success
721 assert_template "confirmations/confirm"
723 ActionMailer::Base.deliveries.clear
726 def test_user_create_windowslive_failure
727 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
729 new_email = "newtester-windowslive2@osm.org"
730 display_name = "new_tester-windowslive2"
731 assert_difference("User.count", 0) do
732 assert_difference("ActionMailer::Base.deliveries.size", 0) do
733 perform_enqueued_jobs do
735 :params => { :user => { :email => new_email,
736 :email_confirmation => new_email,
737 :display_name => display_name,
738 :auth_provider => "windowslive",
740 :pass_crypt_confirmation => "" } }
741 assert_response :redirect
742 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
743 post response.location
744 assert_response :redirect
745 assert_redirected_to auth_success_path(:provider => "windowslive")
747 assert_response :redirect
748 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/user/new")
750 assert_response :redirect
752 assert_response :success
753 assert_template "users/new"
758 ActionMailer::Base.deliveries.clear
761 def test_user_create_windowslive_redirect
762 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
764 new_email = "redirect_tester_windowslive@osm.org"
765 display_name = "redirect_tester_windowslive"
766 # nothing special about this page, just need a protected page to redirect back to.
767 referer = "/traces/mine"
768 assert_difference("User.count") do
769 assert_difference("ActionMailer::Base.deliveries.size", 1) do
770 perform_enqueued_jobs do
772 :params => { :user => { :email => new_email,
773 :email_confirmation => new_email,
774 :display_name => display_name,
775 :auth_provider => "windowslive",
777 :pass_crypt_confirmation => "" },
778 :referer => referer }
779 assert_response :redirect
780 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
781 post response.location
782 assert_response :redirect
783 assert_redirected_to auth_success_path(:provider => "windowslive")
785 assert_response :redirect
786 assert_redirected_to "/user/terms"
788 :params => { :user => { :email => new_email,
789 :email_confirmation => new_email,
790 :display_name => display_name,
791 :auth_provider => "windowslive",
792 :auth_uid => "http://localhost:1123/new.tester",
793 :pass_crypt => "testtest",
794 :pass_crypt_confirmation => "testtest" },
795 :read_ct => 1, :read_tou => 1 }
802 register_email = ActionMailer::Base.deliveries.first
804 assert_equal register_email.to.first, new_email
805 # Check that the confirm account url is correct
806 confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
807 email_text_parts(register_email).each do |part|
808 assert_match confirm_regex, part.body.to_s
810 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
813 assert_response :success
814 assert_template "confirmations/confirm"
816 ActionMailer::Base.deliveries.clear
818 # Go to the confirmation page
819 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
820 assert_response :success
821 assert_template "confirmations/confirm"
823 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
824 assert_response :redirect
826 assert_response :success
827 assert_template "site/welcome"
830 def test_user_create_github_success
831 OmniAuth.config.add_mock(:github, :uid => "123454321")
833 new_email = "newtester-github@osm.org"
834 display_name = "new_tester-github"
835 password = "testtest"
836 assert_difference("User.count") do
837 assert_difference("ActionMailer::Base.deliveries.size", 1) do
838 perform_enqueued_jobs do
840 :params => { :user => { :email => new_email,
841 :email_confirmation => new_email,
842 :display_name => display_name,
843 :auth_provider => "github",
845 :pass_crypt_confirmation => "" } }
846 assert_response :redirect
847 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
848 post response.location
849 assert_response :redirect
850 assert_redirected_to auth_success_path(:provider => "github")
852 assert_response :redirect
853 assert_redirected_to "/user/terms"
855 :params => { :user => { :email => new_email,
856 :email_confirmation => new_email,
857 :display_name => display_name,
858 :auth_provider => "github",
859 :auth_uid => "123454321",
860 :pass_crypt => password,
861 :pass_crypt_confirmation => password },
864 assert_response :redirect
871 assert_response :success
872 assert_template "confirmations/confirm"
874 ActionMailer::Base.deliveries.clear
877 def test_user_create_github_failure
878 OmniAuth.config.mock_auth[:github] = :connection_failed
880 new_email = "newtester-github2@osm.org"
881 display_name = "new_tester-github2"
882 assert_difference("User.count", 0) do
883 assert_difference("ActionMailer::Base.deliveries.size", 0) do
884 perform_enqueued_jobs do
886 :params => { :user => { :email => new_email,
887 :email_confirmation => new_email,
888 :display_name => display_name,
889 :auth_provider => "github",
891 :pass_crypt_confirmation => "" } }
892 assert_response :redirect
893 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
894 post response.location
895 assert_response :redirect
896 assert_redirected_to auth_success_path(:provider => "github")
898 assert_response :redirect
899 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
901 assert_response :redirect
903 assert_response :success
904 assert_template "users/new"
909 ActionMailer::Base.deliveries.clear
912 def test_user_create_github_redirect
913 OmniAuth.config.add_mock(:github, :uid => "123454321")
915 new_email = "redirect_tester_github@osm.org"
916 display_name = "redirect_tester_github"
917 # nothing special about this page, just need a protected page to redirect back to.
918 referer = "/traces/mine"
919 assert_difference("User.count") do
920 assert_difference("ActionMailer::Base.deliveries.size", 1) do
921 perform_enqueued_jobs do
923 :params => { :user => { :email => new_email,
924 :email_confirmation => new_email,
925 :display_name => display_name,
926 :auth_provider => "github",
928 :pass_crypt_confirmation => "" },
929 :referer => referer }
930 assert_response :redirect
931 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
932 post response.location
933 assert_response :redirect
934 assert_redirected_to auth_success_path(:provider => "github")
936 assert_response :redirect
937 assert_redirected_to "/user/terms"
939 :params => { :user => { :email => new_email,
940 :email_confirmation => new_email,
941 :display_name => display_name,
942 :auth_provider => "github",
943 :auth_uid => "http://localhost:1123/new.tester",
944 :pass_crypt => "testtest",
945 :pass_crypt_confirmation => "testtest" },
954 register_email = ActionMailer::Base.deliveries.first
956 assert_equal register_email.to.first, new_email
957 # Check that the confirm account url is correct
958 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
959 email_text_parts(register_email).each do |part|
960 assert_match confirm_regex, part.body.to_s
962 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
965 assert_response :success
966 assert_template "confirmations/confirm"
968 ActionMailer::Base.deliveries.clear
970 # Go to the confirmation page
971 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
972 assert_response :success
973 assert_template "confirmations/confirm"
975 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
976 assert_response :redirect
978 assert_response :success
979 assert_template "site/welcome"
982 def test_user_create_wikipedia_success
983 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
985 new_email = "newtester-wikipedia@osm.org"
986 display_name = "new_tester-wikipedia"
987 password = "testtest"
988 assert_difference("User.count") do
989 assert_difference("ActionMailer::Base.deliveries.size", 1) do
990 perform_enqueued_jobs do
992 :params => { :user => { :email => new_email,
993 :email_confirmation => new_email,
994 :display_name => display_name,
995 :auth_provider => "wikipedia",
997 :pass_crypt_confirmation => "" } }
998 assert_response :redirect
999 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1000 post response.location
1001 assert_response :redirect
1002 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1004 assert_response :redirect
1005 assert_redirected_to "/user/terms"
1007 :params => { :user => { :email => new_email,
1008 :email_confirmation => new_email,
1009 :display_name => display_name,
1010 :auth_provider => "wikipedia",
1011 :auth_uid => "123454321",
1012 :pass_crypt => password,
1013 :pass_crypt_confirmation => password },
1016 assert_response :redirect
1023 assert_response :success
1024 assert_template "confirmations/confirm"
1026 ActionMailer::Base.deliveries.clear
1029 def test_user_create_wikipedia_failure
1030 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
1032 new_email = "newtester-wikipedia2@osm.org"
1033 display_name = "new_tester-wikipedia2"
1034 assert_difference("User.count", 0) do
1035 assert_difference("ActionMailer::Base.deliveries.size", 0) do
1036 perform_enqueued_jobs do
1038 :params => { :user => { :email => new_email,
1039 :email_confirmation => new_email,
1040 :display_name => display_name,
1041 :auth_provider => "wikipedia",
1043 :pass_crypt_confirmation => "" } }
1044 assert_response :redirect
1045 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1046 post response.location
1047 assert_response :redirect
1048 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1050 assert_response :redirect
1051 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
1053 assert_response :redirect
1055 assert_response :success
1056 assert_template "users/new"
1061 ActionMailer::Base.deliveries.clear
1064 def test_user_create_wikipedia_redirect
1065 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
1067 new_email = "redirect_tester_wikipedia@osm.org"
1068 display_name = "redirect_tester_wikipedia"
1069 # nothing special about this page, just need a protected page to redirect back to.
1070 referer = "/traces/mine"
1071 assert_difference("User.count") do
1072 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1073 perform_enqueued_jobs do
1075 :params => { :user => { :email => new_email,
1076 :email_confirmation => new_email,
1077 :display_name => display_name,
1078 :auth_provider => "wikipedia",
1080 :pass_crypt_confirmation => "" },
1081 :referer => referer }
1082 assert_response :redirect
1083 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1084 post response.location
1085 assert_response :redirect
1086 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1088 assert_response :redirect
1089 assert_redirected_to "/user/terms"
1091 :params => { :user => { :email => new_email,
1092 :email_confirmation => new_email,
1093 :display_name => display_name,
1094 :auth_provider => "wikipedia",
1095 :auth_uid => "http://localhost:1123/new.tester",
1096 :pass_crypt => "testtest",
1097 :pass_crypt_confirmation => "testtest" },
1106 register_email = ActionMailer::Base.deliveries.first
1108 assert_equal register_email.to.first, new_email
1109 # Check that the confirm account url is correct
1110 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
1111 email_text_parts(register_email).each do |part|
1112 assert_match confirm_regex, part.body.to_s
1114 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
1117 assert_response :success
1118 assert_template "confirmations/confirm"
1120 ActionMailer::Base.deliveries.clear
1122 # Go to the confirmation page
1123 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1124 assert_response :success
1125 assert_template "confirmations/confirm"
1127 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1128 assert_response :redirect
1130 assert_response :success
1131 assert_template "site/welcome"