From 15135f7dc61e3b109e62f1e9be826cb31dfd12d9 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 27 Aug 2020 18:38:26 -0300 Subject: [PATCH] User `assert_includes`/`refute_includes` minitest helpers --- test/controllers/load_hooks_controller_test.rb | 4 ++-- test/failure_app_test.rb | 16 ++++++++-------- test/integration/authenticatable_test.rb | 4 ++-- test/integration/confirmable_test.rb | 6 +++--- test/integration/lockable_test.rb | 6 +++--- test/integration/recoverable_test.rb | 6 +++--- test/integration/registerable_test.rb | 6 +++--- test/mailers/confirmation_instructions_test.rb | 2 +- test/mailers/email_changed_test.rb | 2 +- test/mailers/reset_password_instructions_test.rb | 2 +- test/mailers/unlock_instructions_test.rb | 2 +- test/models/confirmable_test.rb | 2 +- test/models/lockable_test.rb | 2 +- test/models/recoverable_test.rb | 2 +- test/support/integration.rb | 2 +- test/test/controller_helpers_test.rb | 4 ++-- 16 files changed, 34 insertions(+), 34 deletions(-) diff --git a/test/controllers/load_hooks_controller_test.rb b/test/controllers/load_hooks_controller_test.rb index 6387b309..63720c2e 100644 --- a/test/controllers/load_hooks_controller_test.rb +++ b/test/controllers/load_hooks_controller_test.rb @@ -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 \ No newline at end of file +end diff --git a/test/failure_app_test.rb b/test/failure_app_test.rb index dc2a5bbc..920e47cb 100644 --- a/test/failure_app_test.rb +++ b/test/failure_app_test.rb @@ -326,8 +326,8 @@ class FailureTest < ActiveSupport::TestCase "warden" => stub_everything } call_failure(env) - assert @response.third.body.include?('

Log in

') - assert @response.third.body.include?('Invalid Email or password.') + assert_includes @response.third.body, '

Log in

' + 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?('

Log in

') - assert @response.third.body.include?('You have to confirm your email address before continuing.') + assert_includes @response.third.body, '

Log in

' + 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?('

Log in

') - assert @response.third.body.include?('Your account is not activated yet.') + assert_includes @response.third.body, '

Log in

' + 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?('

Log in

') - assert @response.third.body.include?('Invalid Email or password.') + assert_includes @response.third.body, '

Log in

' + 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 diff --git a/test/integration/authenticatable_test.rb b/test/integration/authenticatable_test.rb index 40c79cca..fcc1d734 100644 --- a/test/integration/authenticatable_test.rb +++ b/test/integration/authenticatable_test.rb @@ -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? %(\n) + assert_includes response.body, %(\n) 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? %(\n) + assert_includes response.body, %(\n) end test 'sign out with html redirects' do diff --git a/test/integration/confirmable_test.rb b/test/integration/confirmable_test.rb index 4886a6b5..85b2f723 100644 --- a/test/integration/confirmable_test.rb +++ b/test/integration/confirmable_test.rb @@ -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? %(\n) + assert_includes response.body, %(\n) 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? %(\n) + assert_includes response.body, %(\n) 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? %(\n) + assert_includes response.body, %(\n) end test 'request an account confirmation account with JSON, should return an empty JSON' do diff --git a/test/integration/lockable_test.rb b/test/integration/lockable_test.rb index ca72befd..01077f60 100644 --- a/test/integration/lockable_test.rb +++ b/test/integration/lockable_test.rb @@ -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? %(\n) + assert_includes response.body, %(\n) 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? %(\n) + assert_includes response.body, %(\n) 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? %(\n) + assert_includes response.body, %(\n) end test "when using json to ask a unlock request, should not return the user" do diff --git a/test/integration/recoverable_test.rb b/test/integration/recoverable_test.rb index c6f8c6cf..d3cbb96b 100644 --- a/test/integration/recoverable_test.rb +++ b/test/integration/recoverable_test.rb @@ -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? %(\n) + assert_includes response.body, %(\n) 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? %(\n) + assert_includes response.body, %(\n) 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? %(\n) + assert_includes response.body, %(\n) end test "when using json requests to ask a confirmable request, should not return the object" do diff --git a/test/integration/registerable_test.rb b/test/integration/registerable_test.rb index dfe4b48e..462b478f 100644 --- a/test/integration/registerable_test.rb +++ b/test/integration/registerable_test.rb @@ -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? %(\n) + assert_includes response.body, %(\n) 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? %(\n) + assert_includes response.body, %(\n) 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? %(\n) + assert_includes response.body, %(\n) end test 'a user update information with valid data in XML format should return valid response' do diff --git a/test/mailers/confirmation_instructions_test.rb b/test/mailers/confirmation_instructions_test.rb index 8f9dbc15..5b463312 100644 --- a/test/mailers/confirmation_instructions_test.rb +++ b/test/mailers/confirmation_instructions_test.rb @@ -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 diff --git a/test/mailers/email_changed_test.rb b/test/mailers/email_changed_test.rb index c82517f5..f3241654 100644 --- a/test/mailers/email_changed_test.rb +++ b/test/mailers/email_changed_test.rb @@ -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 diff --git a/test/mailers/reset_password_instructions_test.rb b/test/mailers/reset_password_instructions_test.rb index 1a371b72..5a344cbf 100644 --- a/test/mailers/reset_password_instructions_test.rb +++ b/test/mailers/reset_password_instructions_test.rb @@ -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 diff --git a/test/mailers/unlock_instructions_test.rb b/test/mailers/unlock_instructions_test.rb index 3722cf9c..dff580e2 100644 --- a/test/mailers/unlock_instructions_test.rb +++ b/test/mailers/unlock_instructions_test.rb @@ -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 diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index d6f26c2b..36acf540 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -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 diff --git a/test/models/lockable_test.rb b/test/models/lockable_test.rb index c1844160..8b12d550 100644 --- a/test/models/lockable_test.rb +++ b/test/models/lockable_test.rb @@ -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 diff --git a/test/models/recoverable_test.rb b/test/models/recoverable_test.rb index 69f14a9b..187c2dd1 100644 --- a/test/models/recoverable_test.rb +++ b/test/models/recoverable_test.rb @@ -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 diff --git a/test/support/integration.rb b/test/support/integration.rb index 2dccccf1..94554cba 100644 --- a/test/support/integration.rb +++ b/test/support/integration.rb @@ -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"] diff --git a/test/test/controller_helpers_test.rb b/test/test/controller_helpers_test.rb index 9aad7341..73548e4a 100644 --- a/test/test/controller_helpers_test.rb +++ b/test/test/controller_helpers_test.rb @@ -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