+class UserLoginTest < ActionDispatch::IntegrationTest
+ fixtures :users, :user_blocks
+
+ def setup
+ OmniAuth.config.test_mode = true
+ end
+
+ def teardown
+ OmniAuth.config.mock_auth[:openid] = nil
+ OmniAuth.config.mock_auth[:google] = nil
+ OmniAuth.config.mock_auth[:facebook] = nil
+ OmniAuth.config.mock_auth[:windowslive] = nil
+ OmniAuth.config.mock_auth[:github] = nil
+ OmniAuth.config.test_mode = false
+ end
+
+ def test_login_email_password_normal
+ user = users(:normal_user)
+
+ try_password_login user.email, "test"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "test"
+ end
+
+ def test_login_email_password_normal_upcase
+ user = users(:normal_user)
+
+ try_password_login user.email.upcase, "test"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "TEST"
+ end
+
+ def test_login_email_password_normal_titlecase
+ user = users(:normal_user)
+
+ try_password_login user.email.titlecase, "test"
+
+ assert_template "login"
+ assert_select "span.username", false
+ end
+
+ def test_login_email_password_public
+ user = users(:public_user)
+
+ try_password_login user.email, "test"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "test2"
+ end
+
+ def test_login_email_password_public_upcase
+ user = users(:public_user)
+
+ try_password_login user.email.upcase, "test"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "test2"
+ end
+
+ def test_login_email_password_public_titlecase
+ user = users(:public_user)
+
+ try_password_login user.email.titlecase, "test"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "test2"
+ end
+
+ def test_login_email_password_inactive
+ user = users(:inactive_user)
+
+ try_password_login user.email, "test2"
+
+ assert_template "confirm"
+ assert_select "span.username", false
+ end
+
+ def test_login_email_password_inactive_upcase
+ user = users(:inactive_user)
+
+ try_password_login user.email.upcase, "test2"
+
+ assert_template "confirm"
+ assert_select "span.username", false
+ end
+
+ def test_login_email_password_inactive_titlecase
+ user = users(:inactive_user)
+
+ try_password_login user.email.titlecase, "test2"
+
+ assert_template "confirm"
+ assert_select "span.username", false
+ end
+
+ def test_login_email_password_suspended
+ user = users(:suspended_user)
+
+ try_password_login user.email, "test"
+
+ assert_template "login"
+ assert_select "span.username", false
+ assert_select "div.flash.error", /your account has been suspended/
+ end
+
+ def test_login_email_password_suspended_upcase
+ user = users(:suspended_user)
+
+ try_password_login user.email.upcase, "test"
+
+ assert_template "login"
+ assert_select "span.username", false
+ assert_select "div.flash.error", /your account has been suspended/
+ end
+
+ def test_login_email_password_suspended_titlecase
+ user = users(:suspended_user)
+
+ try_password_login user.email.titlecase, "test"
+
+ assert_template "login"
+ assert_select "span.username", false
+ assert_select "div.flash.error", /your account has been suspended/
+ end
+
+ def test_login_email_password_blocked
+ user = users(:blocked_user)
+
+ try_password_login user.email, "test"
+
+ assert_template "user_blocks/show"
+ assert_select "span.username", "blocked"
+ end
+
+ def test_login_email_password_blocked_upcase
+ user = users(:blocked_user)
+
+ try_password_login user.email.upcase, "test"
+
+ assert_template "user_blocks/show"
+ assert_select "span.username", "blocked"
+ end
+
+ def test_login_email_password_blocked_titlecase
+ user = users(:blocked_user)
+
+ try_password_login user.email.titlecase, "test"
+
+ assert_template "user_blocks/show"
+ assert_select "span.username", "blocked"
+ end
+
+ def test_login_username_password_normal
+ user = users(:normal_user)
+
+ try_password_login user.display_name, "test"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "test"
+ end
+
+ def test_login_username_password_normal_upcase
+ user = users(:normal_user)
+
+ try_password_login user.display_name.upcase, "test"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "TEST"
+ end
+
+ def test_login_username_password_normal_titlecase
+ user = users(:normal_user)
+
+ try_password_login user.display_name.titlecase, "test"
+
+ assert_template "login"
+ assert_select "span.username", false
+ end
+
+ def test_login_username_password_public
+ user = users(:public_user)
+
+ try_password_login user.display_name, "test"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "test2"
+ end
+
+ def test_login_username_password_public_upcase
+ user = users(:public_user)
+
+ try_password_login user.display_name.upcase, "test"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "test2"
+ end
+
+ def test_login_username_password_public_titlecase
+ user = users(:public_user)
+
+ try_password_login user.display_name.titlecase, "test"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "test2"
+ end
+
+ def test_login_username_password_inactive
+ user = users(:inactive_user)
+
+ try_password_login user.display_name, "test2"
+
+ assert_template "confirm"
+ assert_select "span.username", false
+ end
+
+ def test_login_username_password_inactive_upcase
+ user = users(:inactive_user)
+
+ try_password_login user.display_name.upcase, "test2"
+
+ assert_template "confirm"
+ assert_select "span.username", false
+ end
+
+ def test_login_username_password_inactive_titlecase
+ user = users(:inactive_user)
+
+ try_password_login user.display_name.titlecase, "test2"
+
+ assert_template "confirm"
+ assert_select "span.username", false
+ end
+
+ def test_login_username_password_suspended
+ user = users(:suspended_user)
+
+ try_password_login user.display_name, "test"
+
+ assert_template "login"
+ assert_select "span.username", false
+ assert_select "div.flash.error", /your account has been suspended/
+ end
+
+ def test_login_username_password_suspended_upcase
+ user = users(:suspended_user)
+
+ try_password_login user.display_name.upcase, "test"
+
+ assert_template "login"
+ assert_select "span.username", false
+ assert_select "div.flash.error", /your account has been suspended/
+ end
+
+ def test_login_username_password_suspended_titlecase
+ user = users(:suspended_user)
+
+ try_password_login user.display_name.titlecase, "test"
+
+ assert_template "login"
+ assert_select "span.username", false
+ assert_select "div.flash.error", /your account has been suspended/
+ end
+
+ def test_login_username_password_blocked
+ user = users(:blocked_user)
+
+ try_password_login user.display_name.upcase, "test"
+
+ assert_template "user_blocks/show"
+ assert_select "span.username", "blocked"
+ end
+
+ def test_login_username_password_blocked_upcase
+ user = users(:blocked_user)
+
+ try_password_login user.display_name, "test"
+
+ assert_template "user_blocks/show"
+ assert_select "span.username", "blocked"
+ end
+
+ def test_login_username_password_blocked_titlecase
+ user = users(:blocked_user)
+
+ try_password_login user.display_name.titlecase, "test"
+
+ assert_template "user_blocks/show"
+ assert_select "span.username", "blocked"
+ end
+
+ def test_login_email_password_remember_me
+ user = users(:normal_user)
+
+ try_password_login user.email, "test", "yes"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "test"
+ assert session.key?(:_remember_for)
+ end
+
+ def test_login_username_password_remember_me
+ user = users(:normal_user)
+
+ try_password_login user.display_name, "test", "yes"
+
+ assert_template "changeset/history"
+ assert_select "span.username", "test"
+ assert session.key?(:_remember_for)
+ end