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 "user/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
41 :params => { :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
42 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
45 assert_response :success
46 assert_template "user/new"
47 assert_equal locale.to_s, response.headers["Content-Language"] unless locale == :root
48 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
49 assert_no_missing_translations
53 def test_user_create_submit_duplicate_username
54 I18n.available_locales.each do |locale|
55 dup_display_name = create(:user).display_name
56 email = "#{locale}_new_tester"
57 assert_difference("User.count", 0) do
58 assert_difference("ActionMailer::Base.deliveries.size", 0) do
60 :params => { :user => { :email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
61 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
64 assert_response :success
65 assert_template "user/new"
66 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
67 assert_no_missing_translations
71 def test_user_create_success
72 I18n.available_locales.each do |locale|
73 new_email = "#{locale}newtester@osm.org"
74 display_name = "#{locale}_new_tester"
76 assert_difference("User.count", 0) do
77 assert_difference("ActionMailer::Base.deliveries.size", 0) do
79 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } }
83 assert_redirected_to "/user/terms"
85 assert_difference("User.count") do
86 assert_difference("ActionMailer::Base.deliveries.size", 1) do
88 :headers => { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
94 register_email = ActionMailer::Base.deliveries.first
96 assert_equal register_email.to.first, new_email
97 # Check that the confirm account url is correct
98 assert_match /#{@url}/, register_email.body.to_s
101 assert_response :success
102 assert_template "user/confirm"
104 ActionMailer::Base.deliveries.clear
108 # Check that the user can successfully recover their password
109 def lost_password_recovery_success
110 # Open the lost password form
111 # Submit the lost password form
113 # Submit the reset password token
114 # Check that the password has changed, and the user can login
117 def test_user_create_redirect
118 new_email = "redirect_tester@osm.org"
119 display_name = "redirect_tester"
120 password = "testtest"
121 # nothing special about this page, just need a protected page to redirect back to.
122 referer = "/traces/mine"
123 assert_difference("User.count") do
124 assert_difference("ActionMailer::Base.deliveries.size", 1) do
126 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }, :referer => referer }
127 assert_redirected_to "/user/terms"
129 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password } }
135 register_email = ActionMailer::Base.deliveries.first
137 assert_equal register_email.to.first, new_email
138 # Check that the confirm account url is correct
139 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
140 email_text_parts(register_email).each do |part|
141 assert_match confirm_regex, part.body.to_s
143 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
146 assert_response :success
147 assert_template "user/confirm"
149 ActionMailer::Base.deliveries.clear
151 # Go to the confirmation page
152 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
153 assert_response :success
154 assert_template "user/confirm"
156 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
157 assert_response :redirect
159 assert_response :success
160 assert_template "site/welcome"
163 def test_user_create_openid_success
164 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
166 new_email = "newtester-openid@osm.org"
167 display_name = "new_tester-openid"
168 password = "testtest"
169 assert_difference("User.count") do
170 assert_difference("ActionMailer::Base.deliveries.size", 1) do
172 :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 => "" } }
173 assert_response :redirect
174 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
176 assert_response :redirect
177 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
179 assert_response :redirect
180 assert_redirected_to "/user/terms"
182 :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 } }
183 assert_response :redirect
189 assert_response :success
190 assert_template "user/confirm"
192 ActionMailer::Base.deliveries.clear
195 def test_user_create_openid_failure
196 OmniAuth.config.mock_auth[:openid] = :connection_failed
198 new_email = "newtester-openid2@osm.org"
199 display_name = "new_tester-openid2"
200 assert_difference("User.count", 0) do
201 assert_difference("ActionMailer::Base.deliveries.size", 0) do
203 :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 => "" } }
204 assert_response :redirect
205 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
207 assert_response :redirect
208 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
210 assert_response :redirect
211 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
213 assert_response :redirect
215 assert_response :success
216 assert_template "user/new"
220 ActionMailer::Base.deliveries.clear
223 def test_user_create_openid_redirect
224 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
226 new_email = "redirect_tester_openid@osm.org"
227 display_name = "redirect_tester_openid"
228 # nothing special about this page, just need a protected page to redirect back to.
229 referer = "/traces/mine"
230 assert_difference("User.count") do
231 assert_difference("ActionMailer::Base.deliveries.size", 1) do
233 :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 }
234 assert_response :redirect
235 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
237 assert_response :redirect
238 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
240 assert_response :redirect
241 assert_redirected_to "/user/terms"
243 :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" } }
249 register_email = ActionMailer::Base.deliveries.first
251 assert_equal register_email.to.first, new_email
252 # Check that the confirm account url is correct
253 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
254 email_text_parts(register_email).each do |part|
255 assert_match confirm_regex, part.body.to_s
257 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
260 assert_response :success
261 assert_template "user/confirm"
263 ActionMailer::Base.deliveries.clear
265 # Go to the confirmation page
266 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
267 assert_response :success
268 assert_template "user/confirm"
270 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
271 assert_response :redirect
273 assert_response :success
274 assert_template "site/welcome"
277 def test_user_create_google_success
278 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
279 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
282 new_email = "newtester-google@osm.org"
283 display_name = "new_tester-google"
284 password = "testtest"
285 assert_difference("User.count") do
286 assert_difference("ActionMailer::Base.deliveries.size", 1) do
288 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" } }
289 assert_response :redirect
290 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
292 assert_response :redirect
293 assert_redirected_to auth_success_path(:provider => "google")
295 assert_response :redirect
296 assert_redirected_to "/user/terms"
298 :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 } }
299 assert_response :redirect
305 assert_response :success
306 assert_template "user/confirm"
308 ActionMailer::Base.deliveries.clear
311 def test_user_create_google_failure
312 OmniAuth.config.mock_auth[:google] = :connection_failed
314 new_email = "newtester-google2@osm.org"
315 display_name = "new_tester-google2"
316 assert_difference("User.count", 0) do
317 assert_difference("ActionMailer::Base.deliveries.size", 0) do
319 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" } }
320 assert_response :redirect
321 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
323 assert_response :redirect
324 assert_redirected_to auth_success_path(:provider => "google")
326 assert_response :redirect
327 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
329 assert_response :redirect
331 assert_response :success
332 assert_template "user/new"
336 ActionMailer::Base.deliveries.clear
339 def test_user_create_google_redirect
340 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
341 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
344 new_email = "redirect_tester_google@osm.org"
345 display_name = "redirect_tester_google"
346 # nothing special about this page, just need a protected page to redirect back to.
347 referer = "/traces/mine"
348 assert_difference("User.count") do
349 assert_difference("ActionMailer::Base.deliveries.size", 1) do
351 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
352 assert_response :redirect
353 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
355 assert_response :redirect
356 assert_redirected_to auth_success_path(:provider => "google")
358 assert_response :redirect
359 assert_redirected_to "/user/terms"
361 :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" } }
367 register_email = ActionMailer::Base.deliveries.first
369 assert_equal register_email.to.first, new_email
370 # Check that the confirm account url is correct
371 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
372 email_text_parts(register_email).each do |part|
373 assert_match confirm_regex, part.body.to_s
375 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
378 assert_response :success
379 assert_template "user/confirm"
381 ActionMailer::Base.deliveries.clear
383 # Go to the confirmation page
384 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
385 assert_response :success
386 assert_template "user/confirm"
388 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
389 assert_response :redirect
391 assert_response :success
392 assert_template "site/welcome"
395 def test_user_create_facebook_success
396 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
398 new_email = "newtester-facebook@osm.org"
399 display_name = "new_tester-facebook"
400 password = "testtest"
401 assert_difference("User.count") do
402 assert_difference("ActionMailer::Base.deliveries.size", 1) do
404 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" } }
405 assert_response :redirect
406 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
408 assert_response :redirect
409 assert_redirected_to auth_success_path(:provider => "facebook")
411 assert_response :redirect
412 assert_redirected_to "/user/terms"
414 :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 } }
415 assert_response :redirect
421 assert_response :success
422 assert_template "user/confirm"
424 ActionMailer::Base.deliveries.clear
427 def test_user_create_facebook_failure
428 OmniAuth.config.mock_auth[:facebook] = :connection_failed
430 new_email = "newtester-facebook2@osm.org"
431 display_name = "new_tester-facebook2"
432 assert_difference("User.count", 0) do
433 assert_difference("ActionMailer::Base.deliveries.size", 0) do
435 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" } }
436 assert_response :redirect
437 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
439 assert_response :redirect
440 assert_redirected_to auth_success_path(:provider => "facebook")
442 assert_response :redirect
443 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
445 assert_response :redirect
447 assert_response :success
448 assert_template "user/new"
452 ActionMailer::Base.deliveries.clear
455 def test_user_create_facebook_redirect
456 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
458 new_email = "redirect_tester_facebook@osm.org"
459 display_name = "redirect_tester_facebook"
460 # nothing special about this page, just need a protected page to redirect back to.
461 referer = "/traces/mine"
462 assert_difference("User.count") do
463 assert_difference("ActionMailer::Base.deliveries.size", 1) do
465 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
466 assert_response :redirect
467 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
469 assert_response :redirect
470 assert_redirected_to auth_success_path(:provider => "facebook")
472 assert_response :redirect
473 assert_redirected_to "/user/terms"
475 :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" } }
481 register_email = ActionMailer::Base.deliveries.first
483 assert_equal register_email.to.first, new_email
484 # Check that the confirm account url is correct
485 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
486 email_text_parts(register_email).each do |part|
487 assert_match confirm_regex, part.body.to_s
489 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
492 assert_response :success
493 assert_template "user/confirm"
495 ActionMailer::Base.deliveries.clear
497 # Go to the confirmation page
498 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
499 assert_response :success
500 assert_template "user/confirm"
502 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
503 assert_response :redirect
505 assert_response :success
506 assert_template "site/welcome"
509 def test_user_create_windowslive_success
510 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
512 new_email = "newtester-windowslive@osm.org"
513 display_name = "new_tester-windowslive"
514 password = "testtest"
515 assert_difference("User.count") do
516 assert_difference("ActionMailer::Base.deliveries.size", 1) do
518 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" } }
519 assert_response :redirect
520 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
522 assert_response :redirect
523 assert_redirected_to auth_success_path(:provider => "windowslive")
525 assert_response :redirect
526 assert_redirected_to "/user/terms"
528 :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 } }
529 assert_response :redirect
535 assert_response :success
536 assert_template "user/confirm"
538 ActionMailer::Base.deliveries.clear
541 def test_user_create_windowslive_failure
542 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
544 new_email = "newtester-windowslive2@osm.org"
545 display_name = "new_tester-windowslive2"
546 assert_difference("User.count", 0) do
547 assert_difference("ActionMailer::Base.deliveries.size", 0) do
549 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" } }
550 assert_response :redirect
551 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
553 assert_response :redirect
554 assert_redirected_to auth_success_path(:provider => "windowslive")
556 assert_response :redirect
557 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/user/new")
559 assert_response :redirect
561 assert_response :success
562 assert_template "user/new"
566 ActionMailer::Base.deliveries.clear
569 def test_user_create_windowslive_redirect
570 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
572 new_email = "redirect_tester_windowslive@osm.org"
573 display_name = "redirect_tester_windowslive"
574 # nothing special about this page, just need a protected page to redirect back to.
575 referer = "/traces/mine"
576 assert_difference("User.count") do
577 assert_difference("ActionMailer::Base.deliveries.size", 1) do
579 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
580 assert_response :redirect
581 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
583 assert_response :redirect
584 assert_redirected_to auth_success_path(:provider => "windowslive")
586 assert_response :redirect
587 assert_redirected_to "/user/terms"
589 :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" } }
595 register_email = ActionMailer::Base.deliveries.first
597 assert_equal register_email.to.first, new_email
598 # Check that the confirm account url is correct
599 confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
600 email_text_parts(register_email).each do |part|
601 assert_match confirm_regex, part.body.to_s
603 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
606 assert_response :success
607 assert_template "user/confirm"
609 ActionMailer::Base.deliveries.clear
611 # Go to the confirmation page
612 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
613 assert_response :success
614 assert_template "user/confirm"
616 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
617 assert_response :redirect
619 assert_response :success
620 assert_template "site/welcome"
623 def test_user_create_github_success
624 OmniAuth.config.add_mock(:github, :uid => "123454321")
626 new_email = "newtester-github@osm.org"
627 display_name = "new_tester-github"
628 password = "testtest"
629 assert_difference("User.count") do
630 assert_difference("ActionMailer::Base.deliveries.size", 1) do
632 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" } }
633 assert_response :redirect
634 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
636 assert_response :redirect
637 assert_redirected_to auth_success_path(:provider => "github")
639 assert_response :redirect
640 assert_redirected_to "/user/terms"
642 :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 } }
643 assert_response :redirect
649 assert_response :success
650 assert_template "user/confirm"
652 ActionMailer::Base.deliveries.clear
655 def test_user_create_github_failure
656 OmniAuth.config.mock_auth[:github] = :connection_failed
658 new_email = "newtester-github2@osm.org"
659 display_name = "new_tester-github2"
660 assert_difference("User.count", 0) do
661 assert_difference("ActionMailer::Base.deliveries.size", 0) do
663 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" } }
664 assert_response :redirect
665 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
667 assert_response :redirect
668 assert_redirected_to auth_success_path(:provider => "github")
670 assert_response :redirect
671 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
673 assert_response :redirect
675 assert_response :success
676 assert_template "user/new"
680 ActionMailer::Base.deliveries.clear
683 def test_user_create_github_redirect
684 OmniAuth.config.add_mock(:github, :uid => "123454321")
686 new_email = "redirect_tester_github@osm.org"
687 display_name = "redirect_tester_github"
688 # nothing special about this page, just need a protected page to redirect back to.
689 referer = "/traces/mine"
690 assert_difference("User.count") do
691 assert_difference("ActionMailer::Base.deliveries.size", 1) do
693 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
694 assert_response :redirect
695 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
697 assert_response :redirect
698 assert_redirected_to auth_success_path(:provider => "github")
700 assert_response :redirect
701 assert_redirected_to "/user/terms"
703 :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" } }
709 register_email = ActionMailer::Base.deliveries.first
711 assert_equal register_email.to.first, new_email
712 # Check that the confirm account url is correct
713 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
714 email_text_parts(register_email).each do |part|
715 assert_match confirm_regex, part.body.to_s
717 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
720 assert_response :success
721 assert_template "user/confirm"
723 ActionMailer::Base.deliveries.clear
725 # Go to the confirmation page
726 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
727 assert_response :success
728 assert_template "user/confirm"
730 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
731 assert_response :redirect
733 assert_response :success
734 assert_template "site/welcome"
737 def test_user_create_wikipedia_success
738 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
740 new_email = "newtester-wikipedia@osm.org"
741 display_name = "new_tester-wikipedia"
742 password = "testtest"
743 assert_difference("User.count") do
744 assert_difference("ActionMailer::Base.deliveries.size", 1) do
746 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" } }
747 assert_response :redirect
748 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
750 assert_response :redirect
751 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
753 assert_response :redirect
754 assert_redirected_to "/user/terms"
756 :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 } }
757 assert_response :redirect
763 assert_response :success
764 assert_template "user/confirm"
766 ActionMailer::Base.deliveries.clear
769 def test_user_create_wikipedia_failure
770 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
772 new_email = "newtester-wikipedia2@osm.org"
773 display_name = "new_tester-wikipedia2"
774 assert_difference("User.count", 0) do
775 assert_difference("ActionMailer::Base.deliveries.size", 0) do
777 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" } }
778 assert_response :redirect
779 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
781 assert_response :redirect
782 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
784 assert_response :redirect
785 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
787 assert_response :redirect
789 assert_response :success
790 assert_template "user/new"
794 ActionMailer::Base.deliveries.clear
797 def test_user_create_wikipedia_redirect
798 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
800 new_email = "redirect_tester_wikipedia@osm.org"
801 display_name = "redirect_tester_wikipedia"
802 # nothing special about this page, just need a protected page to redirect back to.
803 referer = "/traces/mine"
804 assert_difference("User.count") do
805 assert_difference("ActionMailer::Base.deliveries.size", 1) do
807 :params => { :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer }
808 assert_response :redirect
809 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
811 assert_response :redirect
812 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
814 assert_response :redirect
815 assert_redirected_to "/user/terms"
817 :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" } }
823 register_email = ActionMailer::Base.deliveries.first
825 assert_equal register_email.to.first, new_email
826 # Check that the confirm account url is correct
827 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
828 email_text_parts(register_email).each do |part|
829 assert_match confirm_regex, part.body.to_s
831 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
834 assert_response :success
835 assert_template "user/confirm"
837 ActionMailer::Base.deliveries.clear
839 # Go to the confirmation page
840 get "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
841 assert_response :success
842 assert_template "user/confirm"
844 post "/user/#{display_name}/confirm", :params => { :confirm_string => confirm_string }
845 assert_response :redirect
847 assert_response :success
848 assert_template "site/welcome"