3 class UserCreationTest < ActionDispatch::IntegrationTest
7 OmniAuth.config.test_mode = true
9 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
16 OmniAuth.config.mock_auth[:openid] = nil
17 OmniAuth.config.mock_auth[:google] = nil
18 OmniAuth.config.mock_auth[:facebook] = nil
19 OmniAuth.config.mock_auth[:windowslive] = nil
20 OmniAuth.config.mock_auth[:github] = nil
21 OmniAuth.config.mock_auth[:wikipedia] = nil
22 OmniAuth.config.test_mode = false
25 def test_create_user_form
26 I18n.available_locales.each do |locale|
28 get "/user/new", :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
30 assert_response :success
31 assert_template "users/new"
35 def test_user_create_submit_duplicate_email
36 I18n.available_locales.each do |locale|
37 dup_email = create(:user).email
38 display_name = "#{locale}_new_tester"
39 assert_difference("User.count", 0) do
40 assert_difference("ActionMailer::Base.deliveries.size", 0) do
41 perform_enqueued_jobs do
43 :params => { :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
44 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
48 assert_response :success
49 assert_template "users/new"
50 assert_equal locale.to_s, response.headers["Content-Language"] unless locale == :root
51 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
52 assert_no_missing_translations
56 def test_user_create_submit_duplicate_username
57 I18n.available_locales.each do |locale|
58 dup_display_name = create(:user).display_name
59 email = "#{locale}_new_tester"
60 assert_difference("User.count", 0) do
61 assert_difference("ActionMailer::Base.deliveries.size", 0) do
62 perform_enqueued_jobs do
64 :params => { :user => { :email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
65 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
69 assert_response :success
70 assert_template "users/new"
71 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
72 assert_no_missing_translations
76 def test_user_create_success
77 I18n.available_locales.each do |locale|
78 new_email = "#{locale}newtester@osm.org"
79 display_name = "#{locale}_new_tester"
81 assert_difference("User.count", 0) do
82 assert_difference("ActionMailer::Base.deliveries.size", 0) do
83 perform_enqueued_jobs do
85 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } }
90 assert_redirected_to "/user/terms"
92 assert_difference("User.count") do
93 assert_difference("ActionMailer::Base.deliveries.size", 1) do
94 perform_enqueued_jobs do
96 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s },
97 :params => { :read_tou => 1 }
104 register_email = ActionMailer::Base.deliveries.first
106 assert_equal register_email.to.first, new_email
107 # Check that the confirm account url is correct
108 assert_match(/#{@url}/, register_email.body.to_s)
111 assert_response :success
112 assert_template "users/confirm"
114 ActionMailer::Base.deliveries.clear
118 def test_user_create_no_tou_failure
119 I18n.available_locales.each do |locale|
120 new_email = "#{locale}newtester@osm.org"
121 display_name = "#{locale}_new_tester"
123 assert_difference("User.count", 0) do
124 assert_difference("ActionMailer::Base.deliveries.size", 0) do
125 perform_enqueued_jobs do
127 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } }
132 assert_redirected_to "/user/terms"
134 perform_enqueued_jobs do
136 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
137 assert_redirected_to "/user/terms"
140 ActionMailer::Base.deliveries.clear
144 # Check that the user can successfully recover their password
145 def lost_password_recovery_success
146 # Open the lost password form
147 # Submit the lost password form
149 # Submit the reset password token
150 # Check that the password has changed, and the user can login
153 def test_user_create_redirect
154 new_email = "redirect_tester@osm.org"
155 display_name = "redirect_tester"
156 password = "testtest"
157 # nothing special about this page, just need a protected page to redirect back to.
158 referer = "/traces/mine"
159 assert_difference("User.count") do
160 assert_difference("ActionMailer::Base.deliveries.size", 1) do
161 perform_enqueued_jobs do
163 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }, :referer => referer }
164 assert_redirected_to "/user/terms"
166 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }, :read_tou => 1 }
173 register_email = ActionMailer::Base.deliveries.first
175 assert_equal register_email.to.first, new_email
176 # Check that the confirm account url is correct
177 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
178 email_text_parts(register_email).each do |part|
179 assert_match confirm_regex, part.body.to_s
181 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
184 assert_response :success
185 assert_template "users/confirm"
187 ActionMailer::Base.deliveries.clear
189 # Go to the confirmation page
190 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
191 assert_response :success
192 assert_template "users/confirm"
194 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
195 assert_response :redirect
197 assert_response :success
198 assert_template "site/welcome"
201 def test_user_create_openid_success
202 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
204 new_email = "newtester-openid@osm.org"
205 display_name = "new_tester-openid"
206 password = "testtest"
207 assert_difference("User.count") do
208 assert_difference("ActionMailer::Base.deliveries.size", 1) do
209 perform_enqueued_jobs do
211 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "", :pass_crypt_confirmation => "" } }
212 assert_response :redirect
213 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
215 assert_response :redirect
216 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
218 assert_response :redirect
219 assert_redirected_to "/user/terms"
221 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => password, :pass_crypt_confirmation => password }, :read_tou => 1 }
222 assert_response :redirect
229 assert_response :success
230 assert_template "users/confirm"
232 ActionMailer::Base.deliveries.clear
235 def test_user_create_openid_failure
236 OmniAuth.config.mock_auth[:openid] = :connection_failed
238 new_email = "newtester-openid2@osm.org"
239 display_name = "new_tester-openid2"
240 assert_difference("User.count", 0) do
241 assert_difference("ActionMailer::Base.deliveries.size", 0) do
242 perform_enqueued_jobs do
244 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "", :pass_crypt_confirmation => "" } }
245 assert_response :redirect
246 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
248 assert_response :redirect
249 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
251 assert_response :redirect
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, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
277 assert_response :redirect
278 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
280 assert_response :redirect
281 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
283 assert_response :redirect
284 assert_redirected_to "/user/terms"
286 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "openid", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }, :read_tou => 1 }
293 register_email = ActionMailer::Base.deliveries.first
295 assert_equal register_email.to.first, new_email
296 # Check that the confirm account url is correct
297 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
298 email_text_parts(register_email).each do |part|
299 assert_match confirm_regex, part.body.to_s
301 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
304 assert_response :success
305 assert_template "users/confirm"
307 ActionMailer::Base.deliveries.clear
309 # Go to the confirmation page
310 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
311 assert_response :success
312 assert_template "users/confirm"
314 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
315 assert_response :redirect
317 assert_response :success
318 assert_template "site/welcome"
321 def test_user_create_google_success
322 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
323 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
326 new_email = "newtester-google@osm.org"
327 display_name = "new_tester-google"
328 password = "testtest"
329 assert_difference("User.count") do
330 assert_difference("ActionMailer::Base.deliveries.size", 1) do
331 perform_enqueued_jobs do
333 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" } }
334 assert_response :redirect
335 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
337 assert_response :redirect
338 assert_redirected_to auth_success_path(:provider => "google")
340 assert_response :redirect
341 assert_redirected_to "/user/terms"
343 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }, :read_tou => 1 }
344 assert_response :redirect
351 assert_response :success
352 assert_template "users/confirm"
354 ActionMailer::Base.deliveries.clear
357 def test_user_create_google_failure
358 OmniAuth.config.mock_auth[:google] = :connection_failed
360 new_email = "newtester-google2@osm.org"
361 display_name = "new_tester-google2"
362 assert_difference("User.count", 0) do
363 assert_difference("ActionMailer::Base.deliveries.size", 0) do
364 perform_enqueued_jobs do
366 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" } }
367 assert_response :redirect
368 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
370 assert_response :redirect
371 assert_redirected_to auth_success_path(:provider => "google")
373 assert_response :redirect
374 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
376 assert_response :redirect
378 assert_response :success
379 assert_template "users/new"
384 ActionMailer::Base.deliveries.clear
387 def test_user_create_google_redirect
388 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
389 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
392 new_email = "redirect_tester_google@osm.org"
393 display_name = "redirect_tester_google"
394 # nothing special about this page, just need a protected page to redirect back to.
395 referer = "/traces/mine"
396 assert_difference("User.count") do
397 assert_difference("ActionMailer::Base.deliveries.size", 1) do
398 perform_enqueued_jobs do
400 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
401 assert_response :redirect
402 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
404 assert_response :redirect
405 assert_redirected_to auth_success_path(:provider => "google")
407 assert_response :redirect
408 assert_redirected_to "/user/terms"
410 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }, :read_tou => 1 }
417 register_email = ActionMailer::Base.deliveries.first
419 assert_equal register_email.to.first, new_email
420 # Check that the confirm account url is correct
421 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
422 email_text_parts(register_email).each do |part|
423 assert_match confirm_regex, part.body.to_s
425 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
428 assert_response :success
429 assert_template "users/confirm"
431 ActionMailer::Base.deliveries.clear
433 # Go to the confirmation page
434 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
435 assert_response :success
436 assert_template "users/confirm"
438 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
439 assert_response :redirect
441 assert_response :success
442 assert_template "site/welcome"
445 def test_user_create_facebook_success
446 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
448 new_email = "newtester-facebook@osm.org"
449 display_name = "new_tester-facebook"
450 password = "testtest"
451 assert_difference("User.count") do
452 assert_difference("ActionMailer::Base.deliveries.size", 1) do
453 perform_enqueued_jobs do
455 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" } }
456 assert_response :redirect
457 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
459 assert_response :redirect
460 assert_redirected_to auth_success_path(:provider => "facebook")
462 assert_response :redirect
463 assert_redirected_to "/user/terms"
465 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }, :read_tou => 1 }
466 assert_response :redirect
473 assert_response :success
474 assert_template "users/confirm"
476 ActionMailer::Base.deliveries.clear
479 def test_user_create_facebook_failure
480 OmniAuth.config.mock_auth[:facebook] = :connection_failed
482 new_email = "newtester-facebook2@osm.org"
483 display_name = "new_tester-facebook2"
484 assert_difference("User.count", 0) do
485 assert_difference("ActionMailer::Base.deliveries.size", 0) do
486 perform_enqueued_jobs do
488 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" } }
489 assert_response :redirect
490 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
492 assert_response :redirect
493 assert_redirected_to auth_success_path(:provider => "facebook")
495 assert_response :redirect
496 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
498 assert_response :redirect
500 assert_response :success
501 assert_template "users/new"
506 ActionMailer::Base.deliveries.clear
509 def test_user_create_facebook_redirect
510 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
512 new_email = "redirect_tester_facebook@osm.org"
513 display_name = "redirect_tester_facebook"
514 # nothing special about this page, just need a protected page to redirect back to.
515 referer = "/traces/mine"
516 assert_difference("User.count") do
517 assert_difference("ActionMailer::Base.deliveries.size", 1) do
518 perform_enqueued_jobs do
520 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
521 assert_response :redirect
522 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
524 assert_response :redirect
525 assert_redirected_to auth_success_path(:provider => "facebook")
527 assert_response :redirect
528 assert_redirected_to "/user/terms"
530 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }, :read_tou => 1 }
537 register_email = ActionMailer::Base.deliveries.first
539 assert_equal register_email.to.first, new_email
540 # Check that the confirm account url is correct
541 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
542 email_text_parts(register_email).each do |part|
543 assert_match confirm_regex, part.body.to_s
545 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
548 assert_response :success
549 assert_template "users/confirm"
551 ActionMailer::Base.deliveries.clear
553 # Go to the confirmation page
554 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
555 assert_response :success
556 assert_template "users/confirm"
558 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
559 assert_response :redirect
561 assert_response :success
562 assert_template "site/welcome"
565 def test_user_create_windowslive_success
566 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
568 new_email = "newtester-windowslive@osm.org"
569 display_name = "new_tester-windowslive"
570 password = "testtest"
571 assert_difference("User.count") do
572 assert_difference("ActionMailer::Base.deliveries.size", 1) do
573 perform_enqueued_jobs do
575 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" } }
576 assert_response :redirect
577 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
579 assert_response :redirect
580 assert_redirected_to auth_success_path(:provider => "windowslive")
582 assert_response :redirect
583 assert_redirected_to "/user/terms"
585 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }, :read_tou => 1 }
586 assert_response :redirect
593 assert_response :success
594 assert_template "users/confirm"
596 ActionMailer::Base.deliveries.clear
599 def test_user_create_windowslive_failure
600 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
602 new_email = "newtester-windowslive2@osm.org"
603 display_name = "new_tester-windowslive2"
604 assert_difference("User.count", 0) do
605 assert_difference("ActionMailer::Base.deliveries.size", 0) do
606 perform_enqueued_jobs do
608 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" } }
609 assert_response :redirect
610 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
612 assert_response :redirect
613 assert_redirected_to auth_success_path(:provider => "windowslive")
615 assert_response :redirect
616 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/user/new")
618 assert_response :redirect
620 assert_response :success
621 assert_template "users/new"
626 ActionMailer::Base.deliveries.clear
629 def test_user_create_windowslive_redirect
630 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
632 new_email = "redirect_tester_windowslive@osm.org"
633 display_name = "redirect_tester_windowslive"
634 # nothing special about this page, just need a protected page to redirect back to.
635 referer = "/traces/mine"
636 assert_difference("User.count") do
637 assert_difference("ActionMailer::Base.deliveries.size", 1) do
638 perform_enqueued_jobs do
640 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
641 assert_response :redirect
642 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
644 assert_response :redirect
645 assert_redirected_to auth_success_path(:provider => "windowslive")
647 assert_response :redirect
648 assert_redirected_to "/user/terms"
650 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }, :read_tou => 1 }
657 register_email = ActionMailer::Base.deliveries.first
659 assert_equal register_email.to.first, new_email
660 # Check that the confirm account url is correct
661 confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
662 email_text_parts(register_email).each do |part|
663 assert_match confirm_regex, part.body.to_s
665 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
668 assert_response :success
669 assert_template "users/confirm"
671 ActionMailer::Base.deliveries.clear
673 # Go to the confirmation page
674 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
675 assert_response :success
676 assert_template "users/confirm"
678 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
679 assert_response :redirect
681 assert_response :success
682 assert_template "site/welcome"
685 def test_user_create_github_success
686 OmniAuth.config.add_mock(:github, :uid => "123454321")
688 new_email = "newtester-github@osm.org"
689 display_name = "new_tester-github"
690 password = "testtest"
691 assert_difference("User.count") do
692 assert_difference("ActionMailer::Base.deliveries.size", 1) do
693 perform_enqueued_jobs do
695 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" } }
696 assert_response :redirect
697 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
699 assert_response :redirect
700 assert_redirected_to auth_success_path(:provider => "github")
702 assert_response :redirect
703 assert_redirected_to "/user/terms"
705 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }, :read_tou => 1 }
706 assert_response :redirect
713 assert_response :success
714 assert_template "users/confirm"
716 ActionMailer::Base.deliveries.clear
719 def test_user_create_github_failure
720 OmniAuth.config.mock_auth[:github] = :connection_failed
722 new_email = "newtester-github2@osm.org"
723 display_name = "new_tester-github2"
724 assert_difference("User.count", 0) do
725 assert_difference("ActionMailer::Base.deliveries.size", 0) do
726 perform_enqueued_jobs do
728 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" } }
729 assert_response :redirect
730 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
732 assert_response :redirect
733 assert_redirected_to auth_success_path(:provider => "github")
735 assert_response :redirect
736 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
738 assert_response :redirect
740 assert_response :success
741 assert_template "users/new"
746 ActionMailer::Base.deliveries.clear
749 def test_user_create_github_redirect
750 OmniAuth.config.add_mock(:github, :uid => "123454321")
752 new_email = "redirect_tester_github@osm.org"
753 display_name = "redirect_tester_github"
754 # nothing special about this page, just need a protected page to redirect back to.
755 referer = "/traces/mine"
756 assert_difference("User.count") do
757 assert_difference("ActionMailer::Base.deliveries.size", 1) do
758 perform_enqueued_jobs do
760 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
761 assert_response :redirect
762 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
764 assert_response :redirect
765 assert_redirected_to auth_success_path(:provider => "github")
767 assert_response :redirect
768 assert_redirected_to "/user/terms"
770 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }, :read_tou => 1 }
777 register_email = ActionMailer::Base.deliveries.first
779 assert_equal register_email.to.first, new_email
780 # Check that the confirm account url is correct
781 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
782 email_text_parts(register_email).each do |part|
783 assert_match confirm_regex, part.body.to_s
785 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
788 assert_response :success
789 assert_template "users/confirm"
791 ActionMailer::Base.deliveries.clear
793 # Go to the confirmation page
794 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
795 assert_response :success
796 assert_template "users/confirm"
798 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
799 assert_response :redirect
801 assert_response :success
802 assert_template "site/welcome"
805 def test_user_create_wikipedia_success
806 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
808 new_email = "newtester-wikipedia@osm.org"
809 display_name = "new_tester-wikipedia"
810 password = "testtest"
811 assert_difference("User.count") do
812 assert_difference("ActionMailer::Base.deliveries.size", 1) do
813 perform_enqueued_jobs do
815 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" } }
816 assert_response :redirect
817 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
819 assert_response :redirect
820 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
822 assert_response :redirect
823 assert_redirected_to "/user/terms"
825 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :auth_uid => "123454321", :pass_crypt => password, :pass_crypt_confirmation => password }, :read_tou => 1 }
826 assert_response :redirect
833 assert_response :success
834 assert_template "users/confirm"
836 ActionMailer::Base.deliveries.clear
839 def test_user_create_wikipedia_failure
840 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
842 new_email = "newtester-wikipedia2@osm.org"
843 display_name = "new_tester-wikipedia2"
844 assert_difference("User.count", 0) do
845 assert_difference("ActionMailer::Base.deliveries.size", 0) do
846 perform_enqueued_jobs do
848 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" } }
849 assert_response :redirect
850 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
852 assert_response :redirect
853 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
855 assert_response :redirect
856 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
858 assert_response :redirect
860 assert_response :success
861 assert_template "users/new"
866 ActionMailer::Base.deliveries.clear
869 def test_user_create_wikipedia_redirect
870 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
872 new_email = "redirect_tester_wikipedia@osm.org"
873 display_name = "redirect_tester_wikipedia"
874 # nothing special about this page, just need a protected page to redirect back to.
875 referer = "/traces/mine"
876 assert_difference("User.count") do
877 assert_difference("ActionMailer::Base.deliveries.size", 1) do
878 perform_enqueued_jobs do
880 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
881 assert_response :redirect
882 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
884 assert_response :redirect
885 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
887 assert_response :redirect
888 assert_redirected_to "/user/terms"
890 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :auth_uid => "http://localhost:1123/new.tester", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }, :read_tou => 1 }
897 register_email = ActionMailer::Base.deliveries.first
899 assert_equal register_email.to.first, new_email
900 # Check that the confirm account url is correct
901 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
902 email_text_parts(register_email).each do |part|
903 assert_match confirm_regex, part.body.to_s
905 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
908 assert_response :success
909 assert_template "users/confirm"
911 ActionMailer::Base.deliveries.clear
913 # Go to the confirmation page
914 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
915 assert_response :success
916 assert_template "users/confirm"
918 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
919 assert_response :redirect
921 assert_response :success
922 assert_template "site/welcome"