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",
39 :consider_pd => "1" } }
43 assert_response :success
44 assert_template "users/new"
46 assert_select "form > div > input.is-invalid#user_email"
49 def test_user_create_submit_duplicate_username
50 dup_display_name = create(:user).display_name
52 assert_difference("User.count", 0) do
53 assert_difference("ActionMailer::Base.deliveries.size", 0) do
54 perform_enqueued_jobs do
56 :params => { :user => { :email => email,
57 :email_confirmation => email,
58 :display_name => dup_display_name,
59 :pass_crypt => "testtest",
60 :pass_crypt_confirmation => "testtest" } }
64 assert_response :success
65 assert_template "users/new"
66 assert_select "form > div > input.is-invalid#user_display_name"
69 def test_user_create_submit_mismatched_passwords
70 email = "newtester@osm.org"
71 display_name = "new_tester"
72 assert_difference("User.count", 0) do
73 assert_difference("ActionMailer::Base.deliveries.size", 0) do
74 perform_enqueued_jobs do
76 :params => { :user => { :email => email,
77 :email_confirmation => email,
78 :display_name => display_name,
79 :pass_crypt => "testtest",
80 :pass_crypt_confirmation => "blahblah" } }
84 assert_response :success
85 assert_template "users/new"
86 assert_select "form > div > input.is-invalid#user_pass_crypt_confirmation"
89 def test_user_create_success
90 new_email = "newtester@osm.org"
91 display_name = "new_tester"
93 assert_difference("User.count", 1) do
94 assert_difference("ActionMailer::Base.deliveries.size", 1) do
95 perform_enqueued_jobs do
97 :params => { :user => { :email => new_email,
98 :email_confirmation => new_email,
99 :display_name => display_name,
100 :pass_crypt => "testtest",
101 :pass_crypt_confirmation => "testtest",
102 :consider_pd => "1" } }
103 assert_response :redirect
104 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
110 assert_response :success
111 assert_template "confirmations/confirm"
113 user = User.find_by(:email => "newtester@osm.org")
115 assert_not_predicate user, :active?
117 register_email = ActionMailer::Base.deliveries.first
118 assert_equal register_email.to.first, new_email
119 found_confirmation_url = register_email.parts.first.parts.first.to_s =~ %r{\shttp://test.host(/\S+)\s}
120 assert found_confirmation_url
121 confirmation_url = Regexp.last_match(1)
122 ActionMailer::Base.deliveries.clear
124 post confirmation_url
126 assert_redirected_to welcome_path
129 assert_predicate user, :active?
131 assert_equal user, User.authenticate(:username => new_email, :password => "testtest")
134 # Check that the user can successfully recover their password
135 def test_lost_password_recovery_success
136 # Open the lost password form
137 # Submit the lost password form
139 # Submit the reset password token
140 # Check that the password has changed, and the user can login
143 def test_user_create_redirect
144 new_email = "redirect_tester@osm.org"
145 display_name = "redirect_tester"
146 password = "testtest"
147 # nothing special about this page, just need a protected page to redirect back to.
148 referer = "/traces/mine"
149 assert_difference("User.count") do
150 assert_difference("ActionMailer::Base.deliveries.size", 1) do
151 perform_enqueued_jobs do
153 :params => { :user => { :email => new_email,
154 :email_confirmation => new_email,
155 :display_name => display_name,
156 :pass_crypt => password,
157 :pass_crypt_confirmation => password,
158 :consider_pd => "1" },
159 :referer => referer }
160 assert_response(:redirect)
161 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
168 register_email = ActionMailer::Base.deliveries.first
170 assert_equal register_email.to.first, new_email
171 # Check that the confirm account url is correct
172 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
173 email_text_parts(register_email).each do |part|
174 assert_match confirm_regex, part.body.to_s
176 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
179 assert_response :success
180 assert_template "confirmations/confirm"
182 ActionMailer::Base.deliveries.clear
184 # Go to the confirmation page
185 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
186 assert_response :success
187 assert_template "confirmations/confirm"
189 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
190 assert_response :redirect
192 assert_response :success
193 assert_template "site/welcome"
196 def test_user_create_openid_success
197 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
199 new_email = "newtester-openid@osm.org"
200 display_name = "new_tester-openid"
201 password = "testtest"
202 assert_difference("User.count") do
203 assert_difference("ActionMailer::Base.deliveries.size", 1) do
204 perform_enqueued_jobs do
206 :params => { :user => { :email => new_email,
207 :email_confirmation => new_email,
208 :display_name => display_name,
209 :auth_provider => "openid",
210 :auth_uid => "http://localhost:1123/new.tester",
211 :pass_crypt => password,
212 :pass_crypt_confirmation => password,
213 :consider_pd => "1" } }
214 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
215 post response.location
216 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
218 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
225 assert_response :success
226 assert_template "confirmations/confirm"
228 ActionMailer::Base.deliveries.clear
231 def test_user_create_openid_failure
232 OmniAuth.config.mock_auth[:openid] = :connection_failed
234 new_email = "newtester-openid2@osm.org"
235 display_name = "new_tester-openid2"
236 assert_difference("User.count", 0) do
237 assert_difference("ActionMailer::Base.deliveries.size", 0) do
238 perform_enqueued_jobs do
240 :params => { :user => { :email => new_email,
241 :email_confirmation => new_email,
242 :display_name => display_name,
243 :auth_provider => "openid",
244 :auth_uid => "http://localhost:1123/new.tester",
245 :pass_crypt => "testtest",
246 :pass_crypt_confirmation => "testtest",
247 :consider_pd => "1" } }
248 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
249 post response.location
250 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
252 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
254 assert_response :redirect
256 assert_response :success
257 assert_template "users/new"
262 ActionMailer::Base.deliveries.clear
265 def test_user_create_openid_redirect
266 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
268 new_email = "redirect_tester_openid@osm.org"
269 display_name = "redirect_tester_openid"
270 # nothing special about this page, just need a protected page to redirect back to.
271 referer = "/traces/mine"
272 assert_difference("User.count") do
273 assert_difference("ActionMailer::Base.deliveries.size", 1) do
274 perform_enqueued_jobs do
276 :params => { :user => { :email => new_email,
277 :email_confirmation => new_email,
278 :display_name => display_name,
279 :auth_provider => "openid",
280 :auth_uid => "http://localhost:1123/new.tester",
281 :pass_crypt => "testtest",
282 :pass_crypt_confirmation => "testtest",
283 :consider_pd => "1" },
284 :referer => referer }
285 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
286 post response.location
287 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
289 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
296 register_email = ActionMailer::Base.deliveries.first
298 assert_equal register_email.to.first, new_email
299 # Check that the confirm account url is correct
300 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
301 email_text_parts(register_email).each do |part|
302 assert_match confirm_regex, part.body.to_s
304 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
307 assert_response :success
308 assert_template "confirmations/confirm"
310 ActionMailer::Base.deliveries.clear
312 # Go to the confirmation page
313 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
314 assert_response :success
315 assert_template "confirmations/confirm"
317 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
318 assert_response :redirect
320 assert_response :success
321 assert_template "site/welcome"
324 def test_user_create_google_success
325 new_email = "newtester-google@osm.org"
326 display_name = "new_tester-google"
327 password = "testtest"
329 OmniAuth.config.add_mock(:google, :uid => "123454321", :info => { "email" => new_email })
331 assert_difference("User.count") do
332 assert_no_difference("ActionMailer::Base.deliveries.size") do
333 perform_enqueued_jobs do
335 :params => { :user => { :email => new_email,
336 :email_confirmation => new_email,
337 :display_name => display_name,
338 :auth_provider => "google",
339 :pass_crypt => password,
340 :pass_crypt_confirmation => password,
341 :consider_pd => "1" } }
342 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
343 post response.location
344 assert_redirected_to auth_success_path(:provider => "google")
346 assert_redirected_to welcome_path
353 assert_response :success
354 assert_template "site/welcome"
356 ActionMailer::Base.deliveries.clear
359 def test_user_create_google_failure
360 OmniAuth.config.mock_auth[:google] = :connection_failed
362 new_email = "newtester-google2@osm.org"
363 display_name = "new_tester-google2"
364 assert_difference("User.count", 0) do
365 assert_difference("ActionMailer::Base.deliveries.size", 0) do
366 perform_enqueued_jobs do
368 :params => { :user => { :email => new_email,
369 :email_confirmation => new_email,
370 :display_name => display_name,
371 :auth_provider => "google",
373 :pass_crypt_confirmation => "",
374 :consider_pd => "1" } }
375 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
376 post response.location
377 assert_redirected_to auth_success_path(:provider => "google")
379 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
381 assert_response :redirect
383 assert_response :success
384 assert_template "users/new"
389 ActionMailer::Base.deliveries.clear
392 def test_user_create_google_redirect
393 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
394 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
397 new_email = "redirect_tester_google@osm.org"
398 display_name = "redirect_tester_google"
399 # nothing special about this page, just need a protected page to redirect back to.
400 referer = "/traces/mine"
401 assert_difference("User.count") do
402 assert_difference("ActionMailer::Base.deliveries.size", 1) do
403 perform_enqueued_jobs do
405 :params => { :user => { :email => new_email,
406 :email_confirmation => new_email,
407 :display_name => display_name,
408 :auth_provider => "google",
409 :pass_crypt => "testtest",
410 :pass_crypt_confirmation => "testtest",
411 :consider_pd => "1" },
412 :referer => referer }
413 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
414 post response.location
415 assert_redirected_to auth_success_path(:provider => "google")
417 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
424 register_email = ActionMailer::Base.deliveries.first
426 assert_equal register_email.to.first, new_email
427 # Check that the confirm account url is correct
428 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
429 email_text_parts(register_email).each do |part|
430 assert_match confirm_regex, part.body.to_s
432 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
435 assert_response :success
436 assert_template "confirmations/confirm"
438 ActionMailer::Base.deliveries.clear
440 # Go to the confirmation page
441 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
442 assert_response :success
443 assert_template "confirmations/confirm"
445 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
446 assert_response :redirect
448 assert_response :success
449 assert_template "site/welcome"
452 def test_user_create_facebook_success
453 new_email = "newtester-facebook@osm.org"
454 display_name = "new_tester-facebook"
455 password = "testtest"
457 OmniAuth.config.add_mock(:facebook, :uid => "123454321", :info => { "email" => new_email })
459 assert_difference("User.count") do
460 assert_no_difference("ActionMailer::Base.deliveries.size") do
461 perform_enqueued_jobs do
463 :params => { :user => { :email => new_email,
464 :email_confirmation => new_email,
465 :display_name => display_name,
466 :auth_provider => "facebook",
467 :pass_crypt => password,
468 :pass_crypt_confirmation => password,
469 :consider_pd => "1" } }
470 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
471 post response.location
472 assert_redirected_to auth_success_path(:provider => "facebook")
474 assert_redirected_to welcome_path
481 assert_response :success
482 assert_template "site/welcome"
484 ActionMailer::Base.deliveries.clear
487 def test_user_create_facebook_failure
488 OmniAuth.config.mock_auth[:facebook] = :connection_failed
490 new_email = "newtester-facebook2@osm.org"
491 display_name = "new_tester-facebook2"
492 assert_difference("User.count", 0) do
493 assert_difference("ActionMailer::Base.deliveries.size", 0) do
494 perform_enqueued_jobs do
496 :params => { :user => { :email => new_email,
497 :email_confirmation => new_email,
498 :display_name => display_name,
499 :auth_provider => "facebook",
501 :pass_crypt_confirmation => "",
502 :consider_pd => "1" } }
503 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
504 post response.location
505 assert_redirected_to auth_success_path(:provider => "facebook")
507 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
509 assert_response :redirect
511 assert_response :success
512 assert_template "users/new"
517 ActionMailer::Base.deliveries.clear
520 def test_user_create_facebook_redirect
521 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
523 new_email = "redirect_tester_facebook@osm.org"
524 display_name = "redirect_tester_facebook"
525 # nothing special about this page, just need a protected page to redirect back to.
526 referer = "/traces/mine"
527 assert_difference("User.count") do
528 assert_difference("ActionMailer::Base.deliveries.size", 1) do
529 perform_enqueued_jobs do
531 :params => { :user => { :email => new_email,
532 :email_confirmation => new_email,
533 :display_name => display_name,
534 :auth_provider => "facebook",
535 :pass_crypt => "testtest",
536 :pass_crypt_confirmation => "testtest",
537 :consider_pd => "1" },
538 :referer => referer }
539 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
540 post response.location
541 assert_redirected_to auth_success_path(:provider => "facebook")
543 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
550 register_email = ActionMailer::Base.deliveries.first
552 assert_equal register_email.to.first, new_email
553 # Check that the confirm account url is correct
554 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
555 email_text_parts(register_email).each do |part|
556 assert_match confirm_regex, part.body.to_s
558 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
561 assert_response :success
562 assert_template "confirmations/confirm"
564 ActionMailer::Base.deliveries.clear
566 # Go to the confirmation page
567 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
568 assert_response :success
569 assert_template "confirmations/confirm"
571 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
572 assert_response :redirect
574 assert_response :success
575 assert_template "site/welcome"
578 def test_user_create_microsoft_success
579 new_email = "newtester-microsoft@osm.org"
580 display_name = "new_tester-microsoft"
581 password = "testtest"
583 OmniAuth.config.add_mock(:microsoft, :uid => "123454321", :info => { "email" => new_email })
585 assert_difference("User.count") 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 => "microsoft",
593 :pass_crypt => password,
594 :pass_crypt_confirmation => password,
595 :consider_pd => "1" } }
596 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
597 post response.location
598 assert_redirected_to auth_success_path(:provider => "microsoft")
600 assert_redirected_to welcome_path
607 assert_response :success
608 assert_template "site/welcome"
610 ActionMailer::Base.deliveries.clear
613 def test_user_create_microsoft_failure
614 OmniAuth.config.mock_auth[:microsoft] = :connection_failed
616 new_email = "newtester-microsoft2@osm.org"
617 display_name = "new_tester-microsoft2"
618 assert_difference("User.count", 0) do
619 assert_difference("ActionMailer::Base.deliveries.size", 0) do
620 perform_enqueued_jobs do
622 :params => { :user => { :email => new_email,
623 :email_confirmation => new_email,
624 :display_name => display_name,
625 :auth_provider => "microsoft",
627 :pass_crypt_confirmation => "",
628 :consider_pd => "1" } }
629 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
630 post response.location
631 assert_redirected_to auth_success_path(:provider => "microsoft")
633 assert_redirected_to auth_failure_path(:strategy => "microsoft", :message => "connection_failed", :origin => "/user/new")
635 assert_response :redirect
637 assert_response :success
638 assert_template "users/new"
643 ActionMailer::Base.deliveries.clear
646 def test_user_create_microsoft_redirect
647 OmniAuth.config.add_mock(:microsoft, :uid => "123454321")
649 new_email = "redirect_tester_microsoft@osm.org"
650 display_name = "redirect_tester_microsoft"
651 # nothing special about this page, just need a protected page to redirect back to.
652 referer = "/traces/mine"
653 assert_difference("User.count") do
654 assert_difference("ActionMailer::Base.deliveries.size", 1) do
655 perform_enqueued_jobs do
657 :params => { :user => { :email => new_email,
658 :email_confirmation => new_email,
659 :display_name => display_name,
660 :auth_provider => "microsoft",
661 :pass_crypt => "testtest",
662 :pass_crypt_confirmation => "testtest",
663 :consider_pd => "1" },
664 :referer => referer }
665 assert_redirected_to auth_path(:provider => "microsoft", :origin => "/user/new")
666 post response.location
667 assert_redirected_to auth_success_path(:provider => "microsoft")
669 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
676 register_email = ActionMailer::Base.deliveries.first
678 assert_equal register_email.to.first, new_email
679 # Check that the confirm account url is correct
680 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
681 email_text_parts(register_email).each do |part|
682 assert_match confirm_regex, part.body.to_s
684 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
687 assert_response :success
688 assert_template "confirmations/confirm"
690 ActionMailer::Base.deliveries.clear
692 # Go to the confirmation page
693 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
694 assert_response :success
695 assert_template "confirmations/confirm"
697 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
698 assert_response :redirect
700 assert_response :success
701 assert_template "site/welcome"
704 def test_user_create_github_success
705 new_email = "newtester-github@osm.org"
706 display_name = "new_tester-github"
707 password = "testtest"
709 OmniAuth.config.add_mock(:github, :uid => "123454321", :info => { "email" => new_email })
711 assert_difference("User.count") do
712 assert_no_difference("ActionMailer::Base.deliveries.size") do
713 perform_enqueued_jobs do
715 :params => { :user => { :email => new_email,
716 :email_confirmation => new_email,
717 :display_name => display_name,
718 :auth_provider => "github",
719 :pass_crypt => password,
720 :pass_crypt_confirmation => password,
721 :consider_pd => "1" } }
722 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
723 post response.location
724 assert_redirected_to auth_success_path(:provider => "github")
726 assert_redirected_to welcome_path
733 assert_response :success
734 assert_template "site/welcome"
736 ActionMailer::Base.deliveries.clear
739 def test_user_create_github_failure
740 OmniAuth.config.mock_auth[:github] = :connection_failed
742 new_email = "newtester-github2@osm.org"
743 display_name = "new_tester-github2"
744 assert_difference("User.count", 0) do
745 assert_difference("ActionMailer::Base.deliveries.size", 0) do
746 perform_enqueued_jobs do
748 :params => { :user => { :email => new_email,
749 :email_confirmation => new_email,
750 :display_name => display_name,
751 :auth_provider => "github",
753 :pass_crypt_confirmation => "",
754 :consider_pd => "1" } }
755 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
756 post response.location
757 assert_redirected_to auth_success_path(:provider => "github")
759 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
761 assert_response :redirect
763 assert_response :success
764 assert_template "users/new"
769 ActionMailer::Base.deliveries.clear
772 def test_user_create_github_redirect
773 OmniAuth.config.add_mock(:github, :uid => "123454321")
775 new_email = "redirect_tester_github@osm.org"
776 display_name = "redirect_tester_github"
777 # nothing special about this page, just need a protected page to redirect back to.
778 referer = "/traces/mine"
779 assert_difference("User.count") do
780 assert_difference("ActionMailer::Base.deliveries.size", 1) do
781 perform_enqueued_jobs do
783 :params => { :user => { :email => new_email,
784 :email_confirmation => new_email,
785 :display_name => display_name,
786 :auth_provider => "github",
787 :pass_crypt => "testtest",
788 :pass_crypt_confirmation => "testtest",
789 :consider_pd => "1" },
790 :referer => referer }
791 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
792 post response.location
793 assert_redirected_to auth_success_path(:provider => "github")
795 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
802 register_email = ActionMailer::Base.deliveries.first
804 assert_equal register_email.to.first, new_email
805 # Check that the confirm account url is correct
806 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
807 email_text_parts(register_email).each do |part|
808 assert_match confirm_regex, part.body.to_s
810 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
813 assert_response :success
814 assert_template "confirmations/confirm"
816 ActionMailer::Base.deliveries.clear
818 # Go to the confirmation page
819 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
820 assert_response :success
821 assert_template "confirmations/confirm"
823 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
824 assert_response :redirect
826 assert_response :success
827 assert_template "site/welcome"
830 def test_user_create_wikipedia_success
831 new_email = "newtester-wikipedia@osm.org"
832 display_name = "new_tester-wikipedia"
833 password = "testtest"
835 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321", :info => { "email" => new_email })
837 assert_difference("User.count") do
838 assert_no_difference("ActionMailer::Base.deliveries.size") do
839 perform_enqueued_jobs do
841 :params => { :user => { :email => new_email,
842 :email_confirmation => new_email,
843 :display_name => display_name,
844 :auth_provider => "wikipedia",
845 :pass_crypt => password,
846 :pass_crypt_confirmation => password,
847 :consider_pd => "1" } }
848 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
849 post response.location
850 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
852 assert_redirected_to welcome_path
859 assert_response :success
860 assert_template "site/welcome"
862 ActionMailer::Base.deliveries.clear
865 def test_user_create_wikipedia_failure
866 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
868 new_email = "newtester-wikipedia2@osm.org"
869 display_name = "new_tester-wikipedia2"
870 assert_difference("User.count", 0) do
871 assert_difference("ActionMailer::Base.deliveries.size", 0) do
872 perform_enqueued_jobs do
874 :params => { :user => { :email => new_email,
875 :email_confirmation => new_email,
876 :display_name => display_name,
877 :auth_provider => "wikipedia",
879 :pass_crypt_confirmation => "",
880 :consider_pd => "1" } }
881 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
882 post response.location
883 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
885 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
887 assert_response :redirect
889 assert_response :success
890 assert_template "users/new"
895 ActionMailer::Base.deliveries.clear
898 def test_user_create_wikipedia_redirect
899 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
901 new_email = "redirect_tester_wikipedia@osm.org"
902 display_name = "redirect_tester_wikipedia"
903 # nothing special about this page, just need a protected page to redirect back to.
904 referer = "/traces/mine"
905 assert_difference("User.count") do
906 assert_difference("ActionMailer::Base.deliveries.size", 1) do
907 perform_enqueued_jobs do
909 :params => { :user => { :email => new_email,
910 :email_confirmation => new_email,
911 :display_name => display_name,
912 :auth_provider => "wikipedia",
913 :pass_crypt => "testtest",
914 :pass_crypt_confirmation => "testtest",
915 :consider_pd => "1" },
916 :referer => referer }
917 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
918 post response.location
919 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
921 assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
928 register_email = ActionMailer::Base.deliveries.first
930 assert_equal register_email.to.first, new_email
931 # Check that the confirm account url is correct
932 confirm_regex = Regexp.new("confirm_string=([a-zA-Z0-9%_-]*)")
933 email_text_parts(register_email).each do |part|
934 assert_match confirm_regex, part.body.to_s
936 confirm_string = CGI.unescape(email_text_parts(register_email).first.body.match(confirm_regex)[1])
939 assert_response :success
940 assert_template "confirmations/confirm"
942 ActionMailer::Base.deliveries.clear
944 # Go to the confirmation page
945 get "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
946 assert_response :success
947 assert_template "confirmations/confirm"
949 post "/user/#{display_name}/confirm", :params => { :referer => "/welcome", :confirm_string => confirm_string }
950 assert_response :redirect
952 assert_response :success
953 assert_template "site/welcome"