3 class UserLoginTest < ActionDispatch::IntegrationTest
4 fixtures :users, :user_blocks
7 OmniAuth.config.test_mode = true
11 OmniAuth.config.mock_auth[:openid] = nil
12 OmniAuth.config.mock_auth[:google] = nil
13 OmniAuth.config.test_mode = false
16 def test_login_email_password_normal
17 user = users(:normal_user)
20 assert_response :redirect
21 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
23 assert_response :success
25 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
26 assert_response :redirect
28 assert_response :success
29 assert_template "login"
31 post "/login", :username => user.email, :password => "test", :referer => "/history"
32 assert_response :redirect
34 assert_response :success
35 assert_template "changeset/history"
36 assert_select "span.username", "test"
39 def test_login_email_password_normal_upcase
40 user = users(:normal_user)
43 assert_response :redirect
44 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
46 assert_response :success
48 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
49 assert_response :redirect
51 assert_response :success
52 assert_template "login"
54 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
55 assert_response :redirect
57 assert_response :success
58 assert_template "changeset/history"
59 assert_select "span.username", "TEST"
62 def test_login_email_password_normal_titlecase
63 user = users(:normal_user)
66 assert_response :redirect
67 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
69 assert_response :success
71 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
72 assert_response :redirect
74 assert_response :success
75 assert_template "login"
77 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
78 assert_response :redirect
80 assert_response :success
81 assert_template "login"
82 assert_select "span.username", false
85 def test_login_email_password_public
86 user = users(:public_user)
89 assert_response :redirect
90 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
92 assert_response :success
94 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
95 assert_response :redirect
97 assert_response :success
98 assert_template "login"
100 post "/login", :username => user.email, :password => "test", :referer => "/history"
101 assert_response :redirect
103 assert_response :success
104 assert_template "changeset/history"
105 assert_select "span.username", "test2"
108 def test_login_email_password_public_upcase
109 user = users(:public_user)
112 assert_response :redirect
113 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
115 assert_response :success
117 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
118 assert_response :redirect
120 assert_response :success
121 assert_template "login"
123 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
124 assert_response :redirect
126 assert_response :success
127 assert_template "changeset/history"
128 assert_select "span.username", "test2"
131 def test_login_email_password_public_titlecase
132 user = users(:public_user)
135 assert_response :redirect
136 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
138 assert_response :success
140 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
141 assert_response :redirect
143 assert_response :success
144 assert_template "login"
146 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
147 assert_response :redirect
149 assert_response :success
150 assert_template "changeset/history"
151 assert_select "span.username", "test2"
154 def test_login_email_password_inactive
155 user = users(:inactive_user)
158 assert_response :redirect
159 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
161 assert_response :success
163 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
164 assert_response :redirect
166 assert_response :success
167 assert_template "login"
169 post "/login", :username => user.email, :password => "test2", :referer => "/history"
170 assert_response :redirect
172 assert_response :success
173 assert_template "confirm"
176 def test_login_email_password_inactive_upcase
177 user = users(:inactive_user)
180 assert_response :redirect
181 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
183 assert_response :success
185 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
186 assert_response :redirect
188 assert_response :success
189 assert_template "login"
191 post "/login", :username => user.email.upcase, :password => "test2", :referer => "/history"
192 assert_response :redirect
194 assert_response :success
195 assert_template "confirm"
198 def test_login_email_password_inactive_titlecase
199 user = users(:inactive_user)
202 assert_response :redirect
203 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
205 assert_response :success
207 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
208 assert_response :redirect
210 assert_response :success
211 assert_template "login"
213 post "/login", :username => user.email.titlecase, :password => "test2", :referer => "/history"
214 assert_response :redirect
216 assert_response :success
217 assert_template "confirm"
220 def test_login_email_password_suspended
221 user = users(:suspended_user)
224 assert_response :redirect
225 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
227 assert_response :success
229 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
230 assert_response :redirect
232 assert_response :success
233 assert_template "login"
235 post "/login", :username => user.email, :password => "test", :referer => "/history"
236 assert_response :redirect
238 assert_response :success
239 assert_template "login"
240 assert_select "div.flash.error", /your account has been suspended/
243 def test_login_email_password_suspended_upcase
244 user = users(:suspended_user)
247 assert_response :redirect
248 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
250 assert_response :success
252 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
253 assert_response :redirect
255 assert_response :success
256 assert_template "login"
258 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
259 assert_response :redirect
261 assert_response :success
262 assert_template "login"
263 assert_select "div.flash.error", /your account has been suspended/
266 def test_login_email_password_suspended_titlecase
267 user = users(:suspended_user)
270 assert_response :redirect
271 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
273 assert_response :success
275 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
276 assert_response :redirect
278 assert_response :success
279 assert_template "login"
281 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
282 assert_response :redirect
284 assert_response :success
285 assert_template "login"
286 assert_select "div.flash.error", /your account has been suspended/
289 def test_login_email_password_blocked
290 user = users(:blocked_user)
293 assert_response :redirect
294 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
296 assert_response :success
298 post "/login", :username => user.email, :password => "wrong", :referer => "/history"
299 assert_response :redirect
301 assert_response :success
302 assert_template "login"
304 post "/login", :username => user.email, :password => "test", :referer => "/history"
305 assert_response :redirect
307 assert_response :success
308 assert_template "user_blocks/show"
311 def test_login_email_password_blocked_upcase
312 user = users(:blocked_user)
315 assert_response :redirect
316 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
318 assert_response :success
320 post "/login", :username => user.email.upcase, :password => "wrong", :referer => "/history"
321 assert_response :redirect
323 assert_response :success
324 assert_template "login"
326 post "/login", :username => user.email.upcase, :password => "test", :referer => "/history"
327 assert_response :redirect
329 assert_response :success
330 assert_template "user_blocks/show"
333 def test_login_email_password_blocked_titlecase
334 user = users(:blocked_user)
337 assert_response :redirect
338 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
340 assert_response :success
342 post "/login", :username => user.email.titlecase, :password => "wrong", :referer => "/history"
343 assert_response :redirect
345 assert_response :success
346 assert_template "login"
348 post "/login", :username => user.email.titlecase, :password => "test", :referer => "/history"
349 assert_response :redirect
351 assert_response :success
352 assert_template "user_blocks/show"
355 def test_login_username_password_normal
356 user = users(:normal_user)
359 assert_response :redirect
360 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
362 assert_response :success
364 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
365 assert_response :redirect
367 assert_response :success
368 assert_template "login"
370 post "/login", :username => user.display_name, :password => "test", :referer => "/history"
371 assert_response :redirect
373 assert_response :success
374 assert_template "changeset/history"
375 assert_select "span.username", "test"
378 def test_login_username_password_normal_upcase
379 user = users(:normal_user)
382 assert_response :redirect
383 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
385 assert_response :success
387 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
388 assert_response :redirect
390 assert_response :success
391 assert_template "login"
393 post "/login", :username => user.display_name.upcase, :password => "test", :referer => "/history"
394 assert_response :redirect
396 assert_response :success
397 assert_template "changeset/history"
398 assert_select "span.username", "TEST"
401 def test_login_username_password_normal_titlecase
402 user = users(:normal_user)
405 assert_response :redirect
406 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
408 assert_response :success
410 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
411 assert_response :redirect
413 assert_response :success
414 assert_template "login"
416 post "/login", :username => user.display_name.titlecase, :password => "test", :referer => "/history"
417 assert_response :redirect
419 assert_response :success
420 assert_template "login"
421 assert_select "span.username", false
424 def test_login_username_password_public
425 user = users(:public_user)
428 assert_response :redirect
429 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
431 assert_response :success
433 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
434 assert_response :redirect
436 assert_response :success
437 assert_template "login"
439 post "/login", :username => user.display_name, :password => "test", :referer => "/history"
440 assert_response :redirect
442 assert_response :success
443 assert_template "changeset/history"
444 assert_select "span.username", "test2"
447 def test_login_username_password_public_upcase
448 user = users(:public_user)
451 assert_response :redirect
452 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
454 assert_response :success
456 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
457 assert_response :redirect
459 assert_response :success
460 assert_template "login"
462 post "/login", :username => user.display_name.upcase, :password => "test", :referer => "/history"
463 assert_response :redirect
465 assert_response :success
466 assert_template "changeset/history"
467 assert_select "span.username", "test2"
470 def test_login_username_password_public_titlecase
471 user = users(:public_user)
474 assert_response :redirect
475 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
477 assert_response :success
479 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
480 assert_response :redirect
482 assert_response :success
483 assert_template "login"
485 post "/login", :username => user.display_name.titlecase, :password => "test", :referer => "/history"
486 assert_response :redirect
488 assert_response :success
489 assert_template "changeset/history"
490 assert_select "span.username", "test2"
493 def test_login_username_password_inactive
494 user = users(:inactive_user)
497 assert_response :redirect
498 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
500 assert_response :success
502 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
503 assert_response :redirect
505 assert_response :success
506 assert_template "login"
508 post "/login", :username => user.display_name, :password => "test2", :referer => "/history"
509 assert_response :redirect
511 assert_response :success
512 assert_template "confirm"
515 def test_login_username_password_inactive_upcase
516 user = users(:inactive_user)
519 assert_response :redirect
520 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
522 assert_response :success
524 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
525 assert_response :redirect
527 assert_response :success
528 assert_template "login"
530 post "/login", :username => user.display_name.upcase, :password => "test2", :referer => "/history"
531 assert_response :redirect
533 assert_response :success
534 assert_template "confirm"
537 def test_login_username_password_inactive_titlecase
538 user = users(:inactive_user)
541 assert_response :redirect
542 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
544 assert_response :success
546 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
547 assert_response :redirect
549 assert_response :success
550 assert_template "login"
552 post "/login", :username => user.display_name.titlecase, :password => "test2", :referer => "/history"
553 assert_response :redirect
555 assert_response :success
556 assert_template "confirm"
559 def test_login_username_password_suspended
560 user = users(:suspended_user)
563 assert_response :redirect
564 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
566 assert_response :success
568 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
569 assert_response :redirect
571 assert_response :success
572 assert_template "login"
574 post "/login", :username => user.display_name, :password => "test", :referer => "/history"
575 assert_response :redirect
577 assert_response :success
578 assert_template "login"
579 assert_select "div.flash.error", /your account has been suspended/
582 def test_login_username_password_suspended_upcase
583 user = users(:suspended_user)
586 assert_response :redirect
587 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
589 assert_response :success
591 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
592 assert_response :redirect
594 assert_response :success
595 assert_template "login"
597 post "/login", :username => user.display_name.upcase, :password => "test", :referer => "/history"
598 assert_response :redirect
600 assert_response :success
601 assert_template "login"
602 assert_select "div.flash.error", /your account has been suspended/
605 def test_login_username_password_suspended_titlecase
606 user = users(:suspended_user)
609 assert_response :redirect
610 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
612 assert_response :success
614 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
615 assert_response :redirect
617 assert_response :success
618 assert_template "login"
620 post "/login", :username => user.display_name.titlecase, :password => "test", :referer => "/history"
621 assert_response :redirect
623 assert_response :success
624 assert_template "login"
625 assert_select "div.flash.error", /your account has been suspended/
628 def test_login_username_password_blocked
629 user = users(:blocked_user)
632 assert_response :redirect
633 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
635 assert_response :success
637 post "/login", :username => user.display_name, :password => "wrong", :referer => "/history"
638 assert_response :redirect
640 assert_response :success
641 assert_template "login"
643 post "/login", :username => user.display_name, :password => "test", :referer => "/history"
644 assert_response :redirect
646 assert_response :success
647 assert_template "user_blocks/show"
650 def test_login_username_password_blocked_upcase
651 user = users(:blocked_user)
654 assert_response :redirect
655 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
657 assert_response :success
659 post "/login", :username => user.display_name.upcase, :password => "wrong", :referer => "/history"
660 assert_response :redirect
662 assert_response :success
663 assert_template "login"
665 post "/login", :username => user.display_name.upcase, :password => "test", :referer => "/history"
666 assert_response :redirect
668 assert_response :success
669 assert_template "user_blocks/show"
672 def test_login_username_password_blocked_titlecase
673 user = users(:blocked_user)
676 assert_response :redirect
677 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
679 assert_response :success
681 post "/login", :username => user.display_name.titlecase, :password => "wrong", :referer => "/history"
682 assert_response :redirect
684 assert_response :success
685 assert_template "login"
687 post "/login", :username => user.display_name.titlecase, :password => "test", :referer => "/history"
688 assert_response :redirect
690 assert_response :success
691 assert_template "user_blocks/show"
694 def test_login_email_password_remember_me
695 user = users(:normal_user)
698 assert_response :redirect
699 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
701 assert_response :success
703 post "/login", :username => user.email, :password => "test", :remember_me => true, :referer => "/history"
704 assert_response :redirect
706 assert_response :success
707 assert_template "changeset/history"
708 assert_select "span.username", "test"
709 assert session.key?(:_remember_for)
712 def test_login_username_password_remember_me
713 user = users(:normal_user)
716 assert_response :redirect
717 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true
719 assert_response :success
721 post "/login", :username => user.display_name, :password => "test", :remember_me => true, :referer => "/history"
722 assert_response :redirect
724 assert_response :success
725 assert_template "changeset/history"
726 assert_select "span.username", "test"
727 assert session.key?(:_remember_for)
730 def test_login_openid_success
731 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
733 get "/login", :referer => "/history"
734 assert_response :redirect
735 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
737 assert_response :success
738 assert_template "user/login"
739 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
740 assert_response :redirect
741 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
743 assert_response :redirect
744 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
746 assert_response :redirect
748 assert_response :success
749 assert_template "changeset/history"
750 assert_select "span.username", "openIDuser"
753 def test_login_openid_remember_me
754 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/john.doe")
756 get "/login", :referer => "/history"
757 assert_response :redirect
758 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
760 assert_response :success
761 assert_template "user/login"
762 post "/login", :openid_url => "http://localhost:1123/john.doe", :remember_me_openid => true, :referer => "/history"
763 assert_response :redirect
764 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
766 assert_response :redirect
767 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
769 assert_response :redirect
771 assert_response :success
772 assert_template "changeset/history"
773 assert_select "span.username", "openIDuser"
774 assert session.key?(:_remember_for)
777 def test_login_openid_connection_failed
778 OmniAuth.config.mock_auth[:openid] = :connection_failed
780 get "/login", :referer => "/history"
781 assert_response :redirect
782 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
784 assert_response :success
785 assert_template "user/login"
786 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
787 assert_response :redirect
788 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
790 assert_response :redirect
791 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
793 assert_response :redirect
794 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "connection_failed", :origin => "/login")
796 assert_response :redirect
798 assert_response :success
799 assert_template "login"
800 assert_select "div.flash.error", "Connection to authentication provider failed"
801 assert_select "span.username", false
804 def test_login_openid_invalid_credentials
805 OmniAuth.config.mock_auth[:openid] = :invalid_credentials
807 get "/login", :referer => "/history"
808 assert_response :redirect
809 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
811 assert_response :success
812 assert_template "user/login"
813 post "/login", :openid_url => "http://localhost:1123/john.doe", :referer => "/history"
814 assert_response :redirect
815 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
817 assert_response :redirect
818 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/john.doe", :origin => "/login")
820 assert_response :redirect
821 assert_redirected_to auth_failure_path(:strategy => "openid", :message => "invalid_credentials", :origin => "/login")
823 assert_response :redirect
825 assert_response :success
826 assert_template "login"
827 assert_select "div.flash.error", "Invalid authentication credentials"
828 assert_select "span.username", false
831 def test_login_openid_unknown
832 OmniAuth.config.add_mock(:openid, :uid => "http://localhost:1123/fred.bloggs")
834 get "/login", :referer => "/history"
835 assert_response :redirect
836 assert_redirected_to :controller => :user, :action => :login, :cookie_test => true, :referer => "/history"
838 assert_response :success
839 assert_template "user/login"
840 post "/login", :openid_url => "http://localhost:1123/fred.bloggs", :referer => "/history"
841 assert_response :redirect
842 assert_redirected_to auth_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login")
844 assert_response :redirect
845 assert_redirected_to auth_success_path(:provider => "openid", :openid_url => "http://localhost:1123/fred.bloggs", :origin => "/login")
847 assert_response :redirect
849 assert_response :success
850 assert_template "user/new"
851 assert_select "span.username", false
854 def test_login_google_success
855 OmniAuth.config.add_mock(:google, :uid => "123456789", :extra => {
856 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
859 get "/login", :referer => "/history"
860 assert_response :redirect
861 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
863 assert_response :success
864 assert_template "user/login"
865 get auth_path(:provider => "google", :origin => "/login")
866 assert_response :redirect
867 assert_redirected_to auth_success_path(:provider => "google")
869 assert_response :redirect
871 assert_response :success
872 assert_template "changeset/history"
873 assert_select "span.username", "googleuser"
876 def test_login_google_connection_failed
877 OmniAuth.config.mock_auth[:google] = :connection_failed
879 get "/login", :referer => "/history"
880 assert_response :redirect
881 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
883 assert_response :success
884 assert_template "user/login"
885 get auth_path(:provider => "google", :origin => "/login")
886 assert_response :redirect
887 assert_redirected_to auth_success_path(:provider => "google")
889 assert_response :redirect
890 assert_redirected_to auth_failure_path(:strategy => "google", :message => "connection_failed", :origin => "/login")
892 assert_response :redirect
894 assert_response :success
895 assert_template "login"
896 assert_select "div.flash.error", "Connection to authentication provider failed"
897 assert_select "span.username", false
900 def test_login_google_invalid_credentials
901 OmniAuth.config.mock_auth[:google] = :invalid_credentials
903 get "/login", :referer => "/history"
904 assert_response :redirect
905 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
907 assert_response :success
908 assert_template "user/login"
909 get auth_path(:provider => "google", :origin => "/login")
910 assert_response :redirect
911 assert_redirected_to auth_success_path(:provider => "google")
913 assert_response :redirect
914 assert_redirected_to auth_failure_path(:strategy => "google", :message => "invalid_credentials", :origin => "/login")
916 assert_response :redirect
918 assert_response :success
919 assert_template "login"
920 assert_select "div.flash.error", "Invalid authentication credentials"
921 assert_select "span.username", false
924 def test_login_google_unknown
925 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
926 :id_info => { "openid_id" => "http://localhost:1123/fred.bloggs" }
929 get "/login", :referer => "/history"
930 assert_response :redirect
931 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
933 assert_response :success
934 assert_template "user/login"
935 get auth_path(:provider => "google", :origin => "/login")
936 assert_response :redirect
937 assert_redirected_to auth_success_path(:provider => "google")
939 assert_response :redirect
941 assert_response :success
942 assert_template "user/new"
943 assert_select "span.username", false
946 def test_login_google_upgrade
947 OmniAuth.config.add_mock(:google, :uid => "987654321", :extra => {
948 :id_info => { "openid_id" => "http://localhost:1123/john.doe" }
951 get "/login", :referer => "/history"
952 assert_response :redirect
953 assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
955 assert_response :success
956 assert_template "user/login"
957 get auth_path(:provider => "google", :origin => "/login")
958 assert_response :redirect
959 assert_redirected_to auth_success_path(:provider => "google")
961 assert_response :redirect
963 assert_response :success
964 assert_template "changeset/history"
965 assert_select "span.username", "openIDuser"
967 user = User.find_by_display_name("openIDuser")
968 assert_equal "google", user.auth_provider
969 assert_equal "987654321", user.auth_uid