From 536279b05b9d78acc80bd579ffe6786a7cff818c Mon Sep 17 00:00:00 2001 From: Lucas Mazza Date: Tue, 3 May 2016 13:57:10 -0300 Subject: [PATCH] Replace homemade `assert_not` matcher in favor of `refute`. --- test/controllers/helpers_test.rb | 4 +- test/controllers/internal_helpers_test.rb | 2 +- test/devise_test.rb | 12 ++-- test/integration/authenticatable_test.rb | 72 +++++++++---------- test/integration/confirmable_test.rb | 14 ++-- .../database_authenticatable_test.rb | 10 +-- test/integration/lockable_test.rb | 2 +- test/integration/omniauthable_test.rb | 2 +- test/integration/recoverable_test.rb | 8 +-- test/integration/registerable_test.rb | 12 ++-- test/integration/rememberable_test.rb | 20 +++--- test/integration/timeoutable_test.rb | 10 +-- test/mapping_test.rb | 2 +- test/models/confirmable_test.rb | 40 +++++------ test/models/database_authenticatable_test.rb | 18 ++--- test/models/lockable_test.rb | 26 +++---- test/models/recoverable_test.rb | 18 ++--- test/models/timeoutable_test.rb | 12 ++-- test/models/validatable_test.rb | 2 +- test/models_test.rb | 2 +- test/support/assertions.rb | 4 -- 21 files changed, 144 insertions(+), 148 deletions(-) diff --git a/test/controllers/helpers_test.rb b/test/controllers/helpers_test.rb index 6df78d9ce2..4783356153 100644 --- a/test/controllers/helpers_test.rb +++ b/test/controllers/helpers_test.rb @@ -96,7 +96,7 @@ def setup test 'proxy admin_signed_in? to authenticatewith admin scope' do @mock_warden.expects(:authenticate).with(scope: :admin) - assert_not @controller.admin_signed_in? + refute @controller.admin_signed_in? end test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do @@ -311,6 +311,6 @@ def setup end test 'is not a devise controller' do - assert_not @controller.devise_controller? + refute @controller.devise_controller? end end diff --git a/test/controllers/internal_helpers_test.rb b/test/controllers/internal_helpers_test.rb index c9eada0024..d2a96119c9 100644 --- a/test/controllers/internal_helpers_test.rb +++ b/test/controllers/internal_helpers_test.rb @@ -119,7 +119,7 @@ def setup MyController.send(:public, :navigational_formats) swap Devise, navigational_formats: ['*/*', :html] do - assert_not @controller.navigational_formats.include?("*/*") + refute @controller.navigational_formats.include?("*/*") end MyController.send(:protected, :navigational_formats) diff --git a/test/devise_test.rb b/test/devise_test.rb index d59deb78cf..1281a5186e 100755 --- a/test/devise_test.rb +++ b/test/devise_test.rb @@ -69,8 +69,8 @@ class DeviseTest < ActiveSupport::TestCase test 'add new module using the helper method' do assert_nothing_raised(Exception) { Devise.add_module(:coconut) } assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size - assert_not Devise::STRATEGIES.include?(:coconut) - assert_not defined?(Devise::Models::Coconut) + refute Devise::STRATEGIES.include?(:coconut) + refute defined?(Devise::Models::Coconut) Devise::ALL.delete(:coconut) assert_nothing_raised(Exception) { Devise.add_module(:banana, strategy: :fruits) } @@ -86,11 +86,11 @@ class DeviseTest < ActiveSupport::TestCase test 'should complain when comparing empty or different sized passes' do [nil, ""].each do |empty| - assert_not Devise.secure_compare(empty, "something") - assert_not Devise.secure_compare("something", empty) - assert_not Devise.secure_compare(empty, empty) + refute Devise.secure_compare(empty, "something") + refute Devise.secure_compare("something", empty) + refute Devise.secure_compare(empty, empty) end - assert_not Devise.secure_compare("size_1", "size_four") + refute Devise.secure_compare("size_1", "size_four") end test 'Devise.email_regexp should match valid email addresses' do diff --git a/test/integration/authenticatable_test.rb b/test/integration/authenticatable_test.rb index e85ae666f2..7ad08486f0 100644 --- a/test/integration/authenticatable_test.rb +++ b/test/integration/authenticatable_test.rb @@ -10,13 +10,13 @@ class AuthenticationSanityTest < Devise::IntegrationTest test 'sign in as user should not authenticate admin scope' do sign_in_as_user assert warden.authenticated?(:user) - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) end test 'sign in as admin should not authenticate user scope' do sign_in_as_admin assert warden.authenticated?(:admin) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end test 'sign in as both user and admin at same time' do @@ -31,7 +31,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest sign_in_as_user sign_in_as_admin delete destroy_user_session_path - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) assert warden.authenticated?(:admin) end end @@ -42,7 +42,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest sign_in_as_admin delete destroy_admin_session_path - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) assert warden.authenticated?(:user) end end @@ -53,8 +53,8 @@ class AuthenticationSanityTest < Devise::IntegrationTest sign_in_as_admin delete destroy_user_session_path - assert_not warden.authenticated?(:user) - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:user) + refute warden.authenticated?(:admin) end end @@ -64,21 +64,21 @@ class AuthenticationSanityTest < Devise::IntegrationTest sign_in_as_admin delete destroy_admin_session_path - assert_not warden.authenticated?(:admin) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:admin) + refute warden.authenticated?(:user) end end test 'not signed in as admin should not be able to access admins actions' do get admins_path assert_redirected_to new_admin_session_path - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) end test 'signed in as user should not be able to access admins actions' do sign_in_as_user assert warden.authenticated?(:user) - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) get admins_path assert_redirected_to new_admin_session_path @@ -87,7 +87,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest test 'signed in as admin should be able to access admin actions' do sign_in_as_admin assert warden.authenticated?(:admin) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) get admins_path @@ -115,7 +115,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest get root_path assert_contain 'Signed out successfully' - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) end test 'unauthenticated admin set message on sign out' do @@ -138,13 +138,13 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest test 'not signed in should not be able to access private route (authenticate denied)' do get private_path assert_redirected_to new_admin_session_path - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) end test 'signed in as user should not be able to access private route restricted to admins (authenticate denied)' do sign_in_as_user assert warden.authenticated?(:user) - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) get private_path assert_redirected_to new_admin_session_path end @@ -152,7 +152,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest test 'signed in as admin should be able to access private route restricted to admins (authenticate accepted)' do sign_in_as_admin assert warden.authenticated?(:admin) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) get private_path @@ -164,7 +164,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do sign_in_as_admin(active: false) assert warden.authenticated?(:admin) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) assert_raises ActionController::RoutingError do get "/private/active" @@ -174,7 +174,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do sign_in_as_admin(active: true) assert warden.authenticated?(:admin) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) get private_active_path @@ -186,7 +186,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest test 'signed in as admin should get admin dashboard (authenticated accepted)' do sign_in_as_admin assert warden.authenticated?(:admin) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) get dashboard_path @@ -198,7 +198,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest test 'signed in as user should get user dashboard (authenticated accepted)' do sign_in_as_user assert warden.authenticated?(:user) - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) get dashboard_path @@ -216,7 +216,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do sign_in_as_admin(active: false) assert warden.authenticated?(:admin) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) assert_raises ActionController::RoutingError do get "/dashboard/active" @@ -226,7 +226,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do sign_in_as_admin(active: true) assert warden.authenticated?(:admin) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) get dashboard_active_path @@ -238,7 +238,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest test 'signed in user should not see unauthenticated page (unauthenticated denied)' do sign_in_as_user assert warden.authenticated?(:user) - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) assert_raises ActionController::RoutingError do get join_path @@ -404,13 +404,13 @@ class AuthenticationOthersTest < Devise::IntegrationTest test 'handles unverified requests gets rid of caches' do swap ApplicationController, allow_forgery_protection: true do post exhibit_user_url(1) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) sign_in_as_user assert warden.authenticated?(:user) post exhibit_user_url(1) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) assert_equal "User is not authenticated", response.body end end @@ -473,7 +473,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest test 'uses the mapping from router' do sign_in_as_user visit: "/as/sign_in" assert warden.authenticated?(:user) - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) end test 'sign in with xml format returns xml response' do @@ -515,14 +515,14 @@ class AuthenticationOthersTest < Devise::IntegrationTest sign_in_as_user delete destroy_user_session_path(format: 'xml') assert_response :no_content - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end test 'sign out with json format returns no content' do sign_in_as_user delete destroy_user_session_path(format: 'json') assert_response :no_content - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end test 'sign out with non-navigational format via XHR does not redirect' do @@ -530,7 +530,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest sign_in_as_admin get destroy_sign_out_via_get_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*. assert_response :no_content - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end @@ -540,7 +540,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest sign_in_as_user delete destroy_user_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "text/html,*/*" } assert_response :redirect - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end end @@ -550,7 +550,7 @@ class AuthenticationKeysTest < Devise::IntegrationTest swap Devise, authentication_keys: [:subdomain] do sign_in_as_user assert_contain "Invalid Subdomain or password." - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end @@ -579,7 +579,7 @@ class AuthenticationRequestKeysTest < Devise::IntegrationTest sign_in_as_user end - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end @@ -589,7 +589,7 @@ class AuthenticationRequestKeysTest < Devise::IntegrationTest swap Devise, request_keys: [:subdomain] do sign_in_as_user assert_contain "Invalid Email or password." - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end @@ -612,7 +612,7 @@ def sign_in!(scope) test 'allow sign out via delete when sign_out_via provides only delete' do sign_in!(:sign_out_via_delete) delete destroy_sign_out_via_delete_session_path - assert_not warden.authenticated?(:sign_out_via_delete) + refute warden.authenticated?(:sign_out_via_delete) end test 'do not allow sign out via get when sign_out_via provides only delete' do @@ -626,7 +626,7 @@ def sign_in!(scope) test 'allow sign out via post when sign_out_via provides only post' do sign_in!(:sign_out_via_post) post destroy_sign_out_via_post_session_path - assert_not warden.authenticated?(:sign_out_via_post) + refute warden.authenticated?(:sign_out_via_post) end test 'do not allow sign out via get when sign_out_via provides only post' do @@ -640,13 +640,13 @@ def sign_in!(scope) test 'allow sign out via delete when sign_out_via provides delete and post' do sign_in!(:sign_out_via_delete_or_post) delete destroy_sign_out_via_delete_or_post_session_path - assert_not warden.authenticated?(:sign_out_via_delete_or_post) + refute warden.authenticated?(:sign_out_via_delete_or_post) end test 'allow sign out via post when sign_out_via provides delete and post' do sign_in!(:sign_out_via_delete_or_post) post destroy_sign_out_via_delete_or_post_session_path - assert_not warden.authenticated?(:sign_out_via_delete_or_post) + refute warden.authenticated?(:sign_out_via_delete_or_post) end test 'do not allow sign out via get when sign_out_via provides delete and post' do diff --git a/test/integration/confirmable_test.rb b/test/integration/confirmable_test.rb index 484d4bdfde..02730d5891 100644 --- a/test/integration/confirmable_test.rb +++ b/test/integration/confirmable_test.rb @@ -41,12 +41,12 @@ def resend_confirmation test 'user with valid confirmation token should not be able to confirm an account after the token has expired' do swap Devise, confirm_within: 3.days do user = create_user(confirm: false, confirmation_sent_at: 4.days.ago) - assert_not user.confirmed? + refute user.confirmed? visit_user_confirmation_with_token(user.raw_confirmation_token) assert_have_selector '#error_explanation' assert_contain %r{needs to be confirmed within 3 days} - assert_not user.reload.confirmed? + refute user.reload.confirmed? assert_current_url "/users/confirmation?confirmation_token=#{user.raw_confirmation_token}" end end @@ -84,7 +84,7 @@ def resend_confirmation test 'user with valid confirmation token should be able to confirm an account before the token has expired' do swap Devise, confirm_within: 3.days do user = create_user(confirm: false, confirmation_sent_at: 2.days.ago) - assert_not user.confirmed? + refute user.confirmed? visit_user_confirmation_with_token(user.raw_confirmation_token) assert_contain 'Your email address has been successfully confirmed.' @@ -130,7 +130,7 @@ def resend_confirmation sign_in_as_user(confirm: false) assert_contain 'You have to confirm your email address before continuing' - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end @@ -141,7 +141,7 @@ def resend_confirmation end assert_contain 'Invalid Email or password' - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end @@ -284,7 +284,7 @@ def visit_admin_confirmation_with_token(confirmation_token) assert_contain 'Your email address has been successfully confirmed.' assert_current_url '/admin_area/sign_in' assert admin.reload.confirmed? - assert_not admin.reload.pending_reconfirmation? + refute admin.reload.pending_reconfirmation? end test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do @@ -306,7 +306,7 @@ def visit_admin_confirmation_with_token(confirmation_token) assert_contain 'Your email address has been successfully confirmed.' assert_current_url '/admin_area/sign_in' assert admin.reload.confirmed? - assert_not admin.reload.pending_reconfirmation? + refute admin.reload.pending_reconfirmation? end test 'admin email should be unique also within unconfirmed_email' do diff --git a/test/integration/database_authenticatable_test.rb b/test/integration/database_authenticatable_test.rb index 659f20b675..135f113b04 100644 --- a/test/integration/database_authenticatable_test.rb +++ b/test/integration/database_authenticatable_test.rb @@ -19,7 +19,7 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest fill_in 'email', with: 'foo@bar.com' end - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end @@ -41,14 +41,14 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest fill_in 'email', with: ' foo@bar.com ' end - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end test 'sign in should not authenticate if not using proper authentication keys' do swap Devise, authentication_keys: [:username] do sign_in_as_user - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end @@ -59,7 +59,7 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest end assert_contain 'Invalid email address' - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) end end @@ -69,7 +69,7 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest end assert_contain 'Invalid Email or password' - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) end test 'error message is configurable by resource name' do diff --git a/test/integration/lockable_test.rb b/test/integration/lockable_test.rb index 0537742188..5602bb9fd2 100644 --- a/test/integration/lockable_test.rb +++ b/test/integration/lockable_test.rb @@ -85,7 +85,7 @@ def send_unlock_request assert_current_url "/users/sign_in" assert_contain 'Your account has been unlocked successfully. Please sign in to continue.' - assert_not user.reload.access_locked? + refute user.reload.access_locked? end test "user should not send a new e-mail if already locked" do diff --git a/test/integration/omniauthable_test.rb b/test/integration/omniauthable_test.rb index 76c2cdcfea..6af8842007 100644 --- a/test/integration/omniauthable_test.rb +++ b/test/integration/omniauthable_test.rb @@ -71,7 +71,7 @@ def stub_action!(name) assert_current_url "/" assert_contain "You have signed up successfully." assert_contain "Hello User user@example.com" - assert_not session["devise.facebook_data"] + refute session["devise.facebook_data"] end test "cleans up session on cancel" do diff --git a/test/integration/recoverable_test.rb b/test/integration/recoverable_test.rb index d738ccfa89..f35a46b7b3 100644 --- a/test/integration/recoverable_test.rb +++ b/test/integration/recoverable_test.rb @@ -10,7 +10,7 @@ def visit_new_password_path def request_forgot_password(&block) visit_new_password_path assert_response :success - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) fill_in 'email', with: 'user@test.com' yield if block_given? @@ -147,7 +147,7 @@ def reset_password(options={}, &block) assert_current_url '/users/password' assert_have_selector '#error_explanation' assert_contain %r{Reset password token(.*)invalid} - assert_not user.reload.valid_password?('987654321') + refute user.reload.valid_password?('987654321') end test 'not authenticated user with valid reset password token but invalid password should not be able to change their password' do @@ -161,7 +161,7 @@ def reset_password(options={}, &block) assert_current_url '/users/password' assert_have_selector '#error_explanation' assert_contain "Password confirmation doesn't match Password" - assert_not user.reload.valid_password?('987654321') + refute user.reload.valid_password?('987654321') end test 'not authenticated user with valid data should be able to change their password' do @@ -181,7 +181,7 @@ def reset_password(options={}, &block) reset_password { fill_in 'Confirm new password', with: 'other_password' } assert_response :success assert_have_selector '#error_explanation' - assert_not user.reload.valid_password?('987654321') + refute user.reload.valid_password?('987654321') reset_password visit: false assert_contain 'Your password has been changed successfully.' diff --git a/test/integration/registerable_test.rb b/test/integration/registerable_test.rb index 617958d029..9417a17723 100644 --- a/test/integration/registerable_test.rb +++ b/test/integration/registerable_test.rb @@ -64,11 +64,11 @@ def user_sign_up assert_not_contain 'You have to confirm your account before continuing' assert_current_url "/" - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) user = User.to_adapter.find_first(order: [:id, :desc]) assert_equal user.email, 'new_user@test.com' - assert_not user.confirmed? + refute user.confirmed? end test 'a guest user should receive the confirmation instructions from the default mailer' do @@ -92,7 +92,7 @@ def user_sign_up click_button 'Sign up' assert_current_url "/?custom=1" - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end test 'a guest user cannot sign up with invalid information' do @@ -114,7 +114,7 @@ def user_sign_up assert_contain "2 errors prohibited" assert_nil User.to_adapter.find_first - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end test 'a guest should not sign up with email/password that already exists' do @@ -133,7 +133,7 @@ def user_sign_up assert_current_url '/users' assert_contain(/Email.*already.*taken/) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end test 'a guest should not be able to change account' do @@ -217,7 +217,7 @@ def user_sign_up click_button 'Update' assert_contain "Password confirmation doesn't match Password" - assert_not User.to_adapter.find_first.valid_password?('pas123') + refute User.to_adapter.find_first.valid_password?('pas123') end test 'a signed in user should be able to cancel their account' do diff --git a/test/integration/rememberable_test.rb b/test/integration/rememberable_test.rb index 31e5d219f3..b5a227db48 100644 --- a/test/integration/rememberable_test.rb +++ b/test/integration/rememberable_test.rb @@ -33,12 +33,12 @@ def cookie_expires(key) test 'handle unverified requests gets rid of caches' do swap ApplicationController, allow_forgery_protection: true do post exhibit_user_url(1) - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) create_user_and_remember post exhibit_user_url(1) assert_equal "User is not authenticated", response.body - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end @@ -51,8 +51,8 @@ def cookie_expires(key) authenticity_token: "oops", user: { email: "jose.valim@gmail.com", password: "123456", remember_me: "1" } } - assert_not warden.authenticated?(:user) - assert_not request.cookies['remember_user_token'] + refute warden.authenticated?(:user) + refute request.cookies['remember_user_token'] end end @@ -158,13 +158,13 @@ def cookie_expires(key) get root_path assert_response :success assert warden.authenticated?(:user) - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:admin) end test 'do not remember with invalid token' do create_user_and_remember('add') get users_path - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) assert_redirected_to new_user_session_path end @@ -172,7 +172,7 @@ def cookie_expires(key) create_user_and_remember swap Devise, remember_for: 0.days do get users_path - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) assert_redirected_to new_user_session_path end end @@ -183,11 +183,11 @@ def cookie_expires(key) assert warden.authenticated?(:user) delete destroy_user_session_path - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) assert_nil warden.cookies['remember_user_token'] get users_path - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end test 'changing user password expires remember me token' do @@ -197,7 +197,7 @@ def cookie_expires(key) user.save! get users_path - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end test 'valid sign in calls after_remembered callback' do diff --git a/test/integration/timeoutable_test.rb b/test/integration/timeoutable_test.rb index 1458495e4d..d831a96c6f 100644 --- a/test/integration/timeoutable_test.rb +++ b/test/integration/timeoutable_test.rb @@ -56,7 +56,7 @@ def last_request_at get users_path assert_redirected_to users_path - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) assert warden.authenticated?(:admin) end end @@ -70,8 +70,8 @@ def last_request_at assert_not_nil last_request_at get root_path - assert_not warden.authenticated?(:user) - assert_not warden.authenticated?(:admin) + refute warden.authenticated?(:user) + refute warden.authenticated?(:admin) end end @@ -108,7 +108,7 @@ def last_request_at assert_response :success assert_contain 'Sign in' - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end test 'time out is not triggered on sign in' do @@ -134,7 +134,7 @@ def last_request_at get expire_user_path(user) get users_path assert_redirected_to users_path - assert_not warden.authenticated?(:user) + refute warden.authenticated?(:user) end end diff --git a/test/mapping_test.rb b/test/mapping_test.rb index 8c69981d2c..b1010166f6 100644 --- a/test/mapping_test.rb +++ b/test/mapping_test.rb @@ -115,7 +115,7 @@ def user.devise_scope; :special_scope; end assert mapping.authenticatable? assert mapping.recoverable? assert mapping.lockable? - assert_not mapping.omniauthable? + refute mapping.omniauthable? end test 'find mapping by path' do diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index 5baf252e76..9eace6a9d9 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -28,9 +28,9 @@ def setup end test 'should verify whether a user is confirmed or not' do - assert_not new_user.confirmed? + refute new_user.confirmed? user = create_user - assert_not user.confirmed? + refute user.confirmed? user.confirm assert user.confirmed? end @@ -40,7 +40,7 @@ def setup assert user.confirm assert_blank user.errors[:email] - assert_not user.confirm + refute user.confirm assert_equal "was already confirmed, please try signing in", user.errors[:email].join end @@ -54,13 +54,13 @@ def setup test 'should return a new record with errors when a invalid token is given' do confirmed_user = User.confirm_by_token('invalid_confirmation_token') - assert_not confirmed_user.persisted? + refute confirmed_user.persisted? assert_equal "is invalid", confirmed_user.errors[:confirmation_token].join end test 'should return a new record with errors when a blank token is given' do confirmed_user = User.confirm_by_token('') - assert_not confirmed_user.persisted? + refute confirmed_user.persisted? assert_equal "can't be blank", confirmed_user.errors[:confirmation_token].join end @@ -114,7 +114,7 @@ def setup assert_email_not_sent do user.save! - assert_not user.confirmed? + refute user.confirmed? end end @@ -134,7 +134,7 @@ def setup test 'should return a new user if no email was found' do confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com") - assert_not confirmation_user.persisted? + refute confirmation_user.persisted? end test 'should add error to new user email if no email was found' do @@ -181,7 +181,7 @@ def setup test 'should not be able to send instructions if the user is already confirmed' do user = create_user user.confirm - assert_not user.resend_confirmation_instructions + refute user.resend_confirmation_instructions assert user.confirmed? assert_equal 'was already confirmed, please try signing in', user.errors[:email].join end @@ -190,7 +190,7 @@ def setup swap Devise, allow_unconfirmed_access_for: 1.day do user = create_user user.confirmation_sent_at = 2.days.ago - assert_not user.active_for_authentication? + refute user.active_for_authentication? Devise.allow_unconfirmed_access_for = 3.days assert user.active_for_authentication? @@ -206,14 +206,14 @@ def setup assert user.active_for_authentication? user.confirmation_sent_at = 5.days.ago - assert_not user.active_for_authentication? + refute user.active_for_authentication? end end test 'should be active when already confirmed' do user = create_user - assert_not user.confirmed? - assert_not user.active_for_authentication? + refute user.confirmed? + refute user.active_for_authentication? user.confirm assert user.confirmed? @@ -224,7 +224,7 @@ def setup Devise.allow_unconfirmed_access_for = 0.days user = create_user user.confirmation_sent_at = Time.zone.today - assert_not user.active_for_authentication? + refute user.active_for_authentication? end test 'should be active when we set allow_unconfirmed_access_for to nil' do @@ -239,7 +239,7 @@ def setup user = create_user user.confirmation_sent_at = nil user.save - assert_not user.reload.active_for_authentication? + refute user.reload.active_for_authentication? end test 'should be active without confirmation when confirmation is not required' do @@ -272,7 +272,7 @@ def setup swap Devise, confirmation_keys: [:username, :email] do user = create_user confirm_user = User.send_confirmation_instructions(email: user.email) - assert_not confirm_user.persisted? + refute confirm_user.persisted? assert_equal "can't be blank", confirm_user.errors[:username].join end end @@ -297,7 +297,7 @@ def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at) test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do swap Devise, confirm_within: 3.days do - assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago) + refute confirm_user_by_token_with_confirmation_sent_at(4.days.ago) end end @@ -337,14 +337,14 @@ def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at) self.username = self.username.to_s + 'updated' end old = user.username - assert_not user.confirm + refute user.confirm assert_equal user.username, old end test 'should always perform validations upon confirm when ensure valid true' do admin = create_admin admin.stubs(:valid?).returns(false) - assert_not admin.confirm(ensure_valid: true) + refute admin.confirm(ensure_valid: true) end end @@ -370,7 +370,7 @@ class ReconfirmableTest < ActiveSupport::TestCase admin.skip_reconfirmation! assert admin.update_attributes(email: 'new_test@example.com') assert admin.confirmed? - assert_not admin.pending_reconfirmation? + refute admin.pending_reconfirmation? assert_equal original_token, admin.confirmation_token end @@ -461,7 +461,7 @@ class ReconfirmableTest < ActiveSupport::TestCase test 'should return a new admin if no email or unconfirmed_email was found' do confirmation_admin = Admin.send_confirmation_instructions(email: "invalid@email.com") - assert_not confirmation_admin.persisted? + refute confirmation_admin.persisted? end test 'should add error to new admin email if no email or unconfirmed_email was found' do diff --git a/test/models/database_authenticatable_test.rb b/test/models/database_authenticatable_test.rb index 8c12d93c89..4f7aa75bd5 100644 --- a/test/models/database_authenticatable_test.rb +++ b/test/models/database_authenticatable_test.rb @@ -124,7 +124,7 @@ def setup test 'should test for a valid password' do user = create_user assert user.valid_password?('12345678') - assert_not user.valid_password?('654321') + refute user.valid_password?('654321') end test 'should not raise error with an empty password' do @@ -136,7 +136,7 @@ def setup test 'should be an invalid password if the user has an empty password' do user = create_user user.encrypted_password = '' - assert_not user.valid_password?('654321') + refute user.valid_password?('654321') end test 'should respond to current password' do @@ -152,7 +152,7 @@ def setup test 'should add an error to current password when it is invalid' do user = create_user - assert_not user.update_with_password(current_password: 'other', + refute user.update_with_password(current_password: 'other', password: 'pass4321', password_confirmation: 'pass4321') assert user.reload.valid_password?('12345678') assert_match "is invalid", user.errors[:current_password].join @@ -160,7 +160,7 @@ def setup test 'should add an error to current password when it is blank' do user = create_user - assert_not user.update_with_password(password: 'pass4321', + refute user.update_with_password(password: 'pass4321', password_confirmation: 'pass4321') assert user.reload.valid_password?('12345678') assert_match "can't be blank", user.errors[:current_password].join @@ -170,7 +170,7 @@ def setup user = UserWithValidation.create!(valid_attributes) user.save assert user.persisted? - assert_not user.update_with_password(username: "") + refute user.update_with_password(username: "") assert_match "usertest", user.reload.username assert_match "can't be blank", user.errors[:username].join end @@ -183,14 +183,14 @@ def setup test 'should not update password with invalid confirmation' do user = create_user - assert_not user.update_with_password(current_password: '12345678', + refute user.update_with_password(current_password: '12345678', password: 'pass4321', password_confirmation: 'other') assert user.reload.valid_password?('12345678') end test 'should clean up password fields on failure' do user = create_user - assert_not user.update_with_password(current_password: '12345678', + refute user.update_with_password(current_password: '12345678', password: 'pass4321', password_confirmation: 'other') assert user.password.blank? assert user.password_confirmation.blank? @@ -217,14 +217,14 @@ def setup test 'should not destroy user with invalid password' do user = create_user - assert_not user.destroy_with_password('other') + refute user.destroy_with_password('other') assert user.persisted? assert_match "is invalid", user.errors[:current_password].join end test 'should not destroy user with blank password' do user = create_user - assert_not user.destroy_with_password(nil) + refute user.destroy_with_password(nil) assert user.persisted? assert_match "can't be blank", user.errors[:current_password].join end diff --git a/test/models/lockable_test.rb b/test/models/lockable_test.rb index ac86c77909..38ba351138 100644 --- a/test/models/lockable_test.rb +++ b/test/models/lockable_test.rb @@ -46,7 +46,7 @@ def setup test "should verify whether a user is locked or not" do user = create_user - assert_not user.access_locked? + refute user.access_locked? user.lock_access! assert user.access_locked? end @@ -56,7 +56,7 @@ def setup user.confirm assert user.active_for_authentication? user.lock_access! - assert_not user.active_for_authentication? + refute user.active_for_authentication? end test "should unlock a user by cleaning locked_at, failed_attempts and unlock_token" do @@ -72,7 +72,7 @@ def setup end test "new user should not be locked and should have zero failed_attempts" do - assert_not new_user.access_locked? + refute new_user.access_locked? assert_equal 0, create_user.failed_attempts end @@ -83,7 +83,7 @@ def setup assert user.access_locked? Devise.unlock_in = 1.hour - assert_not user.access_locked? + refute user.access_locked? end end @@ -162,18 +162,18 @@ def setup raw = user.send_unlock_instructions locked_user = User.unlock_access_by_token(raw) assert_equal locked_user, user - assert_not user.reload.access_locked? + refute user.reload.access_locked? end test 'should return a new record with errors when a invalid token is given' do locked_user = User.unlock_access_by_token('invalid_token') - assert_not locked_user.persisted? + refute locked_user.persisted? assert_equal "is invalid", locked_user.errors[:unlock_token].join end test 'should return a new record with errors when a blank token is given' do locked_user = User.unlock_access_by_token('') - assert_not locked_user.persisted? + refute locked_user.persisted? assert_equal "can't be blank", locked_user.errors[:unlock_token].join end @@ -186,7 +186,7 @@ def setup test 'should return a new user if no email was found' do unlock_user = User.send_unlock_instructions(email: "invalid@example.com") - assert_not unlock_user.persisted? + refute unlock_user.persisted? end test 'should add error to new user email if no email was found' do @@ -206,23 +206,23 @@ def setup swap Devise, unlock_keys: [:username, :email] do user = create_user unlock_user = User.send_unlock_instructions(email: user.email) - assert_not unlock_user.persisted? + refute unlock_user.persisted? assert_equal "can't be blank", unlock_user.errors[:username].join end end test 'should not be able to send instructions if the user is not locked' do user = create_user - assert_not user.resend_unlock_instructions - assert_not user.access_locked? + refute user.resend_unlock_instructions + refute user.access_locked? assert_equal 'was not locked', user.errors[:email].join end test 'should not be able to send instructions if the user if not locked and have username as unlock key' do swap Devise, unlock_keys: [:username] do user = create_user - assert_not user.resend_unlock_instructions - assert_not user.access_locked? + refute user.resend_unlock_instructions + refute user.access_locked? assert_equal 'was not locked', user.errors[:username].join end end diff --git a/test/models/recoverable_test.rb b/test/models/recoverable_test.rb index 2585bdd161..bf334b5496 100644 --- a/test/models/recoverable_test.rb +++ b/test/models/recoverable_test.rb @@ -92,14 +92,14 @@ def setup user = create_user user.send_reset_password_instructions assert_present user.reset_password_token - assert_not user.reset_password('123456789', '987654321') + refute user.reset_password('123456789', '987654321') assert_present user.reset_password_token end test 'should not reset password with invalid data' do user = create_user user.stubs(:valid?).returns(false) - assert_not user.reset_password('123456789', '987654321') + refute user.reset_password('123456789', '987654321') end test 'should reset reset password token and send instructions by email' do @@ -119,7 +119,7 @@ def setup test 'should return a new record with errors if user was not found by e-mail' do reset_password_user = User.send_reset_password_instructions(email: "invalid@example.com") - assert_not reset_password_user.persisted? + refute reset_password_user.persisted? assert_equal "not found", reset_password_user.errors[:email].join end @@ -135,7 +135,7 @@ def setup swap Devise, reset_password_keys: [:username, :email] do user = create_user reset_password_user = User.send_reset_password_instructions(email: user.email) - assert_not reset_password_user.persisted? + refute reset_password_user.persisted? assert_equal "can't be blank", reset_password_user.errors[:username].join end end @@ -164,13 +164,13 @@ def setup test 'should return a new record with errors if no reset_password_token is found' do reset_password_user = User.reset_password_by_token(reset_password_token: 'invalid_token') - assert_not reset_password_user.persisted? + refute reset_password_user.persisted? assert_equal "is invalid", reset_password_user.errors[:reset_password_token].join end test 'should return a new record with errors if reset_password_token is blank' do reset_password_user = User.reset_password_by_token(reset_password_token: '') - assert_not reset_password_user.persisted? + refute reset_password_user.persisted? assert_match "can't be blank", reset_password_user.errors[:reset_password_token].join end @@ -179,7 +179,7 @@ def setup raw = user.send_reset_password_instructions reset_password_user = User.reset_password_by_token(reset_password_token: raw, password: '') - assert_not reset_password_user.errors.empty? + refute reset_password_user.errors.empty? assert_match "can't be blank", reset_password_user.errors[:password].join assert_equal raw, reset_password_user.reset_password_token end @@ -197,7 +197,7 @@ def setup assert_nil reset_password_user.reset_password_token user.reload - assert_not user.valid_password?(old_password) + refute user.valid_password?(old_password) assert user.valid_password?('new_password') assert_nil user.reset_password_token end @@ -219,7 +219,7 @@ def setup user.reload assert user.valid_password?(old_password) - assert_not user.valid_password?('new_password') + refute user.valid_password?('new_password') assert_equal "has expired, please request a new one", reset_password_user.errors[:reset_password_token].join end end diff --git a/test/models/timeoutable_test.rb b/test/models/timeoutable_test.rb index be68246743..dea3ed6684 100644 --- a/test/models/timeoutable_test.rb +++ b/test/models/timeoutable_test.rb @@ -7,11 +7,11 @@ class TimeoutableTest < ActiveSupport::TestCase end test 'should not be expired' do - assert_not new_user.timedout?(29.minutes.ago) + refute new_user.timedout?(29.minutes.ago) end test 'should not be expired when params is nil' do - assert_not new_user.timedout?(nil) + refute new_user.timedout?(nil) end test 'should use timeout_in method' do @@ -19,23 +19,23 @@ class TimeoutableTest < ActiveSupport::TestCase user.instance_eval { def timeout_in; 10.minutes end } assert user.timedout?(12.minutes.ago) - assert_not user.timedout?(8.minutes.ago) + refute user.timedout?(8.minutes.ago) end test 'should not be expired when timeout_in method returns nil' do user = new_user user.instance_eval { def timeout_in; nil end } - assert_not user.timedout?(10.hours.ago) + refute user.timedout?(10.hours.ago) end test 'fallback to Devise config option' do swap Devise, timeout_in: 1.minute do user = new_user assert user.timedout?(2.minutes.ago) - assert_not user.timedout?(30.seconds.ago) + refute user.timedout?(30.seconds.ago) Devise.timeout_in = 5.minutes - assert_not user.timedout?(2.minutes.ago) + refute user.timedout?(2.minutes.ago) assert user.timedout?(6.minutes.ago) end end diff --git a/test/models/validatable_test.rb b/test/models/validatable_test.rb index 0491297b38..a54810e8c0 100644 --- a/test/models/validatable_test.rb +++ b/test/models/validatable_test.rb @@ -97,7 +97,7 @@ class ValidatableTest < ActiveSupport::TestCase user.password_confirmation = 'confirmation' assert user.invalid? - assert_not (user.errors[:password].join =~ /is too long/) + refute (user.errors[:password].join =~ /is too long/) end test 'should complain about length even if password is not required' do diff --git a/test/models_test.rb b/test/models_test.rb index 3fc78806f6..3b462afc1b 100644 --- a/test/models_test.rb +++ b/test/models_test.rb @@ -13,7 +13,7 @@ def assert_include_modules(klass, *modules) end (Devise::ALL - modules).each do |mod| - assert_not include_module?(klass, mod) + refute include_module?(klass, mod) end end diff --git a/test/support/assertions.rb b/test/support/assertions.rb index 864999efd2..1198e84c0e 100644 --- a/test/support/assertions.rb +++ b/test/support/assertions.rb @@ -1,10 +1,6 @@ require 'active_support/test_case' class ActiveSupport::TestCase - def assert_not(assertion) - assert !assertion - end - def assert_blank(assertion) assert assertion.blank? end