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 :display_name => display_name,
36 :pass_crypt => "testtest",
37 :pass_crypt_confirmation => "testtest",
38 :consider_pd => "1" } }
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 :display_name => dup_display_name,
57 :pass_crypt => "testtest",
58 :pass_crypt_confirmation => "testtest" } }
62 assert_response :success
63 assert_template "users/new"
64 assert_select "form > div > input.is-invalid#user_display_name"
67 def test_user_create_submit_mismatched_passwords
68 email = "newtester@osm.org"
69 display_name = "new_tester"
70 assert_difference("User.count", 0) do
71 assert_difference("ActionMailer::Base.deliveries.size", 0) do
72 perform_enqueued_jobs do
74 :params => { :user => { :email => email,
75 :display_name => display_name,
76 :pass_crypt => "testtest",
77 :pass_crypt_confirmation => "blahblah" } }
81 assert_response :success
82 assert_template "users/new"
83 assert_select "form > div > input.is-invalid#user_pass_crypt_confirmation"
86 def test_user_create_success
87 new_email = "newtester@osm.org"
88 display_name = "new_tester"
90 assert_difference("User.count", 1) do
91 assert_difference("ActionMailer::Base.deliveries.size", 1) do
92 perform_enqueued_jobs do
94 :params => { :user => { :email => new_email,
95 :display_name => display_name,
96 :pass_crypt => "testtest",
97 :pass_crypt_confirmation => "testtest",
98 :consider_pd => "1" } }
99 assert_response :redirect
100 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
106 assert_response :success
107 assert_template "confirmations/confirm"
109 user = User.find_by(:email => "newtester@osm.org")
111 assert_not_predicate user, :active?
113 register_email = ActionMailer::Base.deliveries.first
114 assert_equal register_email.to.first, new_email
115 found_confirmation_url = register_email.parts.first.parts.first.to_s =~ %r{\shttp://test.host(/\S+)\s}
116 assert found_confirmation_url
117 confirmation_url = Regexp.last_match(1)
118 ActionMailer::Base.deliveries.clear
120 post confirmation_url
122 assert_redirected_to welcome_path
125 assert_predicate user, :active?
127 assert_equal user, User.authenticate(:username => new_email, :password => "testtest")
130 # Check that the user can successfully recover their password
131 def test_lost_password_recovery_success
132 # Open the lost password form
133 # Submit the lost password form
135 # Submit the reset password token
136 # Check that the password has changed, and the user can login
139 def test_user_create_redirect
140 new_email = "redirect_tester@osm.org"
141 display_name = "redirect_tester"
142 password = "testtest"
143 # nothing special about this page, just need a protected page to redirect back to.
144 referer = "/traces/mine"
145 assert_difference("User.count") do
146 assert_difference("ActionMailer::Base.deliveries.size", 1) do
147 perform_enqueued_jobs do
149 :params => { :user => { :email => new_email,
150 :display_name => display_name,
151 :pass_crypt => password,
152 :pass_crypt_confirmation => password,
153 :consider_pd => "1" },
154 :referer => referer }
155 assert_response(:redirect)
156 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
163 register_email = ActionMailer::Base.deliveries.first
165 assert_equal register_email.to.first, new_email
166 # Check that the confirm account url is correct
167 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
168 email_text_parts(register_email).each do |part|
169 assert_match confirm_regex, part.body.to_s
171 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
174 assert_response :success
175 assert_template "confirmations/confirm"
177 ActionMailer::Base.deliveries.clear
179 # Go to the confirmation page
180 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
181 assert_response :success
182 assert_template "confirmations/confirm"
184 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
185 assert_response :redirect
187 assert_response :success
188 assert_template "site/welcome"
191 def test_user_create_openid_success
192 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
194 new_email = "newtester-openid@osm.org"
195 display_name = "new_tester-openid"
196 password = "testtest"
197 assert_difference("User.count") do
198 assert_difference("ActionMailer::Base.deliveries.size", 1) do
199 perform_enqueued_jobs do
201 :params => { :user => { :email => new_email,
202 :display_name => display_name,
203 :auth_provider => "openid",
204 :auth_uid => "http://localhost:1123/new.tester",
205 :pass_crypt => password,
206 :pass_crypt_confirmation => password,
207 :consider_pd => "1" } }
208 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
209 post response.location
210 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
212 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
219 assert_response :success
220 assert_template "confirmations/confirm"
222 ActionMailer::Base.deliveries.clear
225 def test_user_create_openid_failure
226 OmniAuth.config.mock_auth[:openid] = :connection_failed
228 new_email = "newtester-openid2@osm.org"
229 display_name = "new_tester-openid2"
230 assert_difference("User.count", 0) do
231 assert_difference("ActionMailer::Base.deliveries.size", 0) do
232 perform_enqueued_jobs do
234 :params => { :user => { :email => new_email,
235 :display_name => display_name,
236 :auth_provider => "openid",
237 :auth_uid => "http://localhost:1123/new.tester",
238 :pass_crypt => "testtest",
239 :pass_crypt_confirmation => "testtest",
240 :consider_pd => "1" } }
241 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
242 post response.location
243 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
245 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
247 assert_response :redirect
249 assert_response :success
250 assert_template "users/new"
255 ActionMailer::Base.deliveries.clear
258 def test_user_create_openid_redirect
259 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
261 new_email = "redirect_tester_openid@osm.org"
262 display_name = "redirect_tester_openid"
263 # nothing special about this page, just need a protected page to redirect back to.
264 referer = "/traces/mine"
265 assert_difference("User.count") do
266 assert_difference("ActionMailer::Base.deliveries.size", 1) do
267 perform_enqueued_jobs do
269 :params => { :user => { :email => new_email,
270 :display_name => display_name,
271 :auth_provider => "openid",
272 :auth_uid => "http://localhost:1123/new.tester",
273 :pass_crypt => "testtest",
274 :pass_crypt_confirmation => "testtest",
275 :consider_pd => "1" },
276 :referer => referer }
277 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
278 post response.location
279 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
281 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
288 register_email = ActionMailer::Base.deliveries.first
290 assert_equal register_email.to.first, new_email
291 # Check that the confirm account url is correct
292 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
293 email_text_parts(register_email).each do |part|
294 assert_match confirm_regex, part.body.to_s
296 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
299 assert_response :success
300 assert_template "confirmations/confirm"
302 ActionMailer::Base.deliveries.clear
304 # Go to the confirmation page
305 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
306 assert_response :success
307 assert_template "confirmations/confirm"
309 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
310 assert_response :redirect
312 assert_response :success
313 assert_template "site/welcome"
316 def test_user_create_google_success
317 new_email = "newtester-google@osm.org"
318 display_name = "new_tester-google"
319 password = "testtest"
321 OmniAuth.config.add_mock(:google, :uid => "123454321", :info => { "email" => new_email })
323 assert_difference("User.count") do
324 assert_no_difference("ActionMailer::Base.deliveries.size") do
325 perform_enqueued_jobs do
327 :params => { :user => { :email => new_email,
328 :display_name => display_name,
329 :auth_provider => "google",
330 :pass_crypt => password,
331 :pass_crypt_confirmation => password,
332 :consider_pd => "1" } }
333 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
334 post response.location
335 assert_redirected_to auth_success_path(:provider => "google")
337 assert_redirected_to welcome_path
344 assert_response :success
345 assert_template "site/welcome"
347 ActionMailer::Base.deliveries.clear
350 def test_user_create_google_failure
351 OmniAuth.config.mock_auth[:google] = :connection_failed
353 new_email = "newtester-google2@osm.org"
354 display_name = "new_tester-google2"
355 assert_difference("User.count", 0) do
356 assert_difference("ActionMailer::Base.deliveries.size", 0) do
357 perform_enqueued_jobs do
359 :params => { :user => { :email => new_email,
360 :display_name => display_name,
361 :auth_provider => "google",
363 :pass_crypt_confirmation => "",
364 :consider_pd => "1" } }
365 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
366 post response.location
367 assert_redirected_to auth_success_path(:provider => "google")
369 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
371 assert_response :redirect
373 assert_response :success
374 assert_template "users/new"
379 ActionMailer::Base.deliveries.clear
382 def test_user_create_google_redirect
383 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
384 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
387 new_email = "redirect_tester_google@osm.org"
388 display_name = "redirect_tester_google"
389 # nothing special about this page, just need a protected page to redirect back to.
390 referer = "/traces/mine"
391 assert_difference("User.count") do
392 assert_difference("ActionMailer::Base.deliveries.size", 1) do
393 perform_enqueued_jobs do
395 :params => { :user => { :email => new_email,
396 :display_name => display_name,
397 :auth_provider => "google",
398 :pass_crypt => "testtest",
399 :pass_crypt_confirmation => "testtest",
400 :consider_pd => "1" },
401 :referer => referer }
402 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
403 post response.location
404 assert_redirected_to auth_success_path(:provider => "google")
406 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
413 register_email = ActionMailer::Base.deliveries.first
415 assert_equal register_email.to.first, new_email
416 # Check that the confirm account url is correct
417 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
418 email_text_parts(register_email).each do |part|
419 assert_match confirm_regex, part.body.to_s
421 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
424 assert_response :success
425 assert_template "confirmations/confirm"
427 ActionMailer::Base.deliveries.clear
429 # Go to the confirmation page
430 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
431 assert_response :success
432 assert_template "confirmations/confirm"
434 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
435 assert_response :redirect
437 assert_response :success
438 assert_template "site/welcome"
441 def test_user_create_facebook_success
442 new_email = "newtester-facebook@osm.org"
443 display_name = "new_tester-facebook"
444 password = "testtest"
446 OmniAuth.config.add_mock(:facebook, :uid => "123454321", :info => { "email" => new_email })
448 assert_difference("User.count") do
449 assert_no_difference("ActionMailer::Base.deliveries.size") do
450 perform_enqueued_jobs do
452 :params => { :user => { :email => new_email,
453 :display_name => display_name,
454 :auth_provider => "facebook",
455 :pass_crypt => password,
456 :pass_crypt_confirmation => password,
457 :consider_pd => "1" } }
458 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
459 post response.location
460 assert_redirected_to auth_success_path(:provider => "facebook")
462 assert_redirected_to welcome_path
469 assert_response :success
470 assert_template "site/welcome"
472 ActionMailer::Base.deliveries.clear
475 def test_user_create_facebook_failure
476 OmniAuth.config.mock_auth[:facebook] = :connection_failed
478 new_email = "newtester-facebook2@osm.org"
479 display_name = "new_tester-facebook2"
480 assert_difference("User.count", 0) do
481 assert_difference("ActionMailer::Base.deliveries.size", 0) do
482 perform_enqueued_jobs do
484 :params => { :user => { :email => new_email,
485 :display_name => display_name,
486 :auth_provider => "facebook",
488 :pass_crypt_confirmation => "",
489 :consider_pd => "1" } }
490 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
491 post response.location
492 assert_redirected_to auth_success_path(:provider => "facebook")
494 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
496 assert_response :redirect
498 assert_response :success
499 assert_template "users/new"
504 ActionMailer::Base.deliveries.clear
507 def test_user_create_facebook_redirect
508 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
510 new_email = "redirect_tester_facebook@osm.org"
511 display_name = "redirect_tester_facebook"
512 # nothing special about this page, just need a protected page to redirect back to.
513 referer = "/traces/mine"
514 assert_difference("User.count") do
515 assert_difference("ActionMailer::Base.deliveries.size", 1) do
516 perform_enqueued_jobs do
518 :params => { :user => { :email => new_email,
519 :display_name => display_name,
520 :auth_provider => "facebook",
521 :pass_crypt => "testtest",
522 :pass_crypt_confirmation => "testtest",
523 :consider_pd => "1" },
524 :referer => referer }
525 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
526 post response.location
527 assert_redirected_to auth_success_path(:provider => "facebook")
529 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
536 register_email = ActionMailer::Base.deliveries.first
538 assert_equal register_email.to.first, new_email
539 # Check that the confirm account url is correct
540 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
541 email_text_parts(register_email).each do |part|
542 assert_match confirm_regex, part.body.to_s
544 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
547 assert_response :success
548 assert_template "confirmations/confirm"
550 ActionMailer::Base.deliveries.clear
552 # Go to the confirmation page
553 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
554 assert_response :success
555 assert_template "confirmations/confirm"
557 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
558 assert_response :redirect
560 assert_response :success
561 assert_template "site/welcome"
564 def test_user_create_microsoft_success
565 new_email = "newtester-microsoft@osm.org"
566 display_name = "new_tester-microsoft"
567 password = "testtest"
569 OmniAuth.config.add_mock(:microsoft, :uid => "123454321", :info => { "email" => new_email })
571 assert_difference("User.count") do
572 assert_difference("ActionMailer::Base.deliveries.size", 0) do
573 perform_enqueued_jobs do
575 :params => { :user => { :email => new_email,
576 :display_name => display_name,
577 :auth_provider => "microsoft",
578 :pass_crypt => password,
579 :pass_crypt_confirmation => password,
580 :consider_pd => "1" } }
581 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
582 post response.location
583 assert_redirected_to auth_success_path(:provider => "microsoft")
585 assert_redirected_to welcome_path
592 assert_response :success
593 assert_template "site/welcome"
595 ActionMailer::Base.deliveries.clear
598 def test_user_create_microsoft_failure
599 OmniAuth.config.mock_auth[:microsoft] = :connection_failed
601 new_email = "newtester-microsoft2@osm.org"
602 display_name = "new_tester-microsoft2"
603 assert_difference("User.count", 0) do
604 assert_difference("ActionMailer::Base.deliveries.size", 0) do
605 perform_enqueued_jobs do
607 :params => { :user => { :email => new_email,
608 :display_name => display_name,
609 :auth_provider => "microsoft",
611 :pass_crypt_confirmation => "",
612 :consider_pd => "1" } }
613 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
614 post response.location
615 assert_redirected_to auth_success_path(:provider => "microsoft")
617 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "connection_failed", :origin => "/user/new")
619 assert_response :redirect
621 assert_response :success
622 assert_template "users/new"
627 ActionMailer::Base.deliveries.clear
630 def test_user_create_microsoft_redirect
631 OmniAuth.config.add_mock(:microsoft, :uid => "123454321")
633 new_email = "redirect_tester_microsoft@osm.org"
634 display_name = "redirect_tester_microsoft"
635 # nothing special about this page, just need a protected page to redirect back to.
636 referer = "/traces/mine"
637 assert_difference("User.count") do
638 assert_difference("ActionMailer::Base.deliveries.size", 1) do
639 perform_enqueued_jobs do
641 :params => { :user => { :email => new_email,
642 :display_name => display_name,
643 :auth_provider => "microsoft",
644 :pass_crypt => "testtest",
645 :pass_crypt_confirmation => "testtest",
646 :consider_pd => "1" },
647 :referer => referer }
648 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
649 post response.location
650 assert_redirected_to auth_success_path(:provider => "microsoft")
652 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
659 register_email = ActionMailer::Base.deliveries.first
661 assert_equal register_email.to.first, new_email
662 # Check that the confirm account url is correct
663 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
664 email_text_parts(register_email).each do |part|
665 assert_match confirm_regex, part.body.to_s
667 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
670 assert_response :success
671 assert_template "confirmations/confirm"
673 ActionMailer::Base.deliveries.clear
675 # Go to the confirmation page
676 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
677 assert_response :success
678 assert_template "confirmations/confirm"
680 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
681 assert_response :redirect
683 assert_response :success
684 assert_template "site/welcome"
687 def test_user_create_github_success
688 new_email = "newtester-github@osm.org"
689 display_name = "new_tester-github"
690 password = "testtest"
692 OmniAuth.config.add_mock(:github, :uid => "123454321", :info => { "email" => new_email })
694 assert_difference("User.count") do
695 assert_no_difference("ActionMailer::Base.deliveries.size") do
696 perform_enqueued_jobs do
698 :params => { :user => { :email => new_email,
699 :display_name => display_name,
700 :auth_provider => "github",
701 :pass_crypt => password,
702 :pass_crypt_confirmation => password,
703 :consider_pd => "1" } }
704 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
705 post response.location
706 assert_redirected_to auth_success_path(:provider => "github")
708 assert_redirected_to welcome_path
715 assert_response :success
716 assert_template "site/welcome"
718 ActionMailer::Base.deliveries.clear
721 def test_user_create_github_failure
722 OmniAuth.config.mock_auth[:github] = :connection_failed
724 new_email = "newtester-github2@osm.org"
725 display_name = "new_tester-github2"
726 assert_difference("User.count", 0) do
727 assert_difference("ActionMailer::Base.deliveries.size", 0) do
728 perform_enqueued_jobs do
730 :params => { :user => { :email => new_email,
731 :display_name => display_name,
732 :auth_provider => "github",
734 :pass_crypt_confirmation => "",
735 :consider_pd => "1" } }
736 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
737 post response.location
738 assert_redirected_to auth_success_path(:provider => "github")
740 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
742 assert_response :redirect
744 assert_response :success
745 assert_template "users/new"
750 ActionMailer::Base.deliveries.clear
753 def test_user_create_github_redirect
754 OmniAuth.config.add_mock(:github, :uid => "123454321")
756 new_email = "redirect_tester_github@osm.org"
757 display_name = "redirect_tester_github"
758 # nothing special about this page, just need a protected page to redirect back to.
759 referer = "/traces/mine"
760 assert_difference("User.count") do
761 assert_difference("ActionMailer::Base.deliveries.size", 1) do
762 perform_enqueued_jobs do
764 :params => { :user => { :email => new_email,
765 :display_name => display_name,
766 :auth_provider => "github",
767 :pass_crypt => "testtest",
768 :pass_crypt_confirmation => "testtest",
769 :consider_pd => "1" },
770 :referer => referer }
771 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
772 post response.location
773 assert_redirected_to auth_success_path(:provider => "github")
775 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
782 register_email = ActionMailer::Base.deliveries.first
784 assert_equal register_email.to.first, new_email
785 # Check that the confirm account url is correct
786 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
787 email_text_parts(register_email).each do |part|
788 assert_match confirm_regex, part.body.to_s
790 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
793 assert_response :success
794 assert_template "confirmations/confirm"
796 ActionMailer::Base.deliveries.clear
798 # Go to the confirmation page
799 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
800 assert_response :success
801 assert_template "confirmations/confirm"
803 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
804 assert_response :redirect
806 assert_response :success
807 assert_template "site/welcome"
810 def test_user_create_wikipedia_success
811 new_email = "newtester-wikipedia@osm.org"
812 display_name = "new_tester-wikipedia"
813 password = "testtest"
815 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321", :info => { "email" => new_email })
817 assert_difference("User.count") do
818 assert_no_difference("ActionMailer::Base.deliveries.size") do
819 perform_enqueued_jobs do
821 :params => { :user => { :email => new_email,
822 :display_name => display_name,
823 :auth_provider => "wikipedia",
824 :pass_crypt => password,
825 :pass_crypt_confirmation => password,
826 :consider_pd => "1" } }
827 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
828 post response.location
829 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
831 assert_redirected_to welcome_path
838 assert_response :success
839 assert_template "site/welcome"
841 ActionMailer::Base.deliveries.clear
844 def test_user_create_wikipedia_failure
845 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
847 new_email = "newtester-wikipedia2@osm.org"
848 display_name = "new_tester-wikipedia2"
849 assert_difference("User.count", 0) do
850 assert_difference("ActionMailer::Base.deliveries.size", 0) do
851 perform_enqueued_jobs do
853 :params => { :user => { :email => new_email,
854 :display_name => display_name,
855 :auth_provider => "wikipedia",
857 :pass_crypt_confirmation => "",
858 :consider_pd => "1" } }
859 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
860 post response.location
861 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
863 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
865 assert_response :redirect
867 assert_response :success
868 assert_template "users/new"
873 ActionMailer::Base.deliveries.clear
876 def test_user_create_wikipedia_redirect
877 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
879 new_email = "redirect_tester_wikipedia@osm.org"
880 display_name = "redirect_tester_wikipedia"
881 # nothing special about this page, just need a protected page to redirect back to.
882 referer = "/traces/mine"
883 assert_difference("User.count") do
884 assert_difference("ActionMailer::Base.deliveries.size", 1) do
885 perform_enqueued_jobs do
887 :params => { :user => { :email => new_email,
888 :display_name => display_name,
889 :auth_provider => "wikipedia",
890 :pass_crypt => "testtest",
891 :pass_crypt_confirmation => "testtest",
892 :consider_pd => "1" },
893 :referer => referer }
894 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
895 post response.location
896 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
898 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
905 register_email = ActionMailer::Base.deliveries.first
907 assert_equal register_email.to.first, new_email
908 # Check that the confirm account url is correct
909 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
910 email_text_parts(register_email).each do |part|
911 assert_match confirm_regex, part.body.to_s
913 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
916 assert_response :success
917 assert_template "confirmations/confirm"
919 ActionMailer::Base.deliveries.clear
921 # Go to the confirmation page
922 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
923 assert_response :success
924 assert_template "confirmations/confirm"
926 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
927 assert_response :redirect
929 assert_response :success
930 assert_template "site/welcome"