User `assert_includes`/`refute_includes` minitest helpers

This commit is contained in:
Carlos Antonio da Silva 2020-08-27 18:38:26 -03:00
parent e39b9b9134
commit 15135f7dc6
16 changed files with 34 additions and 34 deletions

View File

@ -16,6 +16,6 @@ class LoadHooksControllerTest < Devise::ControllerTestCase
end
test 'load hook called when controller is loaded' do
assert DeviseController.instance_methods.include? :defined_by_load_hook
assert_includes DeviseController.instance_methods, :defined_by_load_hook
end
end
end

View File

@ -326,8 +326,8 @@ class FailureTest < ActiveSupport::TestCase
"warden" => stub_everything
}
call_failure(env)
assert @response.third.body.include?('<h2>Log in</h2>')
assert @response.third.body.include?('Invalid Email or password.')
assert_includes @response.third.body, '<h2>Log in</h2>'
assert_includes @response.third.body, 'Invalid Email or password.'
end
test 'calls the original controller if not confirmed email' do
@ -337,8 +337,8 @@ class FailureTest < ActiveSupport::TestCase
"warden" => stub_everything
}
call_failure(env)
assert @response.third.body.include?('<h2>Log in</h2>')
assert @response.third.body.include?('You have to confirm your email address before continuing.')
assert_includes @response.third.body, '<h2>Log in</h2>'
assert_includes @response.third.body, 'You have to confirm your email address before continuing.'
end
test 'calls the original controller if inactive account' do
@ -348,8 +348,8 @@ class FailureTest < ActiveSupport::TestCase
"warden" => stub_everything
}
call_failure(env)
assert @response.third.body.include?('<h2>Log in</h2>')
assert @response.third.body.include?('Your account is not activated yet.')
assert_includes @response.third.body, '<h2>Log in</h2>'
assert_includes @response.third.body, 'Your account is not activated yet.'
end
if Rails.application.config.respond_to?(:relative_url_root)
@ -361,8 +361,8 @@ class FailureTest < ActiveSupport::TestCase
"warden" => stub_everything
}
call_failure(env)
assert @response.third.body.include?('<h2>Log in</h2>')
assert @response.third.body.include?('Invalid Email or password.')
assert_includes @response.third.body, '<h2>Log in</h2>'
assert_includes @response.third.body, 'Invalid Email or password.'
assert_equal '/sample', @request.env["SCRIPT_NAME"]
assert_equal '/users/sign_in', @request.env["PATH_INFO"]
end

View File

@ -496,7 +496,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
create_user
post user_session_path(format: 'xml'), params: { user: {email: "user@test.com", password: '12345678'} }
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'sign in with xml format is idempotent' do
@ -512,7 +512,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
post user_session_path(format: 'xml'), params: { user: {email: "user@test.com", password: '12345678'} }
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'sign out with html redirects' do

View File

@ -225,21 +225,21 @@ class ConfirmationTest < Devise::IntegrationTest
create_user(confirm: false)
post user_confirmation_path(format: 'xml'), params: { user: { email: 'invalid.test@test.com' } }
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'confirm account with valid confirmation token in XML format should return valid response' do
user = create_user(confirm: false)
get user_confirmation_path(confirmation_token: user.raw_confirmation_token, format: 'xml')
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'confirm account with invalid confirmation token in XML format should return invalid response' do
create_user(confirm: false)
get user_confirmation_path(confirmation_token: 'invalid_confirmation', format: 'xml')
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'request an account confirmation account with JSON, should return an empty JSON' do

View File

@ -146,7 +146,7 @@ class LockTest < Devise::IntegrationTest
post user_unlock_path(format: 'xml'), params: { user: {email: user.email} }
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_equal 0, ActionMailer::Base.deliveries.size
end
@ -156,13 +156,13 @@ class LockTest < Devise::IntegrationTest
assert user.access_locked?
get user_unlock_path(format: 'xml', unlock_token: raw)
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'user with invalid unlock token should not be able to unlock the account via XML request' do
get user_unlock_path(format: 'xml', unlock_token: 'invalid_token')
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test "when using json to ask a unlock request, should not return the user" do

View File

@ -272,7 +272,7 @@ class PasswordTest < Devise::IntegrationTest
create_user
post user_password_path(format: 'xml'), params: { user: {email: "invalid.test@test.com"} }
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'reset password request with invalid E-Mail in XML format should return empty and valid response' do
@ -300,7 +300,7 @@ class PasswordTest < Devise::IntegrationTest
request_forgot_password
put user_password_path(format: 'xml'), params: { user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'} }
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'change password with invalid new password in XML format should return invalid response' do
@ -308,7 +308,7 @@ class PasswordTest < Devise::IntegrationTest
request_forgot_password
put user_password_path(format: 'xml'), params: { user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'} }
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test "when using json requests to ask a confirmable request, should not return the object" do

View File

@ -300,7 +300,7 @@ class RegistrationTest < Devise::IntegrationTest
test 'an admin sign up with valid information in XML format should return valid response' do
post admin_registration_path(format: 'xml'), params: { admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
admin = Admin.to_adapter.find_first(order: [:id, :desc])
assert_equal 'new_user@test.com', admin.email
@ -309,7 +309,7 @@ class RegistrationTest < Devise::IntegrationTest
test 'a user sign up with valid information in XML format should return valid response' do
post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
user = User.to_adapter.find_first(order: [:id, :desc])
assert_equal 'new_user@test.com', user.email
@ -318,7 +318,7 @@ class RegistrationTest < Devise::IntegrationTest
test 'a user sign up with invalid information in XML format should return invalid response' do
post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' } }
assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_includes response.body, %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end
test 'a user update information with valid data in XML format should return valid response' do

View File

@ -31,7 +31,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
end
test 'content type should be set to html' do
assert mail.content_type.include?('text/html')
assert_includes mail.content_type, 'text/html'
end
test 'send confirmation instructions to the user email' do

View File

@ -35,7 +35,7 @@ class EmailChangedTest < ActionMailer::TestCase
end
test 'content type should be set to html' do
assert mail.content_type.include?('text/html')
assert_includes mail.content_type, 'text/html'
end
test 'send email changed to the original user email' do

View File

@ -34,7 +34,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
end
test 'content type should be set to html' do
assert mail.content_type.include?('text/html')
assert_includes mail.content_type, 'text/html'
end
test 'send confirmation instructions to the user email' do

View File

@ -35,7 +35,7 @@ class UnlockInstructionsTest < ActionMailer::TestCase
end
test 'content type should be set to html' do
assert mail.content_type.include?('text/html')
assert_includes mail.content_type, 'text/html'
end
test 'send unlock instructions to the user email' do

View File

@ -28,7 +28,7 @@ class ConfirmableTest < ActiveSupport::TestCase
confirmation_tokens = []
3.times do
token = create_user.confirmation_token
assert !confirmation_tokens.include?(token)
refute_includes confirmation_tokens, token
confirmation_tokens << token
end
end

View File

@ -121,7 +121,7 @@ class LockableTest < ActiveSupport::TestCase
user = create_user
user.lock_access!
token = user.unlock_token
assert !unlock_tokens.include?(token)
refute_includes unlock_tokens, token
unlock_tokens << token
end
end

View File

@ -18,7 +18,7 @@ class RecoverableTest < ActiveSupport::TestCase
user = create_user
user.send_reset_password_instructions
token = user.reset_password_token
assert !reset_password_tokens.include?(token)
refute_includes reset_password_tokens, token
reset_password_tokens << token
end
end

View File

@ -61,7 +61,7 @@ class ActionDispatch::IntegrationTest
# account Middleware redirects.
#
def assert_redirected_to(url)
assert [301, 302].include?(@integration_session.status),
assert_includes [301, 302], @integration_session.status,
"Expected status to be 301 or 302, got #{@integration_session.status}"
assert_url url, @integration_session.headers["Location"]

View File

@ -104,9 +104,9 @@ class TestControllerHelpersTest < Devise::ControllerTestCase
get :index, params: { format: :xml }
if Devise::Test.rails6?
assert response.media_type.include?('application/xml')
assert_includes response.media_type, 'application/xml'
else
assert response.content_type.include?('application/xml')
assert_includes response.content_type, 'application/xml'
end
end