From 55ea782b862a666d1e464d0f66f9aade28ec1e85 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Mon, 15 Jul 2024 00:05:56 +0200 Subject: [PATCH] tests rubocopified --- Gemfile | 4 +++- Gemfile.lock | 6 ++++++ test/controllers/admin_controller_test.rb | 8 ++++---- test/test_helper.rb | 22 +++++++++++++--------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 1772505..0adf279 100644 --- a/Gemfile +++ b/Gemfile @@ -97,6 +97,8 @@ group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri + + gem 'factory_bot_rails' end group :test do @@ -159,4 +161,4 @@ gem 'cancancan' # Gravatars gem 'gravtastic' -gem 'bzip2-ffi' \ No newline at end of file +gem 'bzip2-ffi' diff --git a/Gemfile.lock b/Gemfile.lock index 2246d20..c7960c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -138,6 +138,11 @@ GEM e2mmap (0.1.0) erubi (1.12.0) execjs (2.9.1) + factory_bot (6.4.6) + activesupport (>= 5.0.0) + factory_bot_rails (6.4.3) + factory_bot (~> 6.4) + railties (>= 5.0.0) faraday (2.8.1) base64 faraday-net_http (>= 2.0, < 3.1) @@ -495,6 +500,7 @@ DEPENDENCIES capybara debug devise + factory_bot_rails fastimage font-awesome-rails foundation-rails (~> 6.6) diff --git a/test/controllers/admin_controller_test.rb b/test/controllers/admin_controller_test.rb index 78b0b3b..b4406a4 100644 --- a/test/controllers/admin_controller_test.rb +++ b/test/controllers/admin_controller_test.rb @@ -1,18 +1,18 @@ -require "test_helper" +require 'test_helper' class AdminControllerTest < ActionController::TestCase - test "user must login" do + test 'user must login' do get :status assert_redirected_to user_session_path end - test "normal user must not see admin status" do + test 'normal user must not see admin status' do sign_in users(:normal) get :status assert_response :forbidden end - test "admin can see status" do + test 'admin can see status' do sign_in users(:admin) get :status assert_response :success diff --git a/test/test_helper.rb b/test/test_helper.rb index 59f80b7..dd4abd9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,21 +1,25 @@ ENV['RAILS_ENV'] ||= 'test' -require File.expand_path("../../config/environment", __FILE__) -require "rails/test_help" +require File.expand_path('../config/environment', __dir__) +require 'rails/test_help' -require "minitest/reporters" +require 'minitest/reporters' Minitest::Reporters.use! # require "minitest/rails" # require "minitest/autorun" # Uncomment for awesome colorful output -require "minitest/pride" +require 'minitest/pride' -class ActiveSupport::TestCase - # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. - fixtures :all +module ActiveSupport + class TestCase + # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. + fixtures :all + end end -class ActionController::TestCase - include Devise::Test::ControllerHelpers +module ActionController + class TestCase + include Devise::Test::ControllerHelpers + end end