3 class UserCreationTest < ActionDispatch::IntegrationTest
7 OmniAuth.config.test_mode = true
9 stub_request(:get, /.*gravatar.com.*d=404/).to_return(:status => 404)
15 OmniAuth.config.mock_auth[:openid] = nil
16 OmniAuth.config.mock_auth[:google] = nil
17 OmniAuth.config.mock_auth[:facebook] = nil
18 OmniAuth.config.mock_auth[:windowslive] = nil
19 OmniAuth.config.mock_auth[:github] = nil
20 OmniAuth.config.mock_auth[:wikipedia] = nil
21 OmniAuth.config.test_mode = false
24 def test_create_user_form
25 I18n.available_locales.each do |locale|
27 get "/user/new", :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
29 assert_response :success
30 assert_template "users/new"
34 def test_user_create_submit_duplicate_email
35 I18n.available_locales.each do |locale|
36 dup_email = create(:user).email
37 display_name = "#{locale}_new_tester"
38 assert_difference("User.count", 0) do
39 assert_difference("ActionMailer::Base.deliveries.size", 0) do
40 perform_enqueued_jobs do
42 :params => { :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
43 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
47 assert_response :success
48 assert_template "users/new"
49 assert_equal locale.to_s, response.headers["Content-Language"] unless locale == :root
50 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
51 assert_no_missing_translations
55 def test_user_create_submit_duplicate_username
56 I18n.available_locales.each do |locale|
57 dup_display_name = create(:user).display_name
58 email = "#{locale}_new_tester"
59 assert_difference("User.count", 0) do
60 assert_difference("ActionMailer::Base.deliveries.size", 0) do
61 perform_enqueued_jobs do
63 :params => { :user => { :email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
64 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
68 assert_response :success
69 assert_template "users/new"
70 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
71 assert_no_missing_translations
75 def test_user_create_success
76 I18n.available_locales.each do |locale|
77 new_email = "#{locale}newtester@osm.org"
78 display_name = "#{locale}_new_tester"
80 assert_difference("User.count", 0) do
81 assert_difference("ActionMailer::Base.deliveries.size", 0) do
82 perform_enqueued_jobs do
84 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } }
89 assert_redirected_to "/user/terms"
91 assert_difference("User.count") do
92 assert_difference("ActionMailer::Base.deliveries.size", 1) do
93 perform_enqueued_jobs do
95 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
102 register_email = ActionMailer::Base.deliveries.first
104 assert_equal register_email.to.first, new_email
105 # Check that the confirm account url is correct
106 assert_match(/#{@url}/, register_email.body.to_s)
109 assert_response :success
110 assert_template "users/confirm"
112 ActionMailer::Base.deliveries.clear
116 # Check that the user can successfully recover their password
117 def lost_password_recovery_success
118 # Open the lost password form
119 # Submit the lost password form
121 # Submit the reset password token
122 # Check that the password has changed, and the user can login
125 def test_user_create_redirect
126 new_email = "redirect_tester@osm.org"
127 display_name = "redirect_tester"
128 password = "testtest"
129 # nothing special about this page, just need a protected page to redirect back to.
130 referer = "/traces/mine"
131 assert_difference("User.count") do
132 assert_difference("ActionMailer::Base.deliveries.size", 1) do
133 perform_enqueued_jobs do
135 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }, :referer => referer }
136 assert_redirected_to "/user/terms"
138 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password } }
145 register_email = ActionMailer::Base.deliveries.first
147 assert_equal register_email.to.first, new_email
148 # Check that the confirm account url is correct
149 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
150 email_text_parts(register_email).each do |part|
151 assert_match confirm_regex, part.body.to_s
153 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
156 assert_response :success
157 assert_template "users/confirm"
159 ActionMailer::Base.deliveries.clear
161 # Go to the confirmation page
162 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
163 assert_response :success
164 assert_template "users/confirm"
166 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
167 assert_response :redirect
169 assert_response :success
170 assert_template "site/welcome"
173 def test_user_create_openid_success
174 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
176 new_email = "newtester-openid@osm.org"
177 display_name = "new_tester-openid"
178 password = "testtest"
179 assert_difference("User.count") do
180 assert_difference("ActionMailer::Base.deliveries.size", 1) do
181 perform_enqueued_jobs do
183 :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 => "" } }
184 assert_response :redirect
185 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
187 assert_response :redirect
188 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
190 assert_response :redirect
191 assert_redirected_to "/user/terms"
193 :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 } }
194 assert_response :redirect
201 assert_response :success
202 assert_template "users/confirm"
204 ActionMailer::Base.deliveries.clear
207 def test_user_create_openid_failure
208 OmniAuth.config.mock_auth[:openid] = :connection_failed
210 new_email = "newtester-openid2@osm.org"
211 display_name = "new_tester-openid2"
212 assert_difference("User.count", 0) do
213 assert_difference("ActionMailer::Base.deliveries.size", 0) do
214 perform_enqueued_jobs do
216 :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 => "" } }
217 assert_response :redirect
218 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
220 assert_response :redirect
221 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
223 assert_response :redirect
224 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
226 assert_response :redirect
228 assert_response :success
229 assert_template "users/new"
234 ActionMailer::Base.deliveries.clear
237 def test_user_create_openid_redirect
238 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
240 new_email = "redirect_tester_openid@osm.org"
241 display_name = "redirect_tester_openid"
242 # nothing special about this page, just need a protected page to redirect back to.
243 referer = "/traces/mine"
244 assert_difference("User.count") do
245 assert_difference("ActionMailer::Base.deliveries.size", 1) do
246 perform_enqueued_jobs do
248 :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 }
249 assert_response :redirect
250 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
252 assert_response :redirect
253 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
255 assert_response :redirect
256 assert_redirected_to "/user/terms"
258 :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" } }
265 register_email = ActionMailer::Base.deliveries.first
267 assert_equal register_email.to.first, new_email
268 # Check that the confirm account url is correct
269 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
270 email_text_parts(register_email).each do |part|
271 assert_match confirm_regex, part.body.to_s
273 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
276 assert_response :success
277 assert_template "users/confirm"
279 ActionMailer::Base.deliveries.clear
281 # Go to the confirmation page
282 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
283 assert_response :success
284 assert_template "users/confirm"
286 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
287 assert_response :redirect
289 assert_response :success
290 assert_template "site/welcome"
293 def test_user_create_google_success
294 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
295 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
298 new_email = "newtester-google@osm.org"
299 display_name = "new_tester-google"
300 password = "testtest"
301 assert_difference("User.count") do
302 assert_difference("ActionMailer::Base.deliveries.size", 1) do
303 perform_enqueued_jobs do
305 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" } }
306 assert_response :redirect
307 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
309 assert_response :redirect
310 assert_redirected_to auth_success_path(:provider => "google")
312 assert_response :redirect
313 assert_redirected_to "/user/terms"
315 :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 } }
316 assert_response :redirect
323 assert_response :success
324 assert_template "users/confirm"
326 ActionMailer::Base.deliveries.clear
329 def test_user_create_google_failure
330 OmniAuth.config.mock_auth[:google] = :connection_failed
332 new_email = "newtester-google2@osm.org"
333 display_name = "new_tester-google2"
334 assert_difference("User.count", 0) do
335 assert_difference("ActionMailer::Base.deliveries.size", 0) do
336 perform_enqueued_jobs do
338 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" } }
339 assert_response :redirect
340 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
342 assert_response :redirect
343 assert_redirected_to auth_success_path(:provider => "google")
345 assert_response :redirect
346 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
348 assert_response :redirect
350 assert_response :success
351 assert_template "users/new"
356 ActionMailer::Base.deliveries.clear
359 def test_user_create_google_redirect
360 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
361 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
364 new_email = "redirect_tester_google@osm.org"
365 display_name = "redirect_tester_google"
366 # nothing special about this page, just need a protected page to redirect back to.
367 referer = "/traces/mine"
368 assert_difference("User.count") do
369 assert_difference("ActionMailer::Base.deliveries.size", 1) do
370 perform_enqueued_jobs do
372 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
373 assert_response :redirect
374 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
376 assert_response :redirect
377 assert_redirected_to auth_success_path(:provider => "google")
379 assert_response :redirect
380 assert_redirected_to "/user/terms"
382 :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" } }
389 register_email = ActionMailer::Base.deliveries.first
391 assert_equal register_email.to.first, new_email
392 # Check that the confirm account url is correct
393 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
394 email_text_parts(register_email).each do |part|
395 assert_match confirm_regex, part.body.to_s
397 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
400 assert_response :success
401 assert_template "users/confirm"
403 ActionMailer::Base.deliveries.clear
405 # Go to the confirmation page
406 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
407 assert_response :success
408 assert_template "users/confirm"
410 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
411 assert_response :redirect
413 assert_response :success
414 assert_template "site/welcome"
417 def test_user_create_facebook_success
418 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
420 new_email = "newtester-facebook@osm.org"
421 display_name = "new_tester-facebook"
422 password = "testtest"
423 assert_difference("User.count") do
424 assert_difference("ActionMailer::Base.deliveries.size", 1) do
425 perform_enqueued_jobs do
427 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" } }
428 assert_response :redirect
429 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
431 assert_response :redirect
432 assert_redirected_to auth_success_path(:provider => "facebook")
434 assert_response :redirect
435 assert_redirected_to "/user/terms"
437 :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 } }
438 assert_response :redirect
445 assert_response :success
446 assert_template "users/confirm"
448 ActionMailer::Base.deliveries.clear
451 def test_user_create_facebook_failure
452 OmniAuth.config.mock_auth[:facebook] = :connection_failed
454 new_email = "newtester-facebook2@osm.org"
455 display_name = "new_tester-facebook2"
456 assert_difference("User.count", 0) do
457 assert_difference("ActionMailer::Base.deliveries.size", 0) do
458 perform_enqueued_jobs do
460 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" } }
461 assert_response :redirect
462 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
464 assert_response :redirect
465 assert_redirected_to auth_success_path(:provider => "facebook")
467 assert_response :redirect
468 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
470 assert_response :redirect
472 assert_response :success
473 assert_template "users/new"
478 ActionMailer::Base.deliveries.clear
481 def test_user_create_facebook_redirect
482 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
484 new_email = "redirect_tester_facebook@osm.org"
485 display_name = "redirect_tester_facebook"
486 # nothing special about this page, just need a protected page to redirect back to.
487 referer = "/traces/mine"
488 assert_difference("User.count") do
489 assert_difference("ActionMailer::Base.deliveries.size", 1) do
490 perform_enqueued_jobs do
492 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
493 assert_response :redirect
494 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
496 assert_response :redirect
497 assert_redirected_to auth_success_path(:provider => "facebook")
499 assert_response :redirect
500 assert_redirected_to "/user/terms"
502 :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" } }
509 register_email = ActionMailer::Base.deliveries.first
511 assert_equal register_email.to.first, new_email
512 # Check that the confirm account url is correct
513 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
514 email_text_parts(register_email).each do |part|
515 assert_match confirm_regex, part.body.to_s
517 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
520 assert_response :success
521 assert_template "users/confirm"
523 ActionMailer::Base.deliveries.clear
525 # Go to the confirmation page
526 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
527 assert_response :success
528 assert_template "users/confirm"
530 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
531 assert_response :redirect
533 assert_response :success
534 assert_template "site/welcome"
537 def test_user_create_windowslive_success
538 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
540 new_email = "newtester-windowslive@osm.org"
541 display_name = "new_tester-windowslive"
542 password = "testtest"
543 assert_difference("User.count") do
544 assert_difference("ActionMailer::Base.deliveries.size", 1) do
545 perform_enqueued_jobs do
547 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" } }
548 assert_response :redirect
549 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
551 assert_response :redirect
552 assert_redirected_to auth_success_path(:provider => "windowslive")
554 assert_response :redirect
555 assert_redirected_to "/user/terms"
557 :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 } }
558 assert_response :redirect
565 assert_response :success
566 assert_template "users/confirm"
568 ActionMailer::Base.deliveries.clear
571 def test_user_create_windowslive_failure
572 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
574 new_email = "newtester-windowslive2@osm.org"
575 display_name = "new_tester-windowslive2"
576 assert_difference("User.count", 0) do
577 assert_difference("ActionMailer::Base.deliveries.size", 0) do
578 perform_enqueued_jobs do
580 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" } }
581 assert_response :redirect
582 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
584 assert_response :redirect
585 assert_redirected_to auth_success_path(:provider => "windowslive")
587 assert_response :redirect
588 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/user/new")
590 assert_response :redirect
592 assert_response :success
593 assert_template "users/new"
598 ActionMailer::Base.deliveries.clear
601 def test_user_create_windowslive_redirect
602 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
604 new_email = "redirect_tester_windowslive@osm.org"
605 display_name = "redirect_tester_windowslive"
606 # nothing special about this page, just need a protected page to redirect back to.
607 referer = "/traces/mine"
608 assert_difference("User.count") do
609 assert_difference("ActionMailer::Base.deliveries.size", 1) do
610 perform_enqueued_jobs do
612 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
613 assert_response :redirect
614 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
616 assert_response :redirect
617 assert_redirected_to auth_success_path(:provider => "windowslive")
619 assert_response :redirect
620 assert_redirected_to "/user/terms"
622 :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" } }
629 register_email = ActionMailer::Base.deliveries.first
631 assert_equal register_email.to.first, new_email
632 # Check that the confirm account url is correct
633 confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
634 email_text_parts(register_email).each do |part|
635 assert_match confirm_regex, part.body.to_s
637 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
640 assert_response :success
641 assert_template "users/confirm"
643 ActionMailer::Base.deliveries.clear
645 # Go to the confirmation page
646 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
647 assert_response :success
648 assert_template "users/confirm"
650 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
651 assert_response :redirect
653 assert_response :success
654 assert_template "site/welcome"
657 def test_user_create_github_success
658 OmniAuth.config.add_mock(:github, :uid => "123454321")
660 new_email = "newtester-github@osm.org"
661 display_name = "new_tester-github"
662 password = "testtest"
663 assert_difference("User.count") do
664 assert_difference("ActionMailer::Base.deliveries.size", 1) do
665 perform_enqueued_jobs do
667 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" } }
668 assert_response :redirect
669 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
671 assert_response :redirect
672 assert_redirected_to auth_success_path(:provider => "github")
674 assert_response :redirect
675 assert_redirected_to "/user/terms"
677 :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 } }
678 assert_response :redirect
685 assert_response :success
686 assert_template "users/confirm"
688 ActionMailer::Base.deliveries.clear
691 def test_user_create_github_failure
692 OmniAuth.config.mock_auth[:github] = :connection_failed
694 new_email = "newtester-github2@osm.org"
695 display_name = "new_tester-github2"
696 assert_difference("User.count", 0) do
697 assert_difference("ActionMailer::Base.deliveries.size", 0) do
698 perform_enqueued_jobs do
700 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" } }
701 assert_response :redirect
702 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
704 assert_response :redirect
705 assert_redirected_to auth_success_path(:provider => "github")
707 assert_response :redirect
708 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
710 assert_response :redirect
712 assert_response :success
713 assert_template "users/new"
718 ActionMailer::Base.deliveries.clear
721 def test_user_create_github_redirect
722 OmniAuth.config.add_mock(:github, :uid => "123454321")
724 new_email = "redirect_tester_github@osm.org"
725 display_name = "redirect_tester_github"
726 # nothing special about this page, just need a protected page to redirect back to.
727 referer = "/traces/mine"
728 assert_difference("User.count") do
729 assert_difference("ActionMailer::Base.deliveries.size", 1) do
730 perform_enqueued_jobs do
732 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
733 assert_response :redirect
734 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
736 assert_response :redirect
737 assert_redirected_to auth_success_path(:provider => "github")
739 assert_response :redirect
740 assert_redirected_to "/user/terms"
742 :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" } }
749 register_email = ActionMailer::Base.deliveries.first
751 assert_equal register_email.to.first, new_email
752 # Check that the confirm account url is correct
753 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
754 email_text_parts(register_email).each do |part|
755 assert_match confirm_regex, part.body.to_s
757 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
760 assert_response :success
761 assert_template "users/confirm"
763 ActionMailer::Base.deliveries.clear
765 # Go to the confirmation page
766 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
767 assert_response :success
768 assert_template "users/confirm"
770 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
771 assert_response :redirect
773 assert_response :success
774 assert_template "site/welcome"
777 def test_user_create_wikipedia_success
778 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
780 new_email = "newtester-wikipedia@osm.org"
781 display_name = "new_tester-wikipedia"
782 password = "testtest"
783 assert_difference("User.count") do
784 assert_difference("ActionMailer::Base.deliveries.size", 1) do
785 perform_enqueued_jobs do
787 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" } }
788 assert_response :redirect
789 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
791 assert_response :redirect
792 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
794 assert_response :redirect
795 assert_redirected_to "/user/terms"
797 :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 } }
798 assert_response :redirect
805 assert_response :success
806 assert_template "users/confirm"
808 ActionMailer::Base.deliveries.clear
811 def test_user_create_wikipedia_failure
812 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
814 new_email = "newtester-wikipedia2@osm.org"
815 display_name = "new_tester-wikipedia2"
816 assert_difference("User.count", 0) do
817 assert_difference("ActionMailer::Base.deliveries.size", 0) do
818 perform_enqueued_jobs do
820 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" } }
821 assert_response :redirect
822 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
824 assert_response :redirect
825 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
827 assert_response :redirect
828 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
830 assert_response :redirect
832 assert_response :success
833 assert_template "users/new"
838 ActionMailer::Base.deliveries.clear
841 def test_user_create_wikipedia_redirect
842 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
844 new_email = "redirect_tester_wikipedia@osm.org"
845 display_name = "redirect_tester_wikipedia"
846 # nothing special about this page, just need a protected page to redirect back to.
847 referer = "/traces/mine"
848 assert_difference("User.count") do
849 assert_difference("ActionMailer::Base.deliveries.size", 1) do
850 perform_enqueued_jobs do
852 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
853 assert_response :redirect
854 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
856 assert_response :redirect
857 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
859 assert_response :redirect
860 assert_redirected_to "/user/terms"
862 :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" } }
869 register_email = ActionMailer::Base.deliveries.first
871 assert_equal register_email.to.first, new_email
872 # Check that the confirm account url is correct
873 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
874 email_text_parts(register_email).each do |part|
875 assert_match confirm_regex, part.body.to_s
877 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
880 assert_response :success
881 assert_template "users/confirm"
883 ActionMailer::Base.deliveries.clear
885 # Go to the confirmation page
886 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
887 assert_response :success
888 assert_template "users/confirm"
890 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
891 assert_response :redirect
893 assert_response :success
894 assert_template "site/welcome"