Skip to content

Commit

Permalink
Merge branch 'ca-replace-refute-assert-not'
Browse files Browse the repository at this point in the history
Prefer `assert_not*` helpers.

Closes #5158
  • Loading branch information
carlosantoniodasilva committed Mar 2, 2023
2 parents 400eaf7 + 890bd9e commit 7d1dc56
Show file tree
Hide file tree
Showing 26 changed files with 181 additions and 181 deletions.
4 changes: 2 additions & 2 deletions test/controllers/helper_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class HelperMethodsTest < Devise::ControllerTestCase
end

test 'does not respond_to helper or helper_method' do
refute_respond_to @controller.class, :helper
refute_respond_to @controller.class, :helper_method
assert_not_respond_to @controller.class, :helper
assert_not_respond_to @controller.class, :helper_method
end

test 'defines methods like current_user' do
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def setup

test 'proxy admin_signed_in? to authenticatewith admin scope' do
@mock_warden.expects(:authenticate).with(scope: :admin)
refute @controller.admin_signed_in?
assert_not @controller.admin_signed_in?
end

test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
Expand Down Expand Up @@ -319,10 +319,10 @@ def setup

test 'is_flashing_format? is guarded against flash (middleware) not being loaded' do
@controller.request.expects(:respond_to?).with(:flash).returns(false)
refute @controller.is_flashing_format?
assert_not @controller.is_flashing_format?
end

test 'is not a devise controller' do
refute @controller.devise_controller?
assert_not @controller.devise_controller?
end
end
2 changes: 1 addition & 1 deletion test/controllers/internal_helpers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def setup
MyController.send(:public, :navigational_formats)

swap Devise, navigational_formats: ['*/*', :html] do
refute @controller.navigational_formats.include?("*/*")
assert_not @controller.navigational_formats.include?("*/*")
end

MyController.send(:protected, :navigational_formats)
Expand Down
12 changes: 6 additions & 6 deletions test/devise_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class DeviseTest < ActiveSupport::TestCase
test 'add new module using the helper method' do
Devise.add_module(:coconut)
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
refute Devise::STRATEGIES.include?(:coconut)
refute defined?(Devise::Models::Coconut)
assert_not Devise::STRATEGIES.include?(:coconut)
assert_not defined?(Devise::Models::Coconut)
Devise::ALL.delete(:coconut)

Devise.add_module(:banana, strategy: :fruits)
Expand All @@ -88,11 +88,11 @@ class DeviseTest < ActiveSupport::TestCase

test 'should complain when comparing empty or different sized passes' do
[nil, ""].each do |empty|
refute Devise.secure_compare(empty, "something")
refute Devise.secure_compare("something", empty)
refute Devise.secure_compare(empty, empty)
assert_not Devise.secure_compare(empty, "something")
assert_not Devise.secure_compare("something", empty)
assert_not Devise.secure_compare(empty, empty)
end
refute Devise.secure_compare("size_1", "size_four")
assert_not Devise.secure_compare("size_1", "size_four")
end

test 'Devise.email_regexp should match valid email addresses' do
Expand Down
74 changes: 37 additions & 37 deletions test/integration/authenticatable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
test 'sign in should not run model validations' do
sign_in_as_user

refute User.validations_performed
assert_not User.validations_performed
end

test 'home should be accessible without sign in' do
Expand All @@ -18,13 +18,13 @@ class AuthenticationSanityTest < Devise::IntegrationTest
test 'sign in as user should not authenticate admin scope' do
sign_in_as_user
assert warden.authenticated?(:user)
refute warden.authenticated?(:admin)
assert_not warden.authenticated?(:admin)
end

test 'sign in as admin should not authenticate user scope' do
sign_in_as_admin
assert warden.authenticated?(:admin)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)
end

test 'sign in as both user and admin at same time' do
Expand All @@ -39,7 +39,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
sign_in_as_user
sign_in_as_admin
delete destroy_user_session_path
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)
assert warden.authenticated?(:admin)
end
end
Expand All @@ -50,7 +50,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
sign_in_as_admin

delete destroy_admin_session_path
refute warden.authenticated?(:admin)
assert_not warden.authenticated?(:admin)
assert warden.authenticated?(:user)
end
end
Expand All @@ -61,8 +61,8 @@ class AuthenticationSanityTest < Devise::IntegrationTest
sign_in_as_admin

delete destroy_user_session_path
refute warden.authenticated?(:user)
refute warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
end
end

Expand All @@ -72,21 +72,21 @@ class AuthenticationSanityTest < Devise::IntegrationTest
sign_in_as_admin

delete destroy_admin_session_path
refute warden.authenticated?(:admin)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
assert_not 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
refute warden.authenticated?(:admin)
assert_not 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)
refute warden.authenticated?(:admin)
assert_not warden.authenticated?(:admin)

get admins_path
assert_redirected_to new_admin_session_path
Expand All @@ -95,7 +95,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)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)

get admins_path

Expand Down Expand Up @@ -123,7 +123,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest

get root_path
assert_contain 'Signed out successfully'
refute warden.authenticated?(:admin)
assert_not warden.authenticated?(:admin)
end

test 'unauthenticated admin set message on sign out' do
Expand All @@ -146,21 +146,21 @@ 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
refute warden.authenticated?(:admin)
assert_not 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)
refute warden.authenticated?(:admin)
assert_not warden.authenticated?(:admin)
get private_path
assert_redirected_to new_admin_session_path
end

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)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)

get private_path

Expand All @@ -172,7 +172,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)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)

assert_raises ActionController::RoutingError do
get "/private/active"
Expand All @@ -182,7 +182,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)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)

get private_active_path

Expand All @@ -194,7 +194,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)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)

get dashboard_path

Expand All @@ -206,7 +206,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)
refute warden.authenticated?(:admin)
assert_not warden.authenticated?(:admin)

get dashboard_path

Expand All @@ -224,7 +224,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)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)

assert_raises ActionController::RoutingError do
get "/dashboard/active"
Expand All @@ -234,7 +234,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)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)

get dashboard_active_path

Expand All @@ -246,7 +246,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)
refute warden.authenticated?(:admin)
assert_not warden.authenticated?(:admin)

assert_raises ActionController::RoutingError do
get join_path
Expand Down Expand Up @@ -397,7 +397,7 @@ class AuthenticationWithScopedViewsTest < Devise::IntegrationTest
end

assert_match %r{Special user view}, response.body
assert !Devise::PasswordsController.scoped_views?
assert_not Devise::PasswordsController.scoped_views?
ensure
Devise::SessionsController.send :remove_instance_variable, :@scoped_views
end
Expand All @@ -424,13 +424,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)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)

sign_in_as_user
assert warden.authenticated?(:user)

post exhibit_user_url(1)
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)
assert_equal "User is not authenticated", response.body
end
end
Expand Down Expand Up @@ -485,7 +485,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
test 'uses the mapping from router' do
sign_in_as_user visit: "/as/sign_in"
assert warden.authenticated?(:user)
refute warden.authenticated?(:admin)
assert_not warden.authenticated?(:admin)
end

test 'sign in with json format returns json response' do
Expand Down Expand Up @@ -527,15 +527,15 @@ class AuthenticationOthersTest < Devise::IntegrationTest
sign_in_as_user
delete destroy_user_session_path(format: 'json')
assert_response :no_content
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)
end

test 'sign out with non-navigational format via XHR does not redirect' do
swap Devise, navigational_formats: ['*/*', :html] do
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
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)
end
end

Expand All @@ -545,7 +545,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
sign_in_as_user
delete destroy_user_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "text/html,*/*" }
assert_response :redirect
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)
end
end
end
Expand All @@ -555,7 +555,7 @@ class AuthenticationKeysTest < Devise::IntegrationTest
swap Devise, authentication_keys: [:subdomain] do
sign_in_as_user
assert_contain "Invalid Subdomain or password."
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)
end
end

Expand Down Expand Up @@ -584,7 +584,7 @@ class AuthenticationRequestKeysTest < Devise::IntegrationTest
sign_in_as_user
end

refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)
end
end

Expand All @@ -594,7 +594,7 @@ class AuthenticationRequestKeysTest < Devise::IntegrationTest
swap Devise, request_keys: [:subdomain] do
sign_in_as_user
assert_contain "Invalid Email or password."
refute warden.authenticated?(:user)
assert_not warden.authenticated?(:user)
end
end

Expand All @@ -617,7 +617,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
refute warden.authenticated?(:sign_out_via_delete)
assert_not warden.authenticated?(:sign_out_via_delete)
end

test 'do not allow sign out via get when sign_out_via provides only delete' do
Expand All @@ -631,7 +631,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
refute warden.authenticated?(:sign_out_via_post)
assert_not warden.authenticated?(:sign_out_via_post)
end

test 'do not allow sign out via get when sign_out_via provides only post' do
Expand All @@ -645,13 +645,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
refute warden.authenticated?(:sign_out_via_delete_or_post)
assert_not 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
refute warden.authenticated?(:sign_out_via_delete_or_post)
assert_not 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
Expand Down
Loading

0 comments on commit 7d1dc56

Please sign in to comment.