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|
26 get_via_redirect "/user/new", {}, { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
27 assert_response :success
28 assert_template "user/new"
32 def test_user_create_submit_duplicate_email
33 I18n.available_locales.each do |locale|
34 dup_email = create(:user).email
35 display_name = "#{locale}_new_tester"
36 assert_difference("User.count", 0) do
37 assert_difference("ActionMailer::Base.deliveries.size", 0) do
39 { :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
40 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
43 assert_response :success
44 assert_template "user/new"
45 assert_equal locale.to_s, response.headers["Content-Language"] unless locale == :root
46 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_email"
47 assert_no_missing_translations
51 def test_user_create_submit_duplicate_username
52 I18n.available_locales.each do |locale|
53 dup_display_name = create(:user).display_name
54 email = "#{locale}_new_tester"
55 assert_difference("User.count", 0) do
56 assert_difference("ActionMailer::Base.deliveries.size", 0) do
58 { :user => { :email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" } },
59 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
62 assert_response :success
63 assert_template "user/new"
64 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
65 assert_no_missing_translations
69 def test_user_create_success
70 I18n.available_locales.each do |locale|
71 new_email = "#{locale}newtester@osm.org"
72 display_name = "#{locale}_new_tester"
74 assert_difference("User.count", 0) do
75 assert_difference("ActionMailer::Base.deliveries.size", 0) do
77 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest" }
81 assert_redirected_to "/user/terms"
83 assert_difference("User.count") do
84 assert_difference("ActionMailer::Base.deliveries.size", 1) do
85 post_via_redirect "/user/save", {},
86 { "HTTP_ACCEPT_LANGUAGE" => locale.to_s }
91 register_email = ActionMailer::Base.deliveries.first
93 assert_equal register_email.to.first, new_email
94 # Check that the confirm account url is correct
95 assert_match /#{@url}/, register_email.body.to_s
98 assert_response :success
99 assert_template "user/confirm"
101 ActionMailer::Base.deliveries.clear
105 # Check that the user can successfully recover their password
106 def lost_password_recovery_success
107 # Open the lost password form
108 # Submit the lost password form
110 # Submit the reset password token
111 # Check that the password has changed, and the user can login
114 def test_user_create_redirect
115 new_email = "redirect_tester@osm.org"
116 display_name = "redirect_tester"
117 password = "testtest"
118 # nothing special about this page, just need a protected page to redirect back to.
119 referer = "/traces/mine"
120 assert_difference("User.count") do
121 assert_difference("ActionMailer::Base.deliveries.size", 1) do
123 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }, :referer => referer
124 assert_redirected_to "/user/terms"
125 post_via_redirect "/user/save",
126 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password }
131 register_email = ActionMailer::Base.deliveries.first
133 assert_equal register_email.to.first, new_email
134 # Check that the confirm account url is correct
135 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
136 email_text_parts(register_email).each do |part|
137 assert_match confirm_regex, part.body.to_s
139 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
142 assert_response :success
143 assert_template "user/confirm"
145 ActionMailer::Base.deliveries.clear
147 # Go to the confirmation page
148 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
149 assert_response :success
150 assert_template "user/confirm"
152 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
153 assert_response :redirect
155 assert_response :success
156 assert_template "site/welcome"
159 def test_user_create_openid_success
160 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
162 new_email = "newtester-openid@osm.org"
163 display_name = "new_tester-openid"
164 password = "testtest"
165 assert_difference("User.count") do
166 assert_difference("ActionMailer::Base.deliveries.size", 1) do
168 :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 => "" }
169 assert_response :redirect
170 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
172 assert_response :redirect
173 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
175 assert_response :redirect
176 assert_redirected_to "/user/terms"
178 :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 }
179 assert_response :redirect
185 assert_response :success
186 assert_template "user/confirm"
188 ActionMailer::Base.deliveries.clear
191 def test_user_create_openid_failure
192 OmniAuth.config.mock_auth[:openid] = :connection_failed
194 new_email = "newtester-openid2@osm.org"
195 display_name = "new_tester-openid2"
196 assert_difference("User.count", 0) do
197 assert_difference("ActionMailer::Base.deliveries.size", 0) do
199 :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 => "" }
200 assert_response :redirect
201 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
203 assert_response :redirect
204 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
206 assert_response :redirect
207 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/user/new")
209 assert_response :redirect
211 assert_response :success
212 assert_template "user/new"
216 ActionMailer::Base.deliveries.clear
219 def test_user_create_openid_redirect
220 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/new.tester")
222 new_email = "redirect_tester_openid@osm.org"
223 display_name = "redirect_tester_openid"
224 # nothing special about this page, just need a protected page to redirect back to.
225 referer = "/traces/mine"
226 assert_difference("User.count") do
227 assert_difference("ActionMailer::Base.deliveries.size", 1) do
229 :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
230 assert_response :redirect
231 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
233 assert_response :redirect
234 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/new.tester", :origin => "/user/new")
236 assert_response :redirect
237 assert_redirected_to "/user/terms"
238 post_via_redirect "/user/save",
239 :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" }
244 register_email = ActionMailer::Base.deliveries.first
246 assert_equal register_email.to.first, new_email
247 # Check that the confirm account url is correct
248 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
249 email_text_parts(register_email).each do |part|
250 assert_match confirm_regex, part.body.to_s
252 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
255 assert_response :success
256 assert_template "user/confirm"
258 ActionMailer::Base.deliveries.clear
260 # Go to the confirmation page
261 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
262 assert_response :success
263 assert_template "user/confirm"
265 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
266 assert_response :redirect
268 assert_response :success
269 assert_template "site/welcome"
272 def test_user_create_google_success
273 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
274 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
277 new_email = "newtester-google@osm.org"
278 display_name = "new_tester-google"
279 password = "testtest"
280 assert_difference("User.count") do
281 assert_difference("ActionMailer::Base.deliveries.size", 1) do
283 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }
284 assert_response :redirect
285 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
287 assert_response :redirect
288 assert_redirected_to auth_success_path(:provider => "google")
290 assert_response :redirect
291 assert_redirected_to "/user/terms"
293 :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 }
294 assert_response :redirect
300 assert_response :success
301 assert_template "user/confirm"
303 ActionMailer::Base.deliveries.clear
306 def test_user_create_google_failure
307 OmniAuth.config.mock_auth[:google] = :connection_failed
309 new_email = "newtester-google2@osm.org"
310 display_name = "new_tester-google2"
311 assert_difference("User.count", 0) do
312 assert_difference("ActionMailer::Base.deliveries.size", 0) do
314 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }
315 assert_response :redirect
316 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
318 assert_response :redirect
319 assert_redirected_to auth_success_path(:provider => "google")
321 assert_response :redirect
322 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/user/new")
324 assert_response :redirect
326 assert_response :success
327 assert_template "user/new"
331 ActionMailer::Base.deliveries.clear
334 def test_user_create_google_redirect
335 OmniAuth.config.add_mock(:google, :uid => "123454321", :extra => {
336 :id_info => { "openid_id" => "http://localhost:1123/new.tester" }
339 new_email = "redirect_tester_google@osm.org"
340 display_name = "redirect_tester_google"
341 # nothing special about this page, just need a protected page to redirect back to.
342 referer = "/traces/mine"
343 assert_difference("User.count") do
344 assert_difference("ActionMailer::Base.deliveries.size", 1) do
346 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "google", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
347 assert_response :redirect
348 assert_redirected_to auth_path(:provider => "google", :origin => "/user/new")
350 assert_response :redirect
351 assert_redirected_to auth_success_path(:provider => "google")
353 assert_response :redirect
354 assert_redirected_to "/user/terms"
355 post_via_redirect "/user/save",
356 :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" }
361 register_email = ActionMailer::Base.deliveries.first
363 assert_equal register_email.to.first, new_email
364 # Check that the confirm account url is correct
365 confirm_regex = Regexp.new("/user/redirect_tester_google/confirm\\?confirm_string=([a-zA-Z0-9]*)")
366 email_text_parts(register_email).each do |part|
367 assert_match confirm_regex, part.body.to_s
369 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
372 assert_response :success
373 assert_template "user/confirm"
375 ActionMailer::Base.deliveries.clear
377 # Go to the confirmation page
378 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
379 assert_response :success
380 assert_template "user/confirm"
382 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
383 assert_response :redirect
385 assert_response :success
386 assert_template "site/welcome"
389 def test_user_create_facebook_success
390 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
392 new_email = "newtester-facebook@osm.org"
393 display_name = "new_tester-facebook"
394 password = "testtest"
395 assert_difference("User.count") do
396 assert_difference("ActionMailer::Base.deliveries.size", 1) do
398 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }
399 assert_response :redirect
400 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
402 assert_response :redirect
403 assert_redirected_to auth_success_path(:provider => "facebook")
405 assert_response :redirect
406 assert_redirected_to "/user/terms"
408 :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 }
409 assert_response :redirect
415 assert_response :success
416 assert_template "user/confirm"
418 ActionMailer::Base.deliveries.clear
421 def test_user_create_facebook_failure
422 OmniAuth.config.mock_auth[:facebook] = :connection_failed
424 new_email = "newtester-facebook2@osm.org"
425 display_name = "new_tester-facebook2"
426 assert_difference("User.count", 0) do
427 assert_difference("ActionMailer::Base.deliveries.size", 0) do
429 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }
430 assert_response :redirect
431 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
433 assert_response :redirect
434 assert_redirected_to auth_success_path(:provider => "facebook")
436 assert_response :redirect
437 assert_redirected_to auth_failure_path(:strategy => "facebook", :message => "connection_failed", :origin => "/user/new")
439 assert_response :redirect
441 assert_response :success
442 assert_template "user/new"
446 ActionMailer::Base.deliveries.clear
449 def test_user_create_facebook_redirect
450 OmniAuth.config.add_mock(:facebook, :uid => "123454321")
452 new_email = "redirect_tester_facebook@osm.org"
453 display_name = "redirect_tester_facebook"
454 # nothing special about this page, just need a protected page to redirect back to.
455 referer = "/traces/mine"
456 assert_difference("User.count") do
457 assert_difference("ActionMailer::Base.deliveries.size", 1) do
459 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "facebook", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
460 assert_response :redirect
461 assert_redirected_to auth_path(:provider => "facebook", :origin => "/user/new")
463 assert_response :redirect
464 assert_redirected_to auth_success_path(:provider => "facebook")
466 assert_response :redirect
467 assert_redirected_to "/user/terms"
468 post_via_redirect "/user/save",
469 :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" }
474 register_email = ActionMailer::Base.deliveries.first
476 assert_equal register_email.to.first, new_email
477 # Check that the confirm account url is correct
478 confirm_regex = Regexp.new("/user/redirect_tester_facebook/confirm\\?confirm_string=([a-zA-Z0-9]*)")
479 email_text_parts(register_email).each do |part|
480 assert_match confirm_regex, part.body.to_s
482 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
485 assert_response :success
486 assert_template "user/confirm"
488 ActionMailer::Base.deliveries.clear
490 # Go to the confirmation page
491 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
492 assert_response :success
493 assert_template "user/confirm"
495 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
496 assert_response :redirect
498 assert_response :success
499 assert_template "site/welcome"
502 def test_user_create_windowslive_success
503 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
505 new_email = "newtester-windowslive@osm.org"
506 display_name = "new_tester-windowslive"
507 password = "testtest"
508 assert_difference("User.count") do
509 assert_difference("ActionMailer::Base.deliveries.size", 1) do
511 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }
512 assert_response :redirect
513 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
515 assert_response :redirect
516 assert_redirected_to auth_success_path(:provider => "windowslive")
518 assert_response :redirect
519 assert_redirected_to "/user/terms"
521 :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 }
522 assert_response :redirect
528 assert_response :success
529 assert_template "user/confirm"
531 ActionMailer::Base.deliveries.clear
534 def test_user_create_windowslive_failure
535 OmniAuth.config.mock_auth[:windowslive] = :connection_failed
537 new_email = "newtester-windowslive2@osm.org"
538 display_name = "new_tester-windowslive2"
539 assert_difference("User.count", 0) do
540 assert_difference("ActionMailer::Base.deliveries.size", 0) do
542 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }
543 assert_response :redirect
544 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
546 assert_response :redirect
547 assert_redirected_to auth_success_path(:provider => "windowslive")
549 assert_response :redirect
550 assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/user/new")
552 assert_response :redirect
554 assert_response :success
555 assert_template "user/new"
559 ActionMailer::Base.deliveries.clear
562 def test_user_create_windowslive_redirect
563 OmniAuth.config.add_mock(:windowslive, :uid => "123454321")
565 new_email = "redirect_tester_windowslive@osm.org"
566 display_name = "redirect_tester_windowslive"
567 # nothing special about this page, just need a protected page to redirect back to.
568 referer = "/traces/mine"
569 assert_difference("User.count") do
570 assert_difference("ActionMailer::Base.deliveries.size", 1) do
572 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "windowslive", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
573 assert_response :redirect
574 assert_redirected_to auth_path(:provider => "windowslive", :origin => "/user/new")
576 assert_response :redirect
577 assert_redirected_to auth_success_path(:provider => "windowslive")
579 assert_response :redirect
580 assert_redirected_to "/user/terms"
581 post_via_redirect "/user/save",
582 :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" }
587 register_email = ActionMailer::Base.deliveries.first
589 assert_equal register_email.to.first, new_email
590 # Check that the confirm account url is correct
591 confirm_regex = Regexp.new("/user/redirect_tester_windowslive/confirm\\?confirm_string=([a-zA-Z0-9]*)")
592 email_text_parts(register_email).each do |part|
593 assert_match confirm_regex, part.body.to_s
595 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
598 assert_response :success
599 assert_template "user/confirm"
601 ActionMailer::Base.deliveries.clear
603 # Go to the confirmation page
604 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
605 assert_response :success
606 assert_template "user/confirm"
608 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
609 assert_response :redirect
611 assert_response :success
612 assert_template "site/welcome"
615 def test_user_create_github_success
616 OmniAuth.config.add_mock(:github, :uid => "123454321")
618 new_email = "newtester-github@osm.org"
619 display_name = "new_tester-github"
620 password = "testtest"
621 assert_difference("User.count") do
622 assert_difference("ActionMailer::Base.deliveries.size", 1) do
624 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" }
625 assert_response :redirect
626 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
628 assert_response :redirect
629 assert_redirected_to auth_success_path(:provider => "github", :origin => "/user/new")
631 assert_response :redirect
632 assert_redirected_to "/user/terms"
634 :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 }
635 assert_response :redirect
641 assert_response :success
642 assert_template "user/confirm"
644 ActionMailer::Base.deliveries.clear
647 def test_user_create_github_failure
648 OmniAuth.config.mock_auth[:github] = :connection_failed
650 new_email = "newtester-github2@osm.org"
651 display_name = "new_tester-github2"
652 assert_difference("User.count", 0) do
653 assert_difference("ActionMailer::Base.deliveries.size", 0) do
655 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" }
656 assert_response :redirect
657 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
659 assert_response :redirect
660 assert_redirected_to auth_success_path(:provider => "github", :origin => "/user/new")
662 assert_response :redirect
663 assert_redirected_to auth_failure_path(:strategy => "github", :message => "connection_failed", :origin => "/user/new")
665 assert_response :redirect
667 assert_response :success
668 assert_template "user/new"
672 ActionMailer::Base.deliveries.clear
675 def test_user_create_github_redirect
676 OmniAuth.config.add_mock(:github, :uid => "123454321")
678 new_email = "redirect_tester_github@osm.org"
679 display_name = "redirect_tester_github"
680 # nothing special about this page, just need a protected page to redirect back to.
681 referer = "/traces/mine"
682 assert_difference("User.count") do
683 assert_difference("ActionMailer::Base.deliveries.size", 1) do
685 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "github", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
686 assert_response :redirect
687 assert_redirected_to auth_path(:provider => "github", :origin => "/user/new")
689 assert_response :redirect
690 assert_redirected_to auth_success_path(:provider => "github", :origin => "/user/new")
692 assert_response :redirect
693 assert_redirected_to "/user/terms"
694 post_via_redirect "/user/save",
695 :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" }
700 register_email = ActionMailer::Base.deliveries.first
702 assert_equal register_email.to.first, new_email
703 # Check that the confirm account url is correct
704 confirm_regex = Regexp.new("/user/redirect_tester_github/confirm\\?confirm_string=([a-zA-Z0-9]*)")
705 email_text_parts(register_email).each do |part|
706 assert_match confirm_regex, part.body.to_s
708 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
711 assert_response :success
712 assert_template "user/confirm"
714 ActionMailer::Base.deliveries.clear
716 # Go to the confirmation page
717 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
718 assert_response :success
719 assert_template "user/confirm"
721 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
722 assert_response :redirect
724 assert_response :success
725 assert_template "site/welcome"
728 def test_user_create_wikipedia_success
729 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
731 new_email = "newtester-wikipedia@osm.org"
732 display_name = "new_tester-wikipedia"
733 password = "testtest"
734 assert_difference("User.count") do
735 assert_difference("ActionMailer::Base.deliveries.size", 1) do
737 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" }
738 assert_response :redirect
739 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
741 assert_response :redirect
742 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
744 assert_response :redirect
745 assert_redirected_to "/user/terms"
747 :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 }
748 assert_response :redirect
754 assert_response :success
755 assert_template "user/confirm"
757 ActionMailer::Base.deliveries.clear
760 def test_user_create_wikipedia_failure
761 OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
763 new_email = "newtester-wikipedia2@osm.org"
764 display_name = "new_tester-wikipedia2"
765 assert_difference("User.count", 0) do
766 assert_difference("ActionMailer::Base.deliveries.size", 0) do
768 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" }
769 assert_response :redirect
770 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
772 assert_response :redirect
773 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
775 assert_response :redirect
776 assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/user/new")
778 assert_response :redirect
780 assert_response :success
781 assert_template "user/new"
785 ActionMailer::Base.deliveries.clear
788 def test_user_create_wikipedia_redirect
789 OmniAuth.config.add_mock(:wikipedia, :uid => "123454321")
791 new_email = "redirect_tester_wikipedia@osm.org"
792 display_name = "redirect_tester_wikipedia"
793 # nothing special about this page, just need a protected page to redirect back to.
794 referer = "/traces/mine"
795 assert_difference("User.count") do
796 assert_difference("ActionMailer::Base.deliveries.size", 1) do
798 :user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :auth_provider => "wikipedia", :pass_crypt => "", :pass_crypt_confirmation => "" }, :referer => referer
799 assert_response :redirect
800 assert_redirected_to auth_path(:provider => "wikipedia", :origin => "/user/new")
802 assert_response :redirect
803 assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/user/new")
805 assert_response :redirect
806 assert_redirected_to "/user/terms"
807 post_via_redirect "/user/save",
808 :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" }
813 register_email = ActionMailer::Base.deliveries.first
815 assert_equal register_email.to.first, new_email
816 # Check that the confirm account url is correct
817 confirm_regex = Regexp.new("/user/redirect_tester_wikipedia/confirm\\?confirm_string=([a-zA-Z0-9]*)")
818 email_text_parts(register_email).each do |part|
819 assert_match confirm_regex, part.body.to_s
821 confirm_string = email_text_parts(register_email).first.body.match(confirm_regex)[1]
824 assert_response :success
825 assert_template "user/confirm"
827 ActionMailer::Base.deliveries.clear
829 # Go to the confirmation page
830 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
831 assert_response :success
832 assert_template "user/confirm"
834 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
835 assert_response :redirect
837 assert_response :success
838 assert_template "site/welcome"