3 class UserCreationTest < ActionDispatch::IntegrationTest
5 OmniAuth.config.test_mode = true
7 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
11 OmniAuth.config.mock_auth[:openid] = nil
12 OmniAuth.config.mock_auth[:google] = nil
13 OmniAuth.config.mock_auth[:facebook] = nil
14 OmniAuth.config.mock_auth[:microsoft] = nil
15 OmniAuth.config.mock_auth[:github] = nil
16 OmniAuth.config.mock_auth[:wikipedia] = nil
17 OmniAuth.config.test_mode = false
20 def test_create_user_form
23 assert_response :success
24 assert_template "users/new"
27 def test_user_create_submit_duplicate_email
28 dup_email = create(:user).email
29 display_name = "new_tester"
30 assert_difference("User.count", 0) do
31 assert_difference("ActionMailer::Base.deliveries.size", 0) do
32 perform_enqueued_jobs do
34 :params => { :user => { :email => dup_email,
35 :email_confirmation => dup_email,
36 :display_name => display_name,
37 :pass_crypt => "testtest",
38 :pass_crypt_confirmation => "testtest" } }
42 assert_response :success
43 assert_template "users/new"
45 assert_select "form > div > input.is-invalid#user_email"
48 def test_user_create_submit_duplicate_username
49 dup_display_name = create(:user).display_name
51 assert_difference("User.count", 0) do
52 assert_difference("ActionMailer::Base.deliveries.size", 0) do
53 perform_enqueued_jobs do
55 :params => { :user => { :email => email,
56 :email_confirmation => email,
57 :display_name => dup_display_name,
58 :pass_crypt => "testtest",
59 :pass_crypt_confirmation => "testtest" } }
63 assert_response :success
64 assert_template "users/new"
65 assert_select "form > div > input.is-invalid#user_display_name"
68 def test_user_create_submit_mismatched_passwords
69 email = "newtester@osm.org"
70 display_name = "new_tester"
71 assert_difference("User.count", 0) do
72 assert_difference("ActionMailer::Base.deliveries.size", 0) do
73 perform_enqueued_jobs do
75 :params => { :user => { :email => email,
76 :email_confirmation => email,
77 :display_name => display_name,
78 :pass_crypt => "testtest",
79 :pass_crypt_confirmation => "blahblah" } }
83 assert_response :success
84 assert_template "users/new"
85 assert_select "form > div > input.is-invalid#user_pass_crypt_confirmation"
88 def test_user_create_success
89 new_email = "newtester@osm.org"
90 display_name = "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 :params => { :read_ct => 1, :read_tou => 1 }
117 assert_response :success
118 assert_template "confirmations/confirm"
120 user = User.find_by(:email => "newtester@osm.org")
122 assert_not_predicate user, :active?
124 register_email = ActionMailer::Base.deliveries.first
125 assert_equal register_email.to.first, new_email
126 found_confirmation_url = register_email.parts.first.parts.first.to_s =~ %r{\shttp://test.host(/\S+)\s}
127 assert found_confirmation_url
128 confirmation_url = Regexp.last_match(1)
129 ActionMailer::Base.deliveries.clear
131 post confirmation_url
133 assert_redirected_to welcome_path
136 assert_predicate user, :active?
138 assert_equal user, User.authenticate(:username => new_email, :password => "testtest")
141 def test_user_create_no_tou_failure
142 new_email = "#newtester@osm.org"
143 display_name = "new_tester"
145 assert_difference("User.count", 0) do
146 assert_difference("ActionMailer::Base.deliveries.size", 0) do
147 perform_enqueued_jobs do
149 :params => { :user => { :email => new_email,
150 :email_confirmation => new_email,
151 :display_name => display_name,
152 :pass_crypt => "testtest",
153 :pass_crypt_confirmation => "testtest" } }
158 assert_redirected_to "/user/terms"
160 perform_enqueued_jobs do
162 assert_redirected_to "/user/terms"
165 ActionMailer::Base.deliveries.clear
168 # Check that the user can successfully recover their password
169 def test_lost_password_recovery_success
170 # Open the lost password form
171 # Submit the lost password form
173 # Submit the reset password token
174 # Check that the password has changed, and the user can login
177 def test_user_create_redirect
178 new_email = "redirect_tester@osm.org"
179 display_name = "redirect_tester"
180 password = "testtest"
181 # nothing special about this page, just need a protected page to redirect back to.
182 referer = "/traces/mine"
183 assert_difference("User.count") do
184 assert_difference("ActionMailer::Base.deliveries.size", 1) do
185 perform_enqueued_jobs do
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 :referer => referer }
193 assert_redirected_to "/user/terms"
195 :params => { :user => { :email => new_email,
196 :email_confirmation => new_email,
197 :display_name => display_name,
198 :pass_crypt => password,
199 :pass_crypt_confirmation => password },
200 :read_ct => 1, :read_tou => 1 }
207 register_email = ActionMailer::Base.deliveries.first
209 assert_equal register_email.to.first, new_email
210 # Check that the confirm account url is correct
211 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
212 email_text_parts(register_email).each do |part|
213 assert_match confirm_regex, part.body.to_s
215 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
218 assert_response :success
219 assert_template "confirmations/confirm"
221 ActionMailer::Base.deliveries.clear
223 # Go to the confirmation page
224 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
225 assert_response :success
226 assert_template "confirmations/confirm"
228 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
229 assert_response :redirect
231 assert_response :success
232 assert_template "site/welcome"
235 def test_user_create_openid_success
236 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
238 new_email = "newtester-openid@osm.org"
239 display_name = "new_tester-openid"
240 password = "testtest"
241 assert_difference("User.count") do
242 assert_difference("ActionMailer::Base.deliveries.size", 1) do
243 perform_enqueued_jobs do
245 :params => { :user => { :email => new_email,
246 :email_confirmation => new_email,
247 :display_name => display_name,
248 :auth_provider => "openid",
249 :auth_uid => "http://localhost:1123/new.tester",
251 :pass_crypt_confirmation => "" } }
252 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
253 post response.location
254 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
256 assert_redirected_to "/user/terms"
258 :params => { :user => { :email => new_email,
259 :email_confirmation => new_email,
260 :display_name => display_name,
261 :auth_provider => "openid",
262 :auth_uid => "http://localhost:1123/new.tester",
263 :pass_crypt => password,
264 :pass_crypt_confirmation => password },
265 :read_ct => 1, :read_tou => 1 }
266 assert_response :redirect
273 assert_response :success
274 assert_template "confirmations/confirm"
276 ActionMailer::Base.deliveries.clear
279 def test_user_create_openid_failure
280 OmniAuth.config.mock_auth[:openid] = :connection_failed
282 new_email = "newtester-openid2@osm.org"
283 display_name = "new_tester-openid2"
284 assert_difference("User.count", 0) do
285 assert_difference("ActionMailer::Base.deliveries.size", 0) do
286 perform_enqueued_jobs do
288 :params => { :user => { :email => new_email,
289 :email_confirmation => new_email,
290 :display_name => display_name,
291 :auth_provider => "openid",
292 :auth_uid => "http://localhost:1123/new.tester",
294 :pass_crypt_confirmation => "" } }
295 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
296 post response.location
297 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
299 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
301 assert_response :redirect
303 assert_response :success
304 assert_template "users/new"
309 ActionMailer::Base.deliveries.clear
312 def test_user_create_openid_redirect
313 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
315 new_email = "redirect_tester_openid@osm.org"
316 display_name = "redirect_tester_openid"
317 # nothing special about this page, just need a protected page to redirect back to.
318 referer = "/traces/mine"
319 assert_difference("User.count") do
320 assert_difference("ActionMailer::Base.deliveries.size", 1) do
321 perform_enqueued_jobs do
323 :params => { :user => { :email => new_email,
324 :email_confirmation => new_email,
325 :display_name => display_name,
326 :auth_provider => "openid",
327 :auth_uid => "http://localhost:1123/new.tester",
329 :pass_crypt_confirmation => "" },
330 :referer => referer }
331 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
332 post response.location
333 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
335 assert_redirected_to "/user/terms"
337 :params => { :user => { :email => new_email,
338 :email_confirmation => new_email,
339 :display_name => display_name,
340 :auth_provider => "openid",
341 :auth_uid => "http://localhost:1123/new.tester",
342 :pass_crypt => "testtest",
343 :pass_crypt_confirmation => "testtest" },
344 :read_ct => 1, :read_tou => 1 }
351 register_email = ActionMailer::Base.deliveries.first
353 assert_equal register_email.to.first, new_email
354 # Check that the confirm account url is correct
355 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
356 email_text_parts(register_email).each do |part|
357 assert_match confirm_regex, part.body.to_s
359 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
362 assert_response :success
363 assert_template "confirmations/confirm"
365 ActionMailer::Base.deliveries.clear
367 # Go to the confirmation page
368 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
369 assert_response :success
370 assert_template "confirmations/confirm"
372 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
373 assert_response :redirect
375 assert_response :success
376 assert_template "site/welcome"
379 def test_user_create_google_success
380 new_email = "newtester-google@osm.org"
381 display_name = "new_tester-google"
382 password = "testtest"
384 OmniAuth.config.add_mock(:google, :uid => "123454321", :info => { "email" => new_email })
386 assert_difference("User.count") do
387 assert_no_difference("ActionMailer::Base.deliveries.size") do
388 perform_enqueued_jobs do
390 :params => { :user => { :email => new_email,
391 :email_confirmation => new_email,
392 :display_name => display_name,
393 :auth_provider => "google",
395 :pass_crypt_confirmation => "" } }
396 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
397 post response.location
398 assert_redirected_to auth_success_path(:provider => "google")
400 assert_redirected_to "/user/terms"
402 :params => { :user => { :email => new_email,
403 :email_confirmation => new_email,
404 :display_name => display_name,
405 :auth_provider => "google",
406 :auth_uid => "123454321",
407 :pass_crypt => password,
408 :pass_crypt_confirmation => password },
409 :read_ct => 1, :read_tou => 1 }
410 assert_redirected_to welcome_path
417 assert_response :success
418 assert_template "site/welcome"
420 ActionMailer::Base.deliveries.clear
423 def test_user_create_google_failure
424 OmniAuth.config.mock_auth[:google] = :connection_failed
426 new_email = "newtester-google2@osm.org"
427 display_name = "new_tester-google2"
428 assert_difference("User.count", 0) do
429 assert_difference("ActionMailer::Base.deliveries.size", 0) do
430 perform_enqueued_jobs do
432 :params => { :user => { :email => new_email,
433 :email_confirmation => new_email,
434 :display_name => display_name,
435 :auth_provider => "google",
437 :pass_crypt_confirmation => "" } }
438 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
439 post response.location
440 assert_redirected_to auth_success_path(:provider => "google")
442 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
444 assert_response :redirect
446 assert_response :success
447 assert_template "users/new"
452 ActionMailer::Base.deliveries.clear
455 def test_user_create_google_redirect
456 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
457 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
460 new_email = "redirect_tester_google@osm.org"
461 display_name = "redirect_tester_google"
462 # nothing special about this page, just need a protected page to redirect back to.
463 referer = "/traces/mine"
464 assert_difference("User.count") do
465 assert_difference("ActionMailer::Base.deliveries.size", 1) do
466 perform_enqueued_jobs do
468 :params => { :user => { :email => new_email,
469 :email_confirmation => new_email,
470 :display_name => display_name,
471 :auth_provider => "google",
473 :pass_crypt_confirmation => "" },
474 :referer => referer }
475 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
476 post response.location
477 assert_redirected_to auth_success_path(:provider => "google")
479 assert_redirected_to "/user/terms"
481 :params => { :user => { :email => new_email,
482 :email_confirmation => new_email,
483 :display_name => display_name,
484 :auth_provider => "google",
485 :auth_uid => "http://localhost:1123/new.tester",
486 :pass_crypt => "testtest",
487 :pass_crypt_confirmation => "testtest" },
488 :read_ct => 1, :read_tou => 1 }
495 register_email = ActionMailer::Base.deliveries.first
497 assert_equal register_email.to.first, new_email
498 # Check that the confirm account url is correct
499 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
500 email_text_parts(register_email).each do |part|
501 assert_match confirm_regex, part.body.to_s
503 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
506 assert_response :success
507 assert_template "confirmations/confirm"
509 ActionMailer::Base.deliveries.clear
511 # Go to the confirmation page
512 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
513 assert_response :success
514 assert_template "confirmations/confirm"
516 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
517 assert_response :redirect
519 assert_response :success
520 assert_template "site/welcome"
523 def test_user_create_facebook_success
524 new_email = "newtester-facebook@osm.org"
525 display_name = "new_tester-facebook"
526 password = "testtest"
528 OmniAuth.config.add_mock(:facebook, :uid => "123454321", :info => { "email" => new_email })
530 assert_difference("User.count") do
531 assert_no_difference("ActionMailer::Base.deliveries.size") do
532 perform_enqueued_jobs do
534 :params => { :user => { :email => new_email,
535 :email_confirmation => new_email,
536 :display_name => display_name,
537 :auth_provider => "facebook",
539 :pass_crypt_confirmation => "" } }
540 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
541 post response.location
542 assert_redirected_to auth_success_path(:provider => "facebook")
544 assert_redirected_to "/user/terms"
546 :params => { :user => { :email => new_email,
547 :email_confirmation => new_email,
548 :display_name => display_name,
549 :auth_provider => "facebook",
550 :auth_uid => "123454321",
551 :pass_crypt => password,
552 :pass_crypt_confirmation => password },
553 :read_ct => 1, :read_tou => 1 }
554 assert_redirected_to welcome_path
561 assert_response :success
562 assert_template "site/welcome"
564 ActionMailer::Base.deliveries.clear
567 def test_user_create_facebook_failure
568 OmniAuth.config.mock_auth[:facebook] = :connection_failed
570 new_email = "newtester-facebook2@osm.org"
571 display_name = "new_tester-facebook2"
572 assert_difference("User.count", 0) do
573 assert_difference("ActionMailer::Base.deliveries.size", 0) do
574 perform_enqueued_jobs do
576 :params => { :user => { :email => new_email,
577 :email_confirmation => new_email,
578 :display_name => display_name,
579 :auth_provider => "facebook",
581 :pass_crypt_confirmation => "" } }
582 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
583 post response.location
584 assert_redirected_to auth_success_path(:provider => "facebook")
586 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
588 assert_response :redirect
590 assert_response :success
591 assert_template "users/new"
596 ActionMailer::Base.deliveries.clear
599 def test_user_create_facebook_redirect
600 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
602 new_email = "redirect_tester_facebook@osm.org"
603 display_name = "redirect_tester_facebook"
604 # nothing special about this page, just need a protected page to redirect back to.
605 referer = "/traces/mine"
606 assert_difference("User.count") do
607 assert_difference("ActionMailer::Base.deliveries.size", 1) do
608 perform_enqueued_jobs do
610 :params => { :user => { :email => new_email,
611 :email_confirmation => new_email,
612 :display_name => display_name,
613 :auth_provider => "facebook",
615 :pass_crypt_confirmation => "" },
616 :referer => referer }
617 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
618 post response.location
619 assert_redirected_to auth_success_path(:provider => "facebook")
621 assert_redirected_to "/user/terms"
623 :params => { :user => { :email => new_email,
624 :email_confirmation => new_email,
625 :display_name => display_name,
626 :auth_provider => "facebook",
627 :auth_uid => "http://localhost:1123/new.tester",
628 :pass_crypt => "testtest",
629 :pass_crypt_confirmation => "testtest" },
630 :read_ct => 1, :read_tou => 1 }
637 register_email = ActionMailer::Base.deliveries.first
639 assert_equal register_email.to.first, new_email
640 # Check that the confirm account url is correct
641 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
642 email_text_parts(register_email).each do |part|
643 assert_match confirm_regex, part.body.to_s
645 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
648 assert_response :success
649 assert_template "confirmations/confirm"
651 ActionMailer::Base.deliveries.clear
653 # Go to the confirmation page
654 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
655 assert_response :success
656 assert_template "confirmations/confirm"
658 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
659 assert_response :redirect
661 assert_response :success
662 assert_template "site/welcome"
665 def test_user_create_microsoft_success
666 new_email = "newtester-microsoft@osm.org"
667 display_name = "new_tester-microsoft"
668 password = "testtest"
670 OmniAuth.config.add_mock(:microsoft, :uid => "123454321", :info => { "email" => new_email })
672 assert_difference("User.count") do
673 assert_difference("ActionMailer::Base.deliveries.size", 0) do
674 perform_enqueued_jobs do
676 :params => { :user => { :email => new_email,
677 :email_confirmation => new_email,
678 :display_name => display_name,
679 :auth_provider => "microsoft",
681 :pass_crypt_confirmation => "" } }
682 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
683 post response.location
684 assert_redirected_to auth_success_path(:provider => "microsoft")
686 assert_redirected_to "/user/terms"
688 :params => { :user => { :email => new_email,
689 :email_confirmation => new_email,
690 :display_name => display_name,
691 :auth_provider => "microsoft",
692 :auth_uid => "123454321",
693 :pass_crypt => password,
694 :pass_crypt_confirmation => password },
695 :read_ct => 1, :read_tou => 1 }
696 assert_redirected_to welcome_path
703 assert_response :success
704 assert_template "site/welcome"
706 ActionMailer::Base.deliveries.clear
709 def test_user_create_microsoft_failure
710 OmniAuth.config.mock_auth[:microsoft] = :connection_failed
712 new_email = "newtester-microsoft2@osm.org"
713 display_name = "new_tester-microsoft2"
714 assert_difference("User.count", 0) do
715 assert_difference("ActionMailer::Base.deliveries.size", 0) do
716 perform_enqueued_jobs do
718 :params => { :user => { :email => new_email,
719 :email_confirmation => new_email,
720 :display_name => display_name,
721 :auth_provider => "microsoft",
723 :pass_crypt_confirmation => "" } }
724 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
725 post response.location
726 assert_redirected_to auth_success_path(:provider => "microsoft")
728 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "connection_failed", :origin => "/user/new")
730 assert_response :redirect
732 assert_response :success
733 assert_template "users/new"
738 ActionMailer::Base.deliveries.clear
741 def test_user_create_microsoft_redirect
742 OmniAuth.config.add_mock(:microsoft, :uid => "123454321")
744 new_email = "redirect_tester_microsoft@osm.org"
745 display_name = "redirect_tester_microsoft"
746 # nothing special about this page, just need a protected page to redirect back to.
747 referer = "/traces/mine"
748 assert_difference("User.count") do
749 assert_difference("ActionMailer::Base.deliveries.size", 1) do
750 perform_enqueued_jobs do
752 :params => { :user => { :email => new_email,
753 :email_confirmation => new_email,
754 :display_name => display_name,
755 :auth_provider => "microsoft",
757 :pass_crypt_confirmation => "" },
758 :referer => referer }
759 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
760 post response.location
761 assert_redirected_to auth_success_path(:provider => "microsoft")
763 assert_redirected_to "/user/terms"
765 :params => { :user => { :email => new_email,
766 :email_confirmation => new_email,
767 :display_name => display_name,
768 :auth_provider => "microsoft",
769 :auth_uid => "http://localhost:1123/new.tester",
770 :pass_crypt => "testtest",
771 :pass_crypt_confirmation => "testtest" },
772 :read_ct => 1, :read_tou => 1 }
779 register_email = ActionMailer::Base.deliveries.first
781 assert_equal register_email.to.first, new_email
782 # Check that the confirm account url is correct
783 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
784 email_text_parts(register_email).each do |part|
785 assert_match confirm_regex, part.body.to_s
787 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
790 assert_response :success
791 assert_template "confirmations/confirm"
793 ActionMailer::Base.deliveries.clear
795 # Go to the confirmation page
796 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
797 assert_response :success
798 assert_template "confirmations/confirm"
800 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
801 assert_response :redirect
803 assert_response :success
804 assert_template "site/welcome"
807 def test_user_create_github_success
808 new_email = "newtester-github@osm.org"
809 display_name = "new_tester-github"
810 password = "testtest"
812 OmniAuth.config.add_mock(:github, :uid => "123454321", :info => { "email" => new_email })
814 assert_difference("User.count") do
815 assert_no_difference("ActionMailer::Base.deliveries.size") do
816 perform_enqueued_jobs do
818 :params => { :user => { :email => new_email,
819 :email_confirmation => new_email,
820 :display_name => display_name,
821 :auth_provider => "github",
823 :pass_crypt_confirmation => "" } }
824 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
825 post response.location
826 assert_redirected_to auth_success_path(:provider => "github")
828 assert_redirected_to "/user/terms"
830 :params => { :user => { :email => new_email,
831 :email_confirmation => new_email,
832 :display_name => display_name,
833 :auth_provider => "github",
834 :auth_uid => "123454321",
835 :pass_crypt => password,
836 :pass_crypt_confirmation => password },
839 assert_redirected_to welcome_path
846 assert_response :success
847 assert_template "site/welcome"
849 ActionMailer::Base.deliveries.clear
852 def test_user_create_github_failure
853 OmniAuth.config.mock_auth[:github] = :connection_failed
855 new_email = "newtester-github2@osm.org"
856 display_name = "new_tester-github2"
857 assert_difference("User.count", 0) do
858 assert_difference("ActionMailer::Base.deliveries.size", 0) do
859 perform_enqueued_jobs do
861 :params => { :user => { :email => new_email,
862 :email_confirmation => new_email,
863 :display_name => display_name,
864 :auth_provider => "github",
866 :pass_crypt_confirmation => "" } }
867 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
868 post response.location
869 assert_redirected_to auth_success_path(:provider => "github")
871 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
873 assert_response :redirect
875 assert_response :success
876 assert_template "users/new"
881 ActionMailer::Base.deliveries.clear
884 def test_user_create_github_redirect
885 OmniAuth.config.add_mock(:github, :uid => "123454321")
887 new_email = "redirect_tester_github@osm.org"
888 display_name = "redirect_tester_github"
889 # nothing special about this page, just need a protected page to redirect back to.
890 referer = "/traces/mine"
891 assert_difference("User.count") do
892 assert_difference("ActionMailer::Base.deliveries.size", 1) do
893 perform_enqueued_jobs do
895 :params => { :user => { :email => new_email,
896 :email_confirmation => new_email,
897 :display_name => display_name,
898 :auth_provider => "github",
900 :pass_crypt_confirmation => "" },
901 :referer => referer }
902 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
903 post response.location
904 assert_redirected_to auth_success_path(:provider => "github")
906 assert_redirected_to "/user/terms"
908 :params => { :user => { :email => new_email,
909 :email_confirmation => new_email,
910 :display_name => display_name,
911 :auth_provider => "github",
912 :auth_uid => "http://localhost:1123/new.tester",
913 :pass_crypt => "testtest",
914 :pass_crypt_confirmation => "testtest" },
923 register_email = ActionMailer::Base.deliveries.first
925 assert_equal register_email.to.first, new_email
926 # Check that the confirm account url is correct
927 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
928 email_text_parts(register_email).each do |part|
929 assert_match confirm_regex, part.body.to_s
931 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
934 assert_response :success
935 assert_template "confirmations/confirm"
937 ActionMailer::Base.deliveries.clear
939 # Go to the confirmation page
940 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
941 assert_response :success
942 assert_template "confirmations/confirm"
944 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
945 assert_response :redirect
947 assert_response :success
948 assert_template "site/welcome"
951 def test_user_create_wikipedia_success
952 new_email = "newtester-wikipedia@osm.org"
953 display_name = "new_tester-wikipedia"
954 password = "testtest"
956 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321", :info => { "email" => new_email })
958 assert_difference("User.count") do
959 assert_no_difference("ActionMailer::Base.deliveries.size") do
960 perform_enqueued_jobs do
962 :params => { :user => { :email => new_email,
963 :email_confirmation => new_email,
964 :display_name => display_name,
965 :auth_provider => "wikipedia",
967 :pass_crypt_confirmation => "" } }
968 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
969 post response.location
970 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
972 assert_redirected_to "/user/terms"
974 :params => { :user => { :email => new_email,
975 :email_confirmation => new_email,
976 :display_name => display_name,
977 :auth_provider => "wikipedia",
978 :auth_uid => "123454321",
979 :pass_crypt => password,
980 :pass_crypt_confirmation => password },
983 assert_redirected_to welcome_path
990 assert_response :success
991 assert_template "site/welcome"
993 ActionMailer::Base.deliveries.clear
996 def test_user_create_wikipedia_failure
997 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
999 new_email = "newtester-wikipedia2@osm.org"
1000 display_name = "new_tester-wikipedia2"
1001 assert_difference("User.count", 0) do
1002 assert_difference("ActionMailer::Base.deliveries.size", 0) do
1003 perform_enqueued_jobs do
1005 :params => { :user => { :email => new_email,
1006 :email_confirmation => new_email,
1007 :display_name => display_name,
1008 :auth_provider => "wikipedia",
1010 :pass_crypt_confirmation => "" } }
1011 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1012 post response.location
1013 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1015 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
1017 assert_response :redirect
1019 assert_response :success
1020 assert_template "users/new"
1025 ActionMailer::Base.deliveries.clear
1028 def test_user_create_wikipedia_redirect
1029 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
1031 new_email = "redirect_tester_wikipedia@osm.org"
1032 display_name = "redirect_tester_wikipedia"
1033 # nothing special about this page, just need a protected page to redirect back to.
1034 referer = "/traces/mine"
1035 assert_difference("User.count") do
1036 assert_difference("ActionMailer::Base.deliveries.size", 1) do
1037 perform_enqueued_jobs do
1039 :params => { :user => { :email => new_email,
1040 :email_confirmation => new_email,
1041 :display_name => display_name,
1042 :auth_provider => "wikipedia",
1044 :pass_crypt_confirmation => "" },
1045 :referer => referer }
1046 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
1047 post response.location
1048 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
1050 assert_redirected_to "/user/terms"
1052 :params => { :user => { :email => new_email,
1053 :email_confirmation => new_email,
1054 :display_name => display_name,
1055 :auth_provider => "wikipedia",
1056 :auth_uid => "http://localhost:1123/new.tester",
1057 :pass_crypt => "testtest",
1058 :pass_crypt_confirmation => "testtest" },
1067 register_email = ActionMailer::Base.deliveries.first
1069 assert_equal register_email.to.first, new_email
1070 # Check that the confirm account url is correct
1071 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
1072 email_text_parts(register_email).each do |part|
1073 assert_match confirm_regex, part.body.to_s
1075 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
1078 assert_response :success
1079 assert_template "confirmations/confirm"
1081 ActionMailer::Base.deliveries.clear
1083 # Go to the confirmation page
1084 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
1085 assert_response :success
1086 assert_template "confirmations/confirm"
1088 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
1089 assert_response :redirect
1091 assert_response :success
1092 assert_template "site/welcome"