Skip to content

Commit

Permalink
Replace homemade assert_not matcher in favor of refute.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmazza committed May 3, 2016
1 parent 0313512 commit 536279b
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 148 deletions.
4 changes: 2 additions & 2 deletions test/controllers/helpers_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/controllers/internal_helpers_test.rb
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions test/devise_test.rb
Expand Up @@ -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) }
Expand All @@ -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
Expand Down
72 changes: 36 additions & 36 deletions test/integration/authenticatable_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -138,21 +138,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
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

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

Expand All @@ -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"
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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"
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -515,22 +515,22 @@ 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
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
assert_not warden.authenticated?(:user)
refute warden.authenticated?(:user)
end
end

Expand All @@ -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
Expand All @@ -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

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

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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 536279b

Please sign in to comment.