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.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.form-group > 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.form-group > 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 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
388 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
391 new_email = "newtester-google@osm.org"
392 display_name = "new_tester-google"
393 password = "testtest"
394 assert_difference("User.count") do
395 assert_difference("ActionMailer::Base.deliveries.size", 1) do
396 perform_enqueued_jobs do
398 :params => { :user => { :email => new_email,
399 :email_confirmation => new_email,
400 :display_name => display_name,
401 :auth_provider => "google",
403 :pass_crypt_confirmation => "" } }
404 assert_response :redirect
405 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
406 post response.location
407 assert_response :redirect
408 assert_redirected_to auth_success_path(:provider => "google")
410 assert_response :redirect
411 assert_redirected_to "/user/terms"
413 :params => { :user => { :email => new_email,
414 :email_confirmation => new_email,
415 :display_name => display_name,
416 :auth_provider => "google",
417 :auth_uid => "123454321",
418 :pass_crypt => password,
419 :pass_crypt_confirmation => password },
420 :read_ct => 1, :read_tou => 1 }
421 assert_response :redirect
428 assert_response :success
429 assert_template "confirmations/confirm"
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 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
543 new_email = "newtester-facebook@osm.org"
544 display_name = "new_tester-facebook"
545 password = "testtest"
546 assert_difference("User.count") do
547 assert_difference("ActionMailer::Base.deliveries.size", 1) do
548 perform_enqueued_jobs do
550 :params => { :user => { :email => new_email,
551 :email_confirmation => new_email,
552 :display_name => display_name,
553 :auth_provider => "facebook",
555 :pass_crypt_confirmation => "" } }
556 assert_response :redirect
557 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
558 post response.location
559 assert_response :redirect
560 assert_redirected_to auth_success_path(:provider => "facebook")
562 assert_response :redirect
563 assert_redirected_to "/user/terms"
565 :params => { :user => { :email => new_email,
566 :email_confirmation => new_email,
567 :display_name => display_name,
568 :auth_provider => "facebook",
569 :auth_uid => "123454321",
570 :pass_crypt => password,
571 :pass_crypt_confirmation => password },
572 :read_ct => 1, :read_tou => 1 }
573 assert_response :redirect
580 assert_response :success
581 assert_template "confirmations/confirm"
583 ActionMailer::Base.deliveries.clear
586 def test_user_create_facebook_failure
587 OmniAuth.config.mock_auth[:facebook] = :connection_failed
589 new_email = "newtester-facebook2@osm.org"
590 display_name = "new_tester-facebook2"
591 assert_difference("User.count", 0) do
592 assert_difference("ActionMailer::Base.deliveries.size", 0) do
593 perform_enqueued_jobs do
595 :params => { :user => { :email => new_email,
596 :email_confirmation => new_email,
597 :display_name => display_name,
598 :auth_provider => "facebook",
600 :pass_crypt_confirmation => "" } }
601 assert_response :redirect
602 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
603 post response.location
604 assert_response :redirect
605 assert_redirected_to auth_success_path(:provider => "facebook")
607 assert_response :redirect
608 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
610 assert_response :redirect
612 assert_response :success
613 assert_template "users/new"
618 ActionMailer::Base.deliveries.clear
621 def test_user_create_facebook_redirect
622 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
624 new_email = "redirect_tester_facebook@osm.org"
625 display_name = "redirect_tester_facebook"
626 # nothing special about this page, just need a protected page to redirect back to.
627 referer = "/traces/mine"
628 assert_difference("User.count") do
629 assert_difference("ActionMailer::Base.deliveries.size", 1) do
630 perform_enqueued_jobs do
632 :params => { :user => { :email => new_email,
633 :email_confirmation => new_email,
634 :display_name => display_name,
635 :auth_provider => "facebook",
637 :pass_crypt_confirmation => "" },
638 :referer => referer }
639 assert_response :redirect
640 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
641 post response.location
642 assert_response :redirect
643 assert_redirected_to auth_success_path(:provider => "facebook")
645 assert_response :redirect
646 assert_redirected_to "/user/terms"
648 :params => { :user => { :email => new_email,
649 :email_confirmation => new_email,
650 :display_name => display_name,
651 :auth_provider => "facebook",
652 :auth_uid => "http://localhost:1123/new.tester",
653 :pass_crypt => "testtest",
654 :pass_crypt_confirmation => "testtest" },
655 :read_ct => 1, :read_tou => 1 }
662 register_email = ActionMailer::Base.deliveries.first
664 assert_equal register_email.to.first, new_email
665 # Check that the confirm account url is correct
666 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
667 email_text_parts(register_email).each do |part|
668 assert_match confirm_regex, part.body.to_s
670 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
673 assert_response :success
674 assert_template "confirmations/confirm"
676 ActionMailer::Base.deliveries.clear
678 # Go to the confirmation page
679 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
680 assert_response :success
681 assert_template "confirmations/confirm"
683 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
684 assert_response :redirect
686 assert_response :success
687 assert_template "site/welcome"
690 def test_user_create_windowslive_success
691 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
693 new_email = "newtester-windowslive@osm.org"
694 display_name = "new_tester-windowslive"
695 password = "testtest"
696 assert_difference("User.count") do
697 assert_difference("ActionMailer::Base.deliveries.size", 1) do
698 perform_enqueued_jobs do
700 :params => { :user => { :email => new_email,
701 :email_confirmation => new_email,
702 :display_name => display_name,
703 :auth_provider => "windowslive",
705 :pass_crypt_confirmation => "" } }
706 assert_response :redirect
707 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
708 post response.location
709 assert_response :redirect
710 assert_redirected_to auth_success_path(:provider => "windowslive")
712 assert_response :redirect
713 assert_redirected_to "/user/terms"
715 :params => { :user => { :email => new_email,
716 :email_confirmation => new_email,
717 :display_name => display_name,
718 :auth_provider => "windowslive",
719 :auth_uid => "123454321",
720 :pass_crypt => password,
721 :pass_crypt_confirmation => password },
722 :read_ct => 1, :read_tou => 1 }
723 assert_response :redirect
730 assert_response :success
731 assert_template "confirmations/confirm"
733 ActionMailer::Base.deliveries.clear
736 def test_user_create_windowslive_failure
737 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
739 new_email = "newtester-windowslive2@osm.org"
740 display_name = "new_tester-windowslive2"
741 assert_difference("User.count", 0) do
742 assert_difference("ActionMailer::Base.deliveries.size", 0) do
743 perform_enqueued_jobs do
745 :params => { :user => { :email => new_email,
746 :email_confirmation => new_email,
747 :display_name => display_name,
748 :auth_provider => "windowslive",
750 :pass_crypt_confirmation => "" } }
751 assert_response :redirect
752 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
753 post response.location
754 assert_response :redirect
755 assert_redirected_to auth_success_path(:provider => "windowslive")
757 assert_response :redirect
758 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/user/new")
760 assert_response :redirect
762 assert_response :success
763 assert_template "users/new"
768 ActionMailer::Base.deliveries.clear
771 def test_user_create_windowslive_redirect
772 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
774 new_email = "redirect_tester_windowslive@osm.org"
775 display_name = "redirect_tester_windowslive"
776 # nothing special about this page, just need a protected page to redirect back to.
777 referer = "/traces/mine"
778 assert_difference("User.count") do
779 assert_difference("ActionMailer::Base.deliveries.size", 1) do
780 perform_enqueued_jobs do
782 :params => { :user => { :email => new_email,
783 :email_confirmation => new_email,
784 :display_name => display_name,
785 :auth_provider => "windowslive",
787 :pass_crypt_confirmation => "" },
788 :referer => referer }
789 assert_response :redirect
790 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
791 post response.location
792 assert_response :redirect
793 assert_redirected_to auth_success_path(:provider => "windowslive")
795 assert_response :redirect
796 assert_redirected_to "/user/terms"
798 :params => { :user => { :email => new_email,
799 :email_confirmation => new_email,
800 :display_name => display_name,
801 :auth_provider => "windowslive",
802 :auth_uid => "http://localhost:1123/new.tester",
803 :pass_crypt => "testtest",
804 :pass_crypt_confirmation => "testtest" },
805 :read_ct => 1, :read_tou => 1 }
812 register_email = ActionMailer::Base.deliveries.first
814 assert_equal register_email.to.first, new_email
815 # Check that the confirm account url is correct
816 confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
817 email_text_parts(register_email).each do |part|
818 assert_match confirm_regex, part.body.to_s
820 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
823 assert_response :success
824 assert_template "confirmations/confirm"
826 ActionMailer::Base.deliveries.clear
828 # Go to the confirmation page
829 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
830 assert_response :success
831 assert_template "confirmations/confirm"
833 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
834 assert_response :redirect
836 assert_response :success
837 assert_template "site/welcome"
840 def test_user_create_github_success
841 OmniAuth.config.add_mock(:github, :uid => "123454321")
843 new_email = "newtester-github@osm.org"
844 display_name = "new_tester-github"
845 password = "testtest"
846 assert_difference("User.count") do
847 assert_difference("ActionMailer::Base.deliveries.size", 1) do
848 perform_enqueued_jobs do
850 :params => { :user => { :email => new_email,
851 :email_confirmation => new_email,
852 :display_name => display_name,
853 :auth_provider => "github",
855 :pass_crypt_confirmation => "" } }
856 assert_response :redirect
857 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
858 post response.location
859 assert_response :redirect
860 assert_redirected_to auth_success_path(:provider => "github")
862 assert_response :redirect
863 assert_redirected_to "/user/terms"
865 :params => { :user => { :email => new_email,
866 :email_confirmation => new_email,
867 :display_name => display_name,
868 :auth_provider => "github",
869 :auth_uid => "123454321",
870 :pass_crypt => password,
871 :pass_crypt_confirmation => password },
874 assert_response :redirect
881 assert_response :success
882 assert_template "confirmations/confirm"
884 ActionMailer::Base.deliveries.clear
887 def test_user_create_github_failure
888 OmniAuth.config.mock_auth[:github] = :connection_failed
890 new_email = "newtester-github2@osm.org"
891 display_name = "new_tester-github2"
892 assert_difference("User.count", 0) do
893 assert_difference("ActionMailer::Base.deliveries.size", 0) do
894 perform_enqueued_jobs do
896 :params => { :user => { :email => new_email,
897 :email_confirmation => new_email,
898 :display_name => display_name,
899 :auth_provider => "github",
901 :pass_crypt_confirmation => "" } }
902 assert_response :redirect
903 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
904 post response.location
905 assert_response :redirect
906 assert_redirected_to auth_success_path(:provider => "github")
908 assert_response :redirect
909 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
911 assert_response :redirect
913 assert_response :success
914 assert_template "users/new"
919 ActionMailer::Base.deliveries.clear
922 def test_user_create_github_redirect
923 OmniAuth.config.add_mock(:github, :uid => "123454321")
925 new_email = "redirect_tester_github@osm.org"
926 display_name = "redirect_tester_github"
927 # nothing special about this page, just need a protected page to redirect back to.
928 referer = "/traces/mine"
929 assert_difference("User.count") do
930 assert_difference("ActionMailer::Base.deliveries.size", 1) do
931 perform_enqueued_jobs do
933 :params => { :user => { :email => new_email,
934 :email_confirmation => new_email,
935 :display_name => display_name,
936 :auth_provider => "github",
938 :pass_crypt_confirmation => "" },
939 :referer => referer }
940 assert_response :redirect
941 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
942 post response.location
943 assert_response :redirect
944 assert_redirected_to auth_success_path(:provider => "github")
946 assert_response :redirect
947 assert_redirected_to "/user/terms"
949 :params => { :user => { :email => new_email,
950 :email_confirmation => new_email,
951 :display_name => display_name,
952 :auth_provider => "github",
953 :auth_uid => "http://localhost:1123/new.tester",
954 :pass_crypt => "testtest",
955 :pass_crypt_confirmation => "testtest" },
964 register_email = ActionMailer::Base.deliveries.first
966 assert_equal register_email.to.first, new_email
967 # Check that the confirm account url is correct
968 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
969 email_text_parts(register_email).each do |part|
970 assert_match confirm_regex, part.body.to_s
972 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
975 assert_response :success
976 assert_template "confirmations/confirm"
978 ActionMailer::Base.deliveries.clear
980 # Go to the confirmation page
981 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
982 assert_response :success
983 assert_template "confirmations/confirm"
985 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
986 assert_response :redirect
988 assert_response :success
989 assert_template "site/welcome"
992 def test_user_create_wikipedia_success
993 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
995 new_email = "newtester-wikipedia@osm.org"
996 display_name = "new_tester-wikipedia"
997 password = "testtest"
998 assert_difference("User.count") do
999 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1000 perform_enqueued_jobs do
1002 :params => { :user => { :email => new_email,
1003 :email_confirmation => new_email,
1004 :display_name => display_name,
1005 :auth_provider => "wikipedia",
1007 :pass_crypt_confirmation => "" } }
1008 assert_response :redirect
1009 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1010 post response.location
1011 assert_response :redirect
1012 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1014 assert_response :redirect
1015 assert_redirected_to "/user/terms"
1017 :params => { :user => { :email => new_email,
1018 :email_confirmation => new_email,
1019 :display_name => display_name,
1020 :auth_provider => "wikipedia",
1021 :auth_uid => "123454321",
1022 :pass_crypt => password,
1023 :pass_crypt_confirmation => password },
1026 assert_response :redirect
1033 assert_response :success
1034 assert_template "confirmations/confirm"
1036 ActionMailer::Base.deliveries.clear
1039 def test_user_create_wikipedia_failure
1040 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
1042 new_email = "newtester-wikipedia2@osm.org"
1043 display_name = "new_tester-wikipedia2"
1044 assert_difference("User.count", 0) do
1045 assert_difference("ActionMailer::Base.deliveries.size", 0) do
1046 perform_enqueued_jobs do
1048 :params => { :user => { :email => new_email,
1049 :email_confirmation => new_email,
1050 :display_name => display_name,
1051 :auth_provider => "wikipedia",
1053 :pass_crypt_confirmation => "" } }
1054 assert_response :redirect
1055 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1056 post response.location
1057 assert_response :redirect
1058 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1060 assert_response :redirect
1061 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
1063 assert_response :redirect
1065 assert_response :success
1066 assert_template "users/new"
1071 ActionMailer::Base.deliveries.clear
1074 def test_user_create_wikipedia_redirect
1075 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
1077 new_email = "redirect_tester_wikipedia@osm.org"
1078 display_name = "redirect_tester_wikipedia"
1079 # nothing special about this page, just need a protected page to redirect back to.
1080 referer = "/traces/mine"
1081 assert_difference("User.count") do
1082 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1083 perform_enqueued_jobs do
1085 :params => { :user => { :email => new_email,
1086 :email_confirmation => new_email,
1087 :display_name => display_name,
1088 :auth_provider => "wikipedia",
1090 :pass_crypt_confirmation => "" },
1091 :referer => referer }
1092 assert_response :redirect
1093 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1094 post response.location
1095 assert_response :redirect
1096 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1098 assert_response :redirect
1099 assert_redirected_to "/user/terms"
1101 :params => { :user => { :email => new_email,
1102 :email_confirmation => new_email,
1103 :display_name => display_name,
1104 :auth_provider => "wikipedia",
1105 :auth_uid => "http://localhost:1123/new.tester",
1106 :pass_crypt => "testtest",
1107 :pass_crypt_confirmation => "testtest" },
1116 register_email = ActionMailer::Base.deliveries.first
1118 assert_equal register_email.to.first, new_email
1119 # Check that the confirm account url is correct
1120 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
1121 email_text_parts(register_email).each do |part|
1122 assert_match confirm_regex, part.body.to_s
1124 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
1127 assert_response :success
1128 assert_template "confirmations/confirm"
1130 ActionMailer::Base.deliveries.clear
1132 # Go to the confirmation page
1133 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1134 assert_response :success
1135 assert_template "confirmations/confirm"
1137 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1138 assert_response :redirect
1140 assert_response :success
1141 assert_template "site/welcome"