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
21 I18n.with_locale "en" do
22 I18n.available_locales.each do |locale|
24 get "/user/new", :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
26 assert_response :success
27 assert_template "users/new"
32 def test_user_create_submit_duplicate_email
33 I18n.with_locale "en" do
34 Locale.available.each do |locale|
35 dup_email = create(:user).email
36 display_name = "#{locale}_new_tester"
37 assert_difference("User.count", 0) do
38 assert_difference("ActionMailer::Base.deliveries.size", 0) do
39 perform_enqueued_jobs do
41 :params => { :user => { :email => dup_email,
42 :email_confirmation => dup_email,
43 :display_name => display_name,
44 :pass_crypt => "testtest",
45 :pass_crypt_confirmation => "testtest" } },
46 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
50 assert_response :success
51 assert_template "users/new"
52 assert_equal locale.to_s, response.headers["Content-Language"]
54 assert_select "form > div > input.is-invalid#user_email"
55 assert_no_missing_translations
60 def test_user_create_submit_duplicate_username
61 I18n.with_locale "en" do
62 I18n.available_locales.each do |locale|
63 dup_display_name = create(:user).display_name
64 email = "#{locale}_new_tester"
65 assert_difference("User.count", 0) do
66 assert_difference("ActionMailer::Base.deliveries.size", 0) do
67 perform_enqueued_jobs do
69 :params => { :user => { :email => email,
70 :email_confirmation => email,
71 :display_name => dup_display_name,
72 :pass_crypt => "testtest",
73 :pass_crypt_confirmation => "testtest" } },
74 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
78 assert_response :success
79 assert_template "users/new"
80 assert_select "form > div > input.is-invalid#user_display_name"
81 assert_no_missing_translations
86 def test_user_create_success
87 I18n.with_locale "en" do
88 I18n.available_locales.each do |locale|
89 new_email = "#{locale}newtester@osm.org"
90 display_name = "#{locale}_new_tester"
92 assert_difference("User.count", 0) do
93 assert_difference("ActionMailer::Base.deliveries.size", 0) do
94 perform_enqueued_jobs do
96 :params => { :user => { :email => new_email,
97 :email_confirmation => new_email,
98 :display_name => display_name,
99 :pass_crypt => "testtest",
100 :pass_crypt_confirmation => "testtest" } }
105 assert_redirected_to "/user/terms"
107 assert_difference("User.count") do
108 assert_difference("ActionMailer::Base.deliveries.size", 1) do
109 perform_enqueued_jobs do
111 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s },
112 :params => { :read_ct => 1, :read_tou => 1 }
119 register_email = ActionMailer::Base.deliveries.first
121 assert_equal register_email.to.first, new_email
122 # Check that the confirm account url is correct
123 assert_match(/#{@url}/, register_email.body.to_s)
126 assert_response :success
127 assert_template "confirmations/confirm"
129 ActionMailer::Base.deliveries.clear
134 def test_user_create_no_tou_failure
135 I18n.with_locale "en" do
136 I18n.available_locales.each do |locale|
137 new_email = "#{locale}newtester@osm.org"
138 display_name = "#{locale}_new_tester"
140 assert_difference("User.count", 0) do
141 assert_difference("ActionMailer::Base.deliveries.size", 0) do
142 perform_enqueued_jobs do
144 :params => { :user => { :email => new_email,
145 :email_confirmation => new_email,
146 :display_name => display_name,
147 :pass_crypt => "testtest",
148 :pass_crypt_confirmation => "testtest" } }
153 assert_redirected_to "/user/terms"
155 perform_enqueued_jobs do
157 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
158 assert_redirected_to "/user/terms"
161 ActionMailer::Base.deliveries.clear
166 # Check that the user can successfully recover their password
167 def test_lost_password_recovery_success
168 # Open the lost password form
169 # Submit the lost password form
171 # Submit the reset password token
172 # Check that the password has changed, and the user can login
175 def test_user_create_redirect
176 new_email = "redirect_tester@osm.org"
177 display_name = "redirect_tester"
178 password = "testtest"
179 # nothing special about this page, just need a protected page to redirect back to.
180 referer = "/traces/mine"
181 assert_difference("User.count") do
182 assert_difference("ActionMailer::Base.deliveries.size", 1) do
183 perform_enqueued_jobs do
185 :params => { :user => { :email => new_email,
186 :email_confirmation => new_email,
187 :display_name => display_name,
188 :pass_crypt => password,
189 :pass_crypt_confirmation => password },
190 :referer => referer }
191 assert_redirected_to "/user/terms"
193 :params => { :user => { :email => new_email,
194 :email_confirmation => new_email,
195 :display_name => display_name,
196 :pass_crypt => password,
197 :pass_crypt_confirmation => password },
198 :read_ct => 1, :read_tou => 1 }
205 register_email = ActionMailer::Base.deliveries.first
207 assert_equal register_email.to.first, new_email
208 # Check that the confirm account url is correct
209 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
210 email_text_parts(register_email).each do |part|
211 assert_match confirm_regex, part.body.to_s
213 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
216 assert_response :success
217 assert_template "confirmations/confirm"
219 ActionMailer::Base.deliveries.clear
221 # Go to the confirmation page
222 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
223 assert_response :success
224 assert_template "confirmations/confirm"
226 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
227 assert_response :redirect
229 assert_response :success
230 assert_template "site/welcome"
233 def test_user_create_openid_success
234 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
236 new_email = "newtester-openid@osm.org"
237 display_name = "new_tester-openid"
238 password = "testtest"
239 assert_difference("User.count") do
240 assert_difference("ActionMailer::Base.deliveries.size", 1) do
241 perform_enqueued_jobs do
243 :params => { :user => { :email => new_email,
244 :email_confirmation => new_email,
245 :display_name => display_name,
246 :auth_provider => "openid",
247 :auth_uid => "http://localhost:1123/new.tester",
249 :pass_crypt_confirmation => "" } }
250 assert_response :redirect
251 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
252 post response.location
253 assert_response :redirect
254 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
256 assert_response :redirect
257 assert_redirected_to "/user/terms"
259 :params => { :user => { :email => new_email,
260 :email_confirmation => new_email,
261 :display_name => display_name,
262 :auth_provider => "openid",
263 :auth_uid => "http://localhost:1123/new.tester",
264 :pass_crypt => password,
265 :pass_crypt_confirmation => password },
266 :read_ct => 1, :read_tou => 1 }
267 assert_response :redirect
274 assert_response :success
275 assert_template "confirmations/confirm"
277 ActionMailer::Base.deliveries.clear
280 def test_user_create_openid_failure
281 OmniAuth.config.mock_auth[:openid] = :connection_failed
283 new_email = "newtester-openid2@osm.org"
284 display_name = "new_tester-openid2"
285 assert_difference("User.count", 0) do
286 assert_difference("ActionMailer::Base.deliveries.size", 0) do
287 perform_enqueued_jobs do
289 :params => { :user => { :email => new_email,
290 :email_confirmation => new_email,
291 :display_name => display_name,
292 :auth_provider => "openid",
293 :auth_uid => "http://localhost:1123/new.tester",
295 :pass_crypt_confirmation => "" } }
296 assert_response :redirect
297 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
298 post response.location
299 assert_response :redirect
300 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
302 assert_response :redirect
303 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
305 assert_response :redirect
307 assert_response :success
308 assert_template "users/new"
313 ActionMailer::Base.deliveries.clear
316 def test_user_create_openid_redirect
317 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
319 new_email = "redirect_tester_openid@osm.org"
320 display_name = "redirect_tester_openid"
321 # nothing special about this page, just need a protected page to redirect back to.
322 referer = "/traces/mine"
323 assert_difference("User.count") do
324 assert_difference("ActionMailer::Base.deliveries.size", 1) do
325 perform_enqueued_jobs do
327 :params => { :user => { :email => new_email,
328 :email_confirmation => new_email,
329 :display_name => display_name,
330 :auth_provider => "openid",
331 :auth_uid => "http://localhost:1123/new.tester",
333 :pass_crypt_confirmation => "" },
334 :referer => referer }
335 assert_response :redirect
336 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
337 post response.location
338 assert_response :redirect
339 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
341 assert_response :redirect
342 assert_redirected_to "/user/terms"
344 :params => { :user => { :email => new_email,
345 :email_confirmation => new_email,
346 :display_name => display_name,
347 :auth_provider => "openid",
348 :auth_uid => "http://localhost:1123/new.tester",
349 :pass_crypt => "testtest",
350 :pass_crypt_confirmation => "testtest" },
351 :read_ct => 1, :read_tou => 1 }
358 register_email = ActionMailer::Base.deliveries.first
360 assert_equal register_email.to.first, new_email
361 # Check that the confirm account url is correct
362 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
363 email_text_parts(register_email).each do |part|
364 assert_match confirm_regex, part.body.to_s
366 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
369 assert_response :success
370 assert_template "confirmations/confirm"
372 ActionMailer::Base.deliveries.clear
374 # Go to the confirmation page
375 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
376 assert_response :success
377 assert_template "confirmations/confirm"
379 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
380 assert_response :redirect
382 assert_response :success
383 assert_template "site/welcome"
386 def test_user_create_google_success
387 new_email = "newtester-google@osm.org"
388 display_name = "new_tester-google"
389 password = "testtest"
391 OmniAuth.config.add_mock(:google, :uid => "123454321", :info => { "email" => new_email })
393 assert_difference("User.count") do
394 assert_no_difference("ActionMailer::Base.deliveries.size") do
395 perform_enqueued_jobs do
397 :params => { :user => { :email => new_email,
398 :email_confirmation => new_email,
399 :display_name => display_name,
400 :auth_provider => "google",
402 :pass_crypt_confirmation => "" } }
403 assert_response :redirect
404 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
405 post response.location
406 assert_response :redirect
407 assert_redirected_to auth_success_path(:provider => "google")
409 assert_response :redirect
410 assert_redirected_to "/user/terms"
412 :params => { :user => { :email => new_email,
413 :email_confirmation => new_email,
414 :display_name => display_name,
415 :auth_provider => "google",
416 :auth_uid => "123454321",
417 :pass_crypt => password,
418 :pass_crypt_confirmation => password },
419 :read_ct => 1, :read_tou => 1 }
420 assert_response :redirect
421 assert_redirected_to welcome_path
428 assert_response :success
429 assert_template "site/welcome"
431 ActionMailer::Base.deliveries.clear
434 def test_user_create_google_failure
435 OmniAuth.config.mock_auth[:google] = :connection_failed
437 new_email = "newtester-google2@osm.org"
438 display_name = "new_tester-google2"
439 assert_difference("User.count", 0) do
440 assert_difference("ActionMailer::Base.deliveries.size", 0) do
441 perform_enqueued_jobs do
443 :params => { :user => { :email => new_email,
444 :email_confirmation => new_email,
445 :display_name => display_name,
446 :auth_provider => "google",
448 :pass_crypt_confirmation => "" } }
449 assert_response :redirect
450 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
451 post response.location
452 assert_response :redirect
453 assert_redirected_to auth_success_path(:provider => "google")
455 assert_response :redirect
456 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
458 assert_response :redirect
460 assert_response :success
461 assert_template "users/new"
466 ActionMailer::Base.deliveries.clear
469 def test_user_create_google_redirect
470 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
471 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
474 new_email = "redirect_tester_google@osm.org"
475 display_name = "redirect_tester_google"
476 # nothing special about this page, just need a protected page to redirect back to.
477 referer = "/traces/mine"
478 assert_difference("User.count") do
479 assert_difference("ActionMailer::Base.deliveries.size", 1) do
480 perform_enqueued_jobs do
482 :params => { :user => { :email => new_email,
483 :email_confirmation => new_email,
484 :display_name => display_name,
485 :auth_provider => "google",
487 :pass_crypt_confirmation => "" },
488 :referer => referer }
489 assert_response :redirect
490 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
491 post response.location
492 assert_response :redirect
493 assert_redirected_to auth_success_path(:provider => "google")
495 assert_response :redirect
496 assert_redirected_to "/user/terms"
498 :params => { :user => { :email => new_email,
499 :email_confirmation => new_email,
500 :display_name => display_name,
501 :auth_provider => "google",
502 :auth_uid => "http://localhost:1123/new.tester",
503 :pass_crypt => "testtest",
504 :pass_crypt_confirmation => "testtest" },
505 :read_ct => 1, :read_tou => 1 }
512 register_email = ActionMailer::Base.deliveries.first
514 assert_equal register_email.to.first, new_email
515 # Check that the confirm account url is correct
516 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
517 email_text_parts(register_email).each do |part|
518 assert_match confirm_regex, part.body.to_s
520 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
523 assert_response :success
524 assert_template "confirmations/confirm"
526 ActionMailer::Base.deliveries.clear
528 # Go to the confirmation page
529 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
530 assert_response :success
531 assert_template "confirmations/confirm"
533 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
534 assert_response :redirect
536 assert_response :success
537 assert_template "site/welcome"
540 def test_user_create_facebook_success
541 new_email = "newtester-facebook@osm.org"
542 display_name = "new_tester-facebook"
543 password = "testtest"
545 OmniAuth.config.add_mock(:facebook, :uid => "123454321", :info => { "email" => new_email })
547 assert_difference("User.count") do
548 assert_no_difference("ActionMailer::Base.deliveries.size") do
549 perform_enqueued_jobs do
551 :params => { :user => { :email => new_email,
552 :email_confirmation => new_email,
553 :display_name => display_name,
554 :auth_provider => "facebook",
556 :pass_crypt_confirmation => "" } }
557 assert_response :redirect
558 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
559 post response.location
560 assert_response :redirect
561 assert_redirected_to auth_success_path(:provider => "facebook")
563 assert_response :redirect
564 assert_redirected_to "/user/terms"
566 :params => { :user => { :email => new_email,
567 :email_confirmation => new_email,
568 :display_name => display_name,
569 :auth_provider => "facebook",
570 :auth_uid => "123454321",
571 :pass_crypt => password,
572 :pass_crypt_confirmation => password },
573 :read_ct => 1, :read_tou => 1 }
574 assert_response :redirect
575 assert_redirected_to welcome_path
582 assert_response :success
583 assert_template "site/welcome"
585 ActionMailer::Base.deliveries.clear
588 def test_user_create_facebook_failure
589 OmniAuth.config.mock_auth[:facebook] = :connection_failed
591 new_email = "newtester-facebook2@osm.org"
592 display_name = "new_tester-facebook2"
593 assert_difference("User.count", 0) do
594 assert_difference("ActionMailer::Base.deliveries.size", 0) do
595 perform_enqueued_jobs do
597 :params => { :user => { :email => new_email,
598 :email_confirmation => new_email,
599 :display_name => display_name,
600 :auth_provider => "facebook",
602 :pass_crypt_confirmation => "" } }
603 assert_response :redirect
604 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
605 post response.location
606 assert_response :redirect
607 assert_redirected_to auth_success_path(:provider => "facebook")
609 assert_response :redirect
610 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
612 assert_response :redirect
614 assert_response :success
615 assert_template "users/new"
620 ActionMailer::Base.deliveries.clear
623 def test_user_create_facebook_redirect
624 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
626 new_email = "redirect_tester_facebook@osm.org"
627 display_name = "redirect_tester_facebook"
628 # nothing special about this page, just need a protected page to redirect back to.
629 referer = "/traces/mine"
630 assert_difference("User.count") do
631 assert_difference("ActionMailer::Base.deliveries.size", 1) do
632 perform_enqueued_jobs do
634 :params => { :user => { :email => new_email,
635 :email_confirmation => new_email,
636 :display_name => display_name,
637 :auth_provider => "facebook",
639 :pass_crypt_confirmation => "" },
640 :referer => referer }
641 assert_response :redirect
642 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
643 post response.location
644 assert_response :redirect
645 assert_redirected_to auth_success_path(:provider => "facebook")
647 assert_response :redirect
648 assert_redirected_to "/user/terms"
650 :params => { :user => { :email => new_email,
651 :email_confirmation => new_email,
652 :display_name => display_name,
653 :auth_provider => "facebook",
654 :auth_uid => "http://localhost:1123/new.tester",
655 :pass_crypt => "testtest",
656 :pass_crypt_confirmation => "testtest" },
657 :read_ct => 1, :read_tou => 1 }
664 register_email = ActionMailer::Base.deliveries.first
666 assert_equal register_email.to.first, new_email
667 # Check that the confirm account url is correct
668 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
669 email_text_parts(register_email).each do |part|
670 assert_match confirm_regex, part.body.to_s
672 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
675 assert_response :success
676 assert_template "confirmations/confirm"
678 ActionMailer::Base.deliveries.clear
680 # Go to the confirmation page
681 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
682 assert_response :success
683 assert_template "confirmations/confirm"
685 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
686 assert_response :redirect
688 assert_response :success
689 assert_template "site/welcome"
692 def test_user_create_microsoft_success
693 new_email = "newtester-microsoft@osm.org"
694 display_name = "new_tester-microsoft"
695 password = "testtest"
697 OmniAuth.config.add_mock(:microsoft, :uid => "123454321", :info => { "email" => new_email })
699 assert_difference("User.count") do
700 assert_difference("ActionMailer::Base.deliveries.size", 0) do
701 perform_enqueued_jobs do
703 :params => { :user => { :email => new_email,
704 :email_confirmation => new_email,
705 :display_name => display_name,
706 :auth_provider => "microsoft",
708 :pass_crypt_confirmation => "" } }
709 assert_response :redirect
710 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
711 post response.location
712 assert_response :redirect
713 assert_redirected_to auth_success_path(:provider => "microsoft")
715 assert_response :redirect
716 assert_redirected_to "/user/terms"
718 :params => { :user => { :email => new_email,
719 :email_confirmation => new_email,
720 :display_name => display_name,
721 :auth_provider => "microsoft",
722 :auth_uid => "123454321",
723 :pass_crypt => password,
724 :pass_crypt_confirmation => password },
725 :read_ct => 1, :read_tou => 1 }
726 assert_response :redirect
727 assert_redirected_to welcome_path
734 assert_response :success
735 assert_template "site/welcome"
737 ActionMailer::Base.deliveries.clear
740 def test_user_create_microsoft_failure
741 OmniAuth.config.mock_auth[:microsoft] = :connection_failed
743 new_email = "newtester-microsoft2@osm.org"
744 display_name = "new_tester-microsoft2"
745 assert_difference("User.count", 0) do
746 assert_difference("ActionMailer::Base.deliveries.size", 0) do
747 perform_enqueued_jobs do
749 :params => { :user => { :email => new_email,
750 :email_confirmation => new_email,
751 :display_name => display_name,
752 :auth_provider => "microsoft",
754 :pass_crypt_confirmation => "" } }
755 assert_response :redirect
756 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
757 post response.location
758 assert_response :redirect
759 assert_redirected_to auth_success_path(:provider => "microsoft")
761 assert_response :redirect
762 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "connection_failed", :origin => "/user/new")
764 assert_response :redirect
766 assert_response :success
767 assert_template "users/new"
772 ActionMailer::Base.deliveries.clear
775 def test_user_create_microsoft_redirect
776 OmniAuth.config.add_mock(:microsoft, :uid => "123454321")
778 new_email = "redirect_tester_microsoft@osm.org"
779 display_name = "redirect_tester_microsoft"
780 # nothing special about this page, just need a protected page to redirect back to.
781 referer = "/traces/mine"
782 assert_difference("User.count") do
783 assert_difference("ActionMailer::Base.deliveries.size", 1) do
784 perform_enqueued_jobs do
786 :params => { :user => { :email => new_email,
787 :email_confirmation => new_email,
788 :display_name => display_name,
789 :auth_provider => "microsoft",
791 :pass_crypt_confirmation => "" },
792 :referer => referer }
793 assert_response :redirect
794 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
795 post response.location
796 assert_response :redirect
797 assert_redirected_to auth_success_path(:provider => "microsoft")
799 assert_response :redirect
800 assert_redirected_to "/user/terms"
802 :params => { :user => { :email => new_email,
803 :email_confirmation => new_email,
804 :display_name => display_name,
805 :auth_provider => "microsoft",
806 :auth_uid => "http://localhost:1123/new.tester",
807 :pass_crypt => "testtest",
808 :pass_crypt_confirmation => "testtest" },
809 :read_ct => 1, :read_tou => 1 }
816 register_email = ActionMailer::Base.deliveries.first
818 assert_equal register_email.to.first, new_email
819 # Check that the confirm account url is correct
820 confirm_regex = Regexp.new("/user/redirect_tester_microsoft/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
821 email_text_parts(register_email).each do |part|
822 assert_match confirm_regex, part.body.to_s
824 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
827 assert_response :success
828 assert_template "confirmations/confirm"
830 ActionMailer::Base.deliveries.clear
832 # Go to the confirmation page
833 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
834 assert_response :success
835 assert_template "confirmations/confirm"
837 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
838 assert_response :redirect
840 assert_response :success
841 assert_template "site/welcome"
844 def test_user_create_github_success
845 new_email = "newtester-github@osm.org"
846 display_name = "new_tester-github"
847 password = "testtest"
849 OmniAuth.config.add_mock(:github, :uid => "123454321", :info => { "email" => new_email })
851 assert_difference("User.count") do
852 assert_difference("ActionMailer::Base.deliveries.size", 1) do
853 perform_enqueued_jobs do
855 :params => { :user => { :email => new_email,
856 :email_confirmation => new_email,
857 :display_name => display_name,
858 :auth_provider => "github",
860 :pass_crypt_confirmation => "" } }
861 assert_response :redirect
862 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
863 post response.location
864 assert_response :redirect
865 assert_redirected_to auth_success_path(:provider => "github")
867 assert_response :redirect
868 assert_redirected_to "/user/terms"
870 :params => { :user => { :email => new_email,
871 :email_confirmation => new_email,
872 :display_name => display_name,
873 :auth_provider => "github",
874 :auth_uid => "123454321",
875 :pass_crypt => password,
876 :pass_crypt_confirmation => password },
879 assert_response :redirect
880 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
887 assert_response :success
888 assert_template "confirmations/confirm"
890 ActionMailer::Base.deliveries.clear
893 def test_user_create_github_failure
894 OmniAuth.config.mock_auth[:github] = :connection_failed
896 new_email = "newtester-github2@osm.org"
897 display_name = "new_tester-github2"
898 assert_difference("User.count", 0) do
899 assert_difference("ActionMailer::Base.deliveries.size", 0) do
900 perform_enqueued_jobs do
902 :params => { :user => { :email => new_email,
903 :email_confirmation => new_email,
904 :display_name => display_name,
905 :auth_provider => "github",
907 :pass_crypt_confirmation => "" } }
908 assert_response :redirect
909 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
910 post response.location
911 assert_response :redirect
912 assert_redirected_to auth_success_path(:provider => "github")
914 assert_response :redirect
915 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
917 assert_response :redirect
919 assert_response :success
920 assert_template "users/new"
925 ActionMailer::Base.deliveries.clear
928 def test_user_create_github_redirect
929 OmniAuth.config.add_mock(:github, :uid => "123454321")
931 new_email = "redirect_tester_github@osm.org"
932 display_name = "redirect_tester_github"
933 # nothing special about this page, just need a protected page to redirect back to.
934 referer = "/traces/mine"
935 assert_difference("User.count") do
936 assert_difference("ActionMailer::Base.deliveries.size", 1) do
937 perform_enqueued_jobs do
939 :params => { :user => { :email => new_email,
940 :email_confirmation => new_email,
941 :display_name => display_name,
942 :auth_provider => "github",
944 :pass_crypt_confirmation => "" },
945 :referer => referer }
946 assert_response :redirect
947 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
948 post response.location
949 assert_response :redirect
950 assert_redirected_to auth_success_path(:provider => "github")
952 assert_response :redirect
953 assert_redirected_to "/user/terms"
955 :params => { :user => { :email => new_email,
956 :email_confirmation => new_email,
957 :display_name => display_name,
958 :auth_provider => "github",
959 :auth_uid => "http://localhost:1123/new.tester",
960 :pass_crypt => "testtest",
961 :pass_crypt_confirmation => "testtest" },
970 register_email = ActionMailer::Base.deliveries.first
972 assert_equal register_email.to.first, new_email
973 # Check that the confirm account url is correct
974 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
975 email_text_parts(register_email).each do |part|
976 assert_match confirm_regex, part.body.to_s
978 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
981 assert_response :success
982 assert_template "confirmations/confirm"
984 ActionMailer::Base.deliveries.clear
986 # Go to the confirmation page
987 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
988 assert_response :success
989 assert_template "confirmations/confirm"
991 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
992 assert_response :redirect
994 assert_response :success
995 assert_template "site/welcome"
998 def test_user_create_wikipedia_success
999 new_email = "newtester-wikipedia@osm.org"
1000 display_name = "new_tester-wikipedia"
1001 password = "testtest"
1003 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321", :info => { "email" => new_email })
1005 assert_difference("User.count") do
1006 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1007 perform_enqueued_jobs do
1009 :params => { :user => { :email => new_email,
1010 :email_confirmation => new_email,
1011 :display_name => display_name,
1012 :auth_provider => "wikipedia",
1014 :pass_crypt_confirmation => "" } }
1015 assert_response :redirect
1016 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1017 post response.location
1018 assert_response :redirect
1019 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1021 assert_response :redirect
1022 assert_redirected_to "/user/terms"
1024 :params => { :user => { :email => new_email,
1025 :email_confirmation => new_email,
1026 :display_name => display_name,
1027 :auth_provider => "wikipedia",
1028 :auth_uid => "123454321",
1029 :pass_crypt => password,
1030 :pass_crypt_confirmation => password },
1033 assert_response :redirect
1034 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
1041 assert_response :success
1042 assert_template "confirmations/confirm"
1044 ActionMailer::Base.deliveries.clear
1047 def test_user_create_wikipedia_failure
1048 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
1050 new_email = "newtester-wikipedia2@osm.org"
1051 display_name = "new_tester-wikipedia2"
1052 assert_difference("User.count", 0) do
1053 assert_difference("ActionMailer::Base.deliveries.size", 0) do
1054 perform_enqueued_jobs do
1056 :params => { :user => { :email => new_email,
1057 :email_confirmation => new_email,
1058 :display_name => display_name,
1059 :auth_provider => "wikipedia",
1061 :pass_crypt_confirmation => "" } }
1062 assert_response :redirect
1063 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1064 post response.location
1065 assert_response :redirect
1066 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1068 assert_response :redirect
1069 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
1071 assert_response :redirect
1073 assert_response :success
1074 assert_template "users/new"
1079 ActionMailer::Base.deliveries.clear
1082 def test_user_create_wikipedia_redirect
1083 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
1085 new_email = "redirect_tester_wikipedia@osm.org"
1086 display_name = "redirect_tester_wikipedia"
1087 # nothing special about this page, just need a protected page to redirect back to.
1088 referer = "/traces/mine"
1089 assert_difference("User.count") do
1090 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1091 perform_enqueued_jobs do
1093 :params => { :user => { :email => new_email,
1094 :email_confirmation => new_email,
1095 :display_name => display_name,
1096 :auth_provider => "wikipedia",
1098 :pass_crypt_confirmation => "" },
1099 :referer => referer }
1100 assert_response :redirect
1101 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1102 post response.location
1103 assert_response :redirect
1104 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1106 assert_response :redirect
1107 assert_redirected_to "/user/terms"
1109 :params => { :user => { :email => new_email,
1110 :email_confirmation => new_email,
1111 :display_name => display_name,
1112 :auth_provider => "wikipedia",
1113 :auth_uid => "http://localhost:1123/new.tester",
1114 :pass_crypt => "testtest",
1115 :pass_crypt_confirmation => "testtest" },
1124 register_email = ActionMailer::Base.deliveries.first
1126 assert_equal register_email.to.first, new_email
1127 # Check that the confirm account url is correct
1128 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9_-]*)")
1129 email_text_parts(register_email).each do |part|
1130 assert_match confirm_regex, part.body.to_s
1132 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
1135 assert_response :success
1136 assert_template "confirmations/confirm"
1138 ActionMailer::Base.deliveries.clear
1140 # Go to the confirmation page
1141 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1142 assert_response :success
1143 assert_template "confirmations/confirm"
1145 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1146 assert_response :redirect
1148 assert_response :success
1149 assert_template "site/welcome"