3 class UserCreationTest < ActionDispatch::IntegrationTest
7 OmniAuth.config.test_mode = true
9 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
15 OmniAuth.config.mock_auth[:openid] = nil
16 OmniAuth.config.mock_auth[:google] = nil
17 OmniAuth.config.mock_auth[:facebook] = nil
18 OmniAuth.config.mock_auth[:windowslive] = nil
19 OmniAuth.config.mock_auth[:github] = nil
20 OmniAuth.config.mock_auth[:wikipedia] = nil
21 OmniAuth.config.test_mode = false
24 def test_create_user_form
25 I18n.available_locales.each do |locale|
27 get "/user/new", :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
29 assert_response :success
30 assert_template "users/new"
34 def test_user_create_submit_duplicate_email
35 Locale.available.each do |locale|
36 dup_email = create(:user).email
37 display_name = "#{locale}_new_tester"
38 assert_difference("User.count", 0) do
39 assert_difference("ActionMailer::Base.deliveries.size", 0) do
40 perform_enqueued_jobs do
42 :params => { :user => { :email => dup_email,
43 :email_confirmation => dup_email,
44 :display_name => display_name,
45 :pass_crypt => "testtest",
46 :pass_crypt_confirmation => "testtest" } },
47 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
51 assert_response :success
52 assert_template "users/new"
53 assert_equal locale.to_s, response.headers["Content-Language"]
55 assert_select "form > div.form-group > input.is-invalid#user_email"
56 assert_no_missing_translations
60 def test_user_create_submit_duplicate_username
61 I18n.available_locales.each do |locale|
62 dup_display_name = create(:user).display_name
63 email = "#{locale}_new_tester"
64 assert_difference("User.count", 0) do
65 assert_difference("ActionMailer::Base.deliveries.size", 0) do
66 perform_enqueued_jobs do
68 :params => { :user => { :email => email,
69 :email_confirmation => email,
70 :display_name => dup_display_name,
71 :pass_crypt => "testtest",
72 :pass_crypt_confirmation => "testtest" } },
73 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
77 assert_response :success
78 assert_template "users/new"
79 assert_select "form > div.form-group > input.is-invalid#user_display_name"
80 assert_no_missing_translations
84 def test_user_create_success
85 I18n.available_locales.each do |locale|
86 new_email = "#{locale}newtester@osm.org"
87 display_name = "#{locale}_new_tester"
89 assert_difference("User.count", 0) do
90 assert_difference("ActionMailer::Base.deliveries.size", 0) do
91 perform_enqueued_jobs do
93 :params => { :user => { :email => new_email,
94 :email_confirmation => new_email,
95 :display_name => display_name,
96 :pass_crypt => "testtest",
97 :pass_crypt_confirmation => "testtest" } }
102 assert_redirected_to "/user/terms"
104 assert_difference("User.count") do
105 assert_difference("ActionMailer::Base.deliveries.size", 1) do
106 perform_enqueued_jobs do
108 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s },
109 :params => { :read_ct => 1, :read_tou => 1 }
116 register_email = ActionMailer::Base.deliveries.first
118 assert_equal register_email.to.first, new_email
119 # Check that the confirm account url is correct
120 assert_match(/#{@url}/, register_email.body.to_s)
123 assert_response :success
124 assert_template "confirmations/confirm"
126 ActionMailer::Base.deliveries.clear
130 def test_user_create_no_tou_failure
131 I18n.available_locales.each do |locale|
132 new_email = "#{locale}newtester@osm.org"
133 display_name = "#{locale}_new_tester"
135 assert_difference("User.count", 0) do
136 assert_difference("ActionMailer::Base.deliveries.size", 0) do
137 perform_enqueued_jobs do
139 :params => { :user => { :email => new_email,
140 :email_confirmation => new_email,
141 :display_name => display_name,
142 :pass_crypt => "testtest",
143 :pass_crypt_confirmation => "testtest" } }
148 assert_redirected_to "/user/terms"
150 perform_enqueued_jobs do
152 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
153 assert_redirected_to "/user/terms"
156 ActionMailer::Base.deliveries.clear
160 # Check that the user can successfully recover their password
161 def test_lost_password_recovery_success
162 # Open the lost password form
163 # Submit the lost password form
165 # Submit the reset password token
166 # Check that the password has changed, and the user can login
169 def test_user_create_redirect
170 new_email = "redirect_tester@osm.org"
171 display_name = "redirect_tester"
172 password = "testtest"
173 # nothing special about this page, just need a protected page to redirect back to.
174 referer = "/traces/mine"
175 assert_difference("User.count") do
176 assert_difference("ActionMailer::Base.deliveries.size", 1) do
177 perform_enqueued_jobs do
179 :params => { :user => { :email => new_email,
180 :email_confirmation => new_email,
181 :display_name => display_name,
182 :pass_crypt => password,
183 :pass_crypt_confirmation => password },
184 :referer => referer }
185 assert_redirected_to "/user/terms"
187 :params => { :user => { :email => new_email,
188 :email_confirmation => new_email,
189 :display_name => display_name,
190 :pass_crypt => password,
191 :pass_crypt_confirmation => password },
192 :read_ct => 1, :read_tou => 1 }
199 register_email = ActionMailer::Base.deliveries.first
201 assert_equal register_email.to.first, new_email
202 # Check that the confirm account url is correct
203 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
204 email_text_parts(register_email).each do |part|
205 assert_match confirm_regex, part.body.to_s
207 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
210 assert_response :success
211 assert_template "confirmations/confirm"
213 ActionMailer::Base.deliveries.clear
215 # Go to the confirmation page
216 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
217 assert_response :success
218 assert_template "confirmations/confirm"
220 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
221 assert_response :redirect
223 assert_response :success
224 assert_template "site/welcome"
227 def test_user_create_openid_success
228 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
230 new_email = "newtester-openid@osm.org"
231 display_name = "new_tester-openid"
232 password = "testtest"
233 assert_difference("User.count") do
234 assert_difference("ActionMailer::Base.deliveries.size", 1) do
235 perform_enqueued_jobs do
237 :params => { :user => { :email => new_email,
238 :email_confirmation => new_email,
239 :display_name => display_name,
240 :auth_provider => "openid",
241 :auth_uid => "http://localhost:1123/new.tester",
243 :pass_crypt_confirmation => "" } }
244 assert_response :redirect
245 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
246 post response.location
247 assert_response :redirect
248 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
250 assert_response :redirect
251 assert_redirected_to "/user/terms"
253 :params => { :user => { :email => new_email,
254 :email_confirmation => new_email,
255 :display_name => display_name,
256 :auth_provider => "openid",
257 :auth_uid => "http://localhost:1123/new.tester",
258 :pass_crypt => password,
259 :pass_crypt_confirmation => password },
260 :read_ct => 1, :read_tou => 1 }
261 assert_response :redirect
268 assert_response :success
269 assert_template "confirmations/confirm"
271 ActionMailer::Base.deliveries.clear
274 def test_user_create_openid_failure
275 OmniAuth.config.mock_auth[:openid] = :connection_failed
277 new_email = "newtester-openid2@osm.org"
278 display_name = "new_tester-openid2"
279 assert_difference("User.count", 0) do
280 assert_difference("ActionMailer::Base.deliveries.size", 0) do
281 perform_enqueued_jobs do
283 :params => { :user => { :email => new_email,
284 :email_confirmation => new_email,
285 :display_name => display_name,
286 :auth_provider => "openid",
287 :auth_uid => "http://localhost:1123/new.tester",
289 :pass_crypt_confirmation => "" } }
290 assert_response :redirect
291 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
292 post response.location
293 assert_response :redirect
294 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
296 assert_response :redirect
297 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
299 assert_response :redirect
301 assert_response :success
302 assert_template "users/new"
307 ActionMailer::Base.deliveries.clear
310 def test_user_create_openid_redirect
311 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
313 new_email = "redirect_tester_openid@osm.org"
314 display_name = "redirect_tester_openid"
315 # nothing special about this page, just need a protected page to redirect back to.
316 referer = "/traces/mine"
317 assert_difference("User.count") do
318 assert_difference("ActionMailer::Base.deliveries.size", 1) do
319 perform_enqueued_jobs do
321 :params => { :user => { :email => new_email,
322 :email_confirmation => new_email,
323 :display_name => display_name,
324 :auth_provider => "openid",
325 :auth_uid => "http://localhost:1123/new.tester",
327 :pass_crypt_confirmation => "" },
328 :referer => referer }
329 assert_response :redirect
330 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
331 post response.location
332 assert_response :redirect
333 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
335 assert_response :redirect
336 assert_redirected_to "/user/terms"
338 :params => { :user => { :email => new_email,
339 :email_confirmation => new_email,
340 :display_name => display_name,
341 :auth_provider => "openid",
342 :auth_uid => "http://localhost:1123/new.tester",
343 :pass_crypt => "testtest",
344 :pass_crypt_confirmation => "testtest" },
345 :read_ct => 1, :read_tou => 1 }
352 register_email = ActionMailer::Base.deliveries.first
354 assert_equal register_email.to.first, new_email
355 # Check that the confirm account url is correct
356 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
357 email_text_parts(register_email).each do |part|
358 assert_match confirm_regex, part.body.to_s
360 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
363 assert_response :success
364 assert_template "confirmations/confirm"
366 ActionMailer::Base.deliveries.clear
368 # Go to the confirmation page
369 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
370 assert_response :success
371 assert_template "confirmations/confirm"
373 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
374 assert_response :redirect
376 assert_response :success
377 assert_template "site/welcome"
380 def test_user_create_google_success
381 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
382 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
385 new_email = "newtester-google@osm.org"
386 display_name = "new_tester-google"
387 password = "testtest"
388 assert_difference("User.count") do
389 assert_difference("ActionMailer::Base.deliveries.size", 1) do
390 perform_enqueued_jobs do
392 :params => { :user => { :email => new_email,
393 :email_confirmation => new_email,
394 :display_name => display_name,
395 :auth_provider => "google",
397 :pass_crypt_confirmation => "" } }
398 assert_response :redirect
399 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
400 post response.location
401 assert_response :redirect
402 assert_redirected_to auth_success_path(:provider => "google")
404 assert_response :redirect
405 assert_redirected_to "/user/terms"
407 :params => { :user => { :email => new_email,
408 :email_confirmation => new_email,
409 :display_name => display_name,
410 :auth_provider => "google",
411 :auth_uid => "123454321",
412 :pass_crypt => password,
413 :pass_crypt_confirmation => password },
414 :read_ct => 1, :read_tou => 1 }
415 assert_response :redirect
422 assert_response :success
423 assert_template "confirmations/confirm"
425 ActionMailer::Base.deliveries.clear
428 def test_user_create_google_failure
429 OmniAuth.config.mock_auth[:google] = :connection_failed
431 new_email = "newtester-google2@osm.org"
432 display_name = "new_tester-google2"
433 assert_difference("User.count", 0) do
434 assert_difference("ActionMailer::Base.deliveries.size", 0) do
435 perform_enqueued_jobs do
437 :params => { :user => { :email => new_email,
438 :email_confirmation => new_email,
439 :display_name => display_name,
440 :auth_provider => "google",
442 :pass_crypt_confirmation => "" } }
443 assert_response :redirect
444 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
445 post response.location
446 assert_response :redirect
447 assert_redirected_to auth_success_path(:provider => "google")
449 assert_response :redirect
450 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
452 assert_response :redirect
454 assert_response :success
455 assert_template "users/new"
460 ActionMailer::Base.deliveries.clear
463 def test_user_create_google_redirect
464 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
465 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
468 new_email = "redirect_tester_google@osm.org"
469 display_name = "redirect_tester_google"
470 # nothing special about this page, just need a protected page to redirect back to.
471 referer = "/traces/mine"
472 assert_difference("User.count") do
473 assert_difference("ActionMailer::Base.deliveries.size", 1) do
474 perform_enqueued_jobs do
476 :params => { :user => { :email => new_email,
477 :email_confirmation => new_email,
478 :display_name => display_name,
479 :auth_provider => "google",
481 :pass_crypt_confirmation => "" },
482 :referer => referer }
483 assert_response :redirect
484 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
485 post response.location
486 assert_response :redirect
487 assert_redirected_to auth_success_path(:provider => "google")
489 assert_response :redirect
490 assert_redirected_to "/user/terms"
492 :params => { :user => { :email => new_email,
493 :email_confirmation => new_email,
494 :display_name => display_name,
495 :auth_provider => "google",
496 :auth_uid => "http://localhost:1123/new.tester",
497 :pass_crypt => "testtest",
498 :pass_crypt_confirmation => "testtest" },
499 :read_ct => 1, :read_tou => 1 }
506 register_email = ActionMailer::Base.deliveries.first
508 assert_equal register_email.to.first, new_email
509 # Check that the confirm account url is correct
510 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
511 email_text_parts(register_email).each do |part|
512 assert_match confirm_regex, part.body.to_s
514 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
517 assert_response :success
518 assert_template "confirmations/confirm"
520 ActionMailer::Base.deliveries.clear
522 # Go to the confirmation page
523 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
524 assert_response :success
525 assert_template "confirmations/confirm"
527 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
528 assert_response :redirect
530 assert_response :success
531 assert_template "site/welcome"
534 def test_user_create_facebook_success
535 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
537 new_email = "newtester-facebook@osm.org"
538 display_name = "new_tester-facebook"
539 password = "testtest"
540 assert_difference("User.count") do
541 assert_difference("ActionMailer::Base.deliveries.size", 1) do
542 perform_enqueued_jobs do
544 :params => { :user => { :email => new_email,
545 :email_confirmation => new_email,
546 :display_name => display_name,
547 :auth_provider => "facebook",
549 :pass_crypt_confirmation => "" } }
550 assert_response :redirect
551 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
552 post response.location
553 assert_response :redirect
554 assert_redirected_to auth_success_path(:provider => "facebook")
556 assert_response :redirect
557 assert_redirected_to "/user/terms"
559 :params => { :user => { :email => new_email,
560 :email_confirmation => new_email,
561 :display_name => display_name,
562 :auth_provider => "facebook",
563 :auth_uid => "123454321",
564 :pass_crypt => password,
565 :pass_crypt_confirmation => password },
566 :read_ct => 1, :read_tou => 1 }
567 assert_response :redirect
574 assert_response :success
575 assert_template "confirmations/confirm"
577 ActionMailer::Base.deliveries.clear
580 def test_user_create_facebook_failure
581 OmniAuth.config.mock_auth[:facebook] = :connection_failed
583 new_email = "newtester-facebook2@osm.org"
584 display_name = "new_tester-facebook2"
585 assert_difference("User.count", 0) do
586 assert_difference("ActionMailer::Base.deliveries.size", 0) do
587 perform_enqueued_jobs do
589 :params => { :user => { :email => new_email,
590 :email_confirmation => new_email,
591 :display_name => display_name,
592 :auth_provider => "facebook",
594 :pass_crypt_confirmation => "" } }
595 assert_response :redirect
596 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
597 post response.location
598 assert_response :redirect
599 assert_redirected_to auth_success_path(:provider => "facebook")
601 assert_response :redirect
602 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
604 assert_response :redirect
606 assert_response :success
607 assert_template "users/new"
612 ActionMailer::Base.deliveries.clear
615 def test_user_create_facebook_redirect
616 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
618 new_email = "redirect_tester_facebook@osm.org"
619 display_name = "redirect_tester_facebook"
620 # nothing special about this page, just need a protected page to redirect back to.
621 referer = "/traces/mine"
622 assert_difference("User.count") do
623 assert_difference("ActionMailer::Base.deliveries.size", 1) do
624 perform_enqueued_jobs do
626 :params => { :user => { :email => new_email,
627 :email_confirmation => new_email,
628 :display_name => display_name,
629 :auth_provider => "facebook",
631 :pass_crypt_confirmation => "" },
632 :referer => referer }
633 assert_response :redirect
634 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
635 post response.location
636 assert_response :redirect
637 assert_redirected_to auth_success_path(:provider => "facebook")
639 assert_response :redirect
640 assert_redirected_to "/user/terms"
642 :params => { :user => { :email => new_email,
643 :email_confirmation => new_email,
644 :display_name => display_name,
645 :auth_provider => "facebook",
646 :auth_uid => "http://localhost:1123/new.tester",
647 :pass_crypt => "testtest",
648 :pass_crypt_confirmation => "testtest" },
649 :read_ct => 1, :read_tou => 1 }
656 register_email = ActionMailer::Base.deliveries.first
658 assert_equal register_email.to.first, new_email
659 # Check that the confirm account url is correct
660 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
661 email_text_parts(register_email).each do |part|
662 assert_match confirm_regex, part.body.to_s
664 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
667 assert_response :success
668 assert_template "confirmations/confirm"
670 ActionMailer::Base.deliveries.clear
672 # Go to the confirmation page
673 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
674 assert_response :success
675 assert_template "confirmations/confirm"
677 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
678 assert_response :redirect
680 assert_response :success
681 assert_template "site/welcome"
684 def test_user_create_windowslive_success
685 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
687 new_email = "newtester-windowslive@osm.org"
688 display_name = "new_tester-windowslive"
689 password = "testtest"
690 assert_difference("User.count") do
691 assert_difference("ActionMailer::Base.deliveries.size", 1) do
692 perform_enqueued_jobs do
694 :params => { :user => { :email => new_email,
695 :email_confirmation => new_email,
696 :display_name => display_name,
697 :auth_provider => "windowslive",
699 :pass_crypt_confirmation => "" } }
700 assert_response :redirect
701 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
702 post response.location
703 assert_response :redirect
704 assert_redirected_to auth_success_path(:provider => "windowslive")
706 assert_response :redirect
707 assert_redirected_to "/user/terms"
709 :params => { :user => { :email => new_email,
710 :email_confirmation => new_email,
711 :display_name => display_name,
712 :auth_provider => "windowslive",
713 :auth_uid => "123454321",
714 :pass_crypt => password,
715 :pass_crypt_confirmation => password },
716 :read_ct => 1, :read_tou => 1 }
717 assert_response :redirect
724 assert_response :success
725 assert_template "confirmations/confirm"
727 ActionMailer::Base.deliveries.clear
730 def test_user_create_windowslive_failure
731 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
733 new_email = "newtester-windowslive2@osm.org"
734 display_name = "new_tester-windowslive2"
735 assert_difference("User.count", 0) do
736 assert_difference("ActionMailer::Base.deliveries.size", 0) do
737 perform_enqueued_jobs do
739 :params => { :user => { :email => new_email,
740 :email_confirmation => new_email,
741 :display_name => display_name,
742 :auth_provider => "windowslive",
744 :pass_crypt_confirmation => "" } }
745 assert_response :redirect
746 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
747 post response.location
748 assert_response :redirect
749 assert_redirected_to auth_success_path(:provider => "windowslive")
751 assert_response :redirect
752 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/user/new")
754 assert_response :redirect
756 assert_response :success
757 assert_template "users/new"
762 ActionMailer::Base.deliveries.clear
765 def test_user_create_windowslive_redirect
766 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
768 new_email = "redirect_tester_windowslive@osm.org"
769 display_name = "redirect_tester_windowslive"
770 # nothing special about this page, just need a protected page to redirect back to.
771 referer = "/traces/mine"
772 assert_difference("User.count") do
773 assert_difference("ActionMailer::Base.deliveries.size", 1) do
774 perform_enqueued_jobs do
776 :params => { :user => { :email => new_email,
777 :email_confirmation => new_email,
778 :display_name => display_name,
779 :auth_provider => "windowslive",
781 :pass_crypt_confirmation => "" },
782 :referer => referer }
783 assert_response :redirect
784 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
785 post response.location
786 assert_response :redirect
787 assert_redirected_to auth_success_path(:provider => "windowslive")
789 assert_response :redirect
790 assert_redirected_to "/user/terms"
792 :params => { :user => { :email => new_email,
793 :email_confirmation => new_email,
794 :display_name => display_name,
795 :auth_provider => "windowslive",
796 :auth_uid => "http://localhost:1123/new.tester",
797 :pass_crypt => "testtest",
798 :pass_crypt_confirmation => "testtest" },
799 :read_ct => 1, :read_tou => 1 }
806 register_email = ActionMailer::Base.deliveries.first
808 assert_equal register_email.to.first, new_email
809 # Check that the confirm account url is correct
810 confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
811 email_text_parts(register_email).each do |part|
812 assert_match confirm_regex, part.body.to_s
814 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
817 assert_response :success
818 assert_template "confirmations/confirm"
820 ActionMailer::Base.deliveries.clear
822 # Go to the confirmation page
823 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
824 assert_response :success
825 assert_template "confirmations/confirm"
827 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
828 assert_response :redirect
830 assert_response :success
831 assert_template "site/welcome"
834 def test_user_create_github_success
835 OmniAuth.config.add_mock(:github, :uid => "123454321")
837 new_email = "newtester-github@osm.org"
838 display_name = "new_tester-github"
839 password = "testtest"
840 assert_difference("User.count") do
841 assert_difference("ActionMailer::Base.deliveries.size", 1) do
842 perform_enqueued_jobs do
844 :params => { :user => { :email => new_email,
845 :email_confirmation => new_email,
846 :display_name => display_name,
847 :auth_provider => "github",
849 :pass_crypt_confirmation => "" } }
850 assert_response :redirect
851 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
852 post response.location
853 assert_response :redirect
854 assert_redirected_to auth_success_path(:provider => "github")
856 assert_response :redirect
857 assert_redirected_to "/user/terms"
859 :params => { :user => { :email => new_email,
860 :email_confirmation => new_email,
861 :display_name => display_name,
862 :auth_provider => "github",
863 :auth_uid => "123454321",
864 :pass_crypt => password,
865 :pass_crypt_confirmation => password },
868 assert_response :redirect
875 assert_response :success
876 assert_template "confirmations/confirm"
878 ActionMailer::Base.deliveries.clear
881 def test_user_create_github_failure
882 OmniAuth.config.mock_auth[:github] = :connection_failed
884 new_email = "newtester-github2@osm.org"
885 display_name = "new_tester-github2"
886 assert_difference("User.count", 0) do
887 assert_difference("ActionMailer::Base.deliveries.size", 0) do
888 perform_enqueued_jobs do
890 :params => { :user => { :email => new_email,
891 :email_confirmation => new_email,
892 :display_name => display_name,
893 :auth_provider => "github",
895 :pass_crypt_confirmation => "" } }
896 assert_response :redirect
897 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
898 post response.location
899 assert_response :redirect
900 assert_redirected_to auth_success_path(:provider => "github")
902 assert_response :redirect
903 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
905 assert_response :redirect
907 assert_response :success
908 assert_template "users/new"
913 ActionMailer::Base.deliveries.clear
916 def test_user_create_github_redirect
917 OmniAuth.config.add_mock(:github, :uid => "123454321")
919 new_email = "redirect_tester_github@osm.org"
920 display_name = "redirect_tester_github"
921 # nothing special about this page, just need a protected page to redirect back to.
922 referer = "/traces/mine"
923 assert_difference("User.count") do
924 assert_difference("ActionMailer::Base.deliveries.size", 1) do
925 perform_enqueued_jobs do
927 :params => { :user => { :email => new_email,
928 :email_confirmation => new_email,
929 :display_name => display_name,
930 :auth_provider => "github",
932 :pass_crypt_confirmation => "" },
933 :referer => referer }
934 assert_response :redirect
935 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
936 post response.location
937 assert_response :redirect
938 assert_redirected_to auth_success_path(:provider => "github")
940 assert_response :redirect
941 assert_redirected_to "/user/terms"
943 :params => { :user => { :email => new_email,
944 :email_confirmation => new_email,
945 :display_name => display_name,
946 :auth_provider => "github",
947 :auth_uid => "http://localhost:1123/new.tester",
948 :pass_crypt => "testtest",
949 :pass_crypt_confirmation => "testtest" },
958 register_email = ActionMailer::Base.deliveries.first
960 assert_equal register_email.to.first, new_email
961 # Check that the confirm account url is correct
962 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
963 email_text_parts(register_email).each do |part|
964 assert_match confirm_regex, part.body.to_s
966 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
969 assert_response :success
970 assert_template "confirmations/confirm"
972 ActionMailer::Base.deliveries.clear
974 # Go to the confirmation page
975 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
976 assert_response :success
977 assert_template "confirmations/confirm"
979 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
980 assert_response :redirect
982 assert_response :success
983 assert_template "site/welcome"
986 def test_user_create_wikipedia_success
987 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
989 new_email = "newtester-wikipedia@osm.org"
990 display_name = "new_tester-wikipedia"
991 password = "testtest"
992 assert_difference("User.count") do
993 assert_difference("ActionMailer::Base.deliveries.size", 1) do
994 perform_enqueued_jobs do
996 :params => { :user => { :email => new_email,
997 :email_confirmation => new_email,
998 :display_name => display_name,
999 :auth_provider => "wikipedia",
1001 :pass_crypt_confirmation => "" } }
1002 assert_response :redirect
1003 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1004 post response.location
1005 assert_response :redirect
1006 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1008 assert_response :redirect
1009 assert_redirected_to "/user/terms"
1011 :params => { :user => { :email => new_email,
1012 :email_confirmation => new_email,
1013 :display_name => display_name,
1014 :auth_provider => "wikipedia",
1015 :auth_uid => "123454321",
1016 :pass_crypt => password,
1017 :pass_crypt_confirmation => password },
1020 assert_response :redirect
1027 assert_response :success
1028 assert_template "confirmations/confirm"
1030 ActionMailer::Base.deliveries.clear
1033 def test_user_create_wikipedia_failure
1034 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
1036 new_email = "newtester-wikipedia2@osm.org"
1037 display_name = "new_tester-wikipedia2"
1038 assert_difference("User.count", 0) do
1039 assert_difference("ActionMailer::Base.deliveries.size", 0) do
1040 perform_enqueued_jobs do
1042 :params => { :user => { :email => new_email,
1043 :email_confirmation => new_email,
1044 :display_name => display_name,
1045 :auth_provider => "wikipedia",
1047 :pass_crypt_confirmation => "" } }
1048 assert_response :redirect
1049 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1050 post response.location
1051 assert_response :redirect
1052 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1054 assert_response :redirect
1055 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
1057 assert_response :redirect
1059 assert_response :success
1060 assert_template "users/new"
1065 ActionMailer::Base.deliveries.clear
1068 def test_user_create_wikipedia_redirect
1069 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
1071 new_email = "redirect_tester_wikipedia@osm.org"
1072 display_name = "redirect_tester_wikipedia"
1073 # nothing special about this page, just need a protected page to redirect back to.
1074 referer = "/traces/mine"
1075 assert_difference("User.count") do
1076 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1077 perform_enqueued_jobs do
1079 :params => { :user => { :email => new_email,
1080 :email_confirmation => new_email,
1081 :display_name => display_name,
1082 :auth_provider => "wikipedia",
1084 :pass_crypt_confirmation => "" },
1085 :referer => referer }
1086 assert_response :redirect
1087 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1088 post response.location
1089 assert_response :redirect
1090 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1092 assert_response :redirect
1093 assert_redirected_to "/user/terms"
1095 :params => { :user => { :email => new_email,
1096 :email_confirmation => new_email,
1097 :display_name => display_name,
1098 :auth_provider => "wikipedia",
1099 :auth_uid => "http://localhost:1123/new.tester",
1100 :pass_crypt => "testtest",
1101 :pass_crypt_confirmation => "testtest" },
1110 register_email = ActionMailer::Base.deliveries.first
1112 assert_equal register_email.to.first, new_email
1113 # Check that the confirm account url is correct
1114 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
1115 email_text_parts(register_email).each do |part|
1116 assert_match confirm_regex, part.body.to_s
1118 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
1121 assert_response :success
1122 assert_template "confirmations/confirm"
1124 ActionMailer::Base.deliveries.clear
1126 # Go to the confirmation page
1127 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1128 assert_response :success
1129 assert_template "confirmations/confirm"
1131 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
1132 assert_response :redirect
1134 assert_response :success
1135 assert_template "site/welcome"