From 7dbe2d19fe710f971aeb780794d3e38155ab7b81 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 18 Aug 2021 14:05:19 +0200 Subject: [PATCH] Move factory linting to CI cycle No need to do this before each and every spec or example. Speeds up suite and make things less fragile. --- .github/workflows/spec.yml | 1 + dotenv.example | 4 ---- lib/tasks/factory_bot.rake | 11 ++++------- lib/tasks/migrate_config.rake | 1 - spec/support/factory_bot.rb | 20 -------------------- 5 files changed, 5 insertions(+), 32 deletions(-) delete mode 100644 spec/support/factory_bot.rb diff --git a/.github/workflows/spec.yml b/.github/workflows/spec.yml index 9431e8b4..a80430d0 100644 --- a/.github/workflows/spec.yml +++ b/.github/workflows/spec.yml @@ -41,6 +41,7 @@ jobs: rm -f osem_test osem_development bundle exec rake db:setup --trace bundle exec bin/rails webdrivers:chromedriver:update + bundle exec rake factory_bot:lint RAILS_ENV=test - name: spec/${{ matrix.suite }} run: bundle exec rake spec:${{ matrix.suite }} - name: coverage upload ${{ matrix.suite }} diff --git a/dotenv.example b/dotenv.example index dfecb0cb..f02147af 100644 --- a/dotenv.example +++ b/dotenv.example @@ -115,10 +115,6 @@ # SKYLIGHT_AUTHENTICATION=1234 # SKYLIGHT_PUBLIC_DASHBOARD_URL='https://oss.skylight.io/app/applications/xxxxxxxxxxxx' -# Disable linting of factories in the test suite. -# Speeds up turn around times of tests -# OSEM_FACTORY_LINT=false - # How should browser tests be performed? # For headless Chrome (default): # OSEM_TEST_DRIVER=chrome_headless diff --git a/lib/tasks/factory_bot.rake b/lib/tasks/factory_bot.rake index 177d2f09..971ed5fc 100644 --- a/lib/tasks/factory_bot.rake +++ b/lib/tasks/factory_bot.rake @@ -1,17 +1,14 @@ -# frozen_string_literal: true - namespace :factory_bot do desc "Verify that all FactoryBot factories are valid" task lint: :environment do if Rails.env.test? - begin - DatabaseCleaner.start + conn = ActiveRecord::Base.connection + conn.transaction do FactoryBot.lint - ensure - DatabaseCleaner.clean + raise ActiveRecord::Rollback end else - system("bundle exec rake factory_bot:lint RAILS_ENV='test'") + raise "\nERROR: You should not run this outside the test environment...\n\n" end end end diff --git a/lib/tasks/migrate_config.rake b/lib/tasks/migrate_config.rake index 7cd22ade..a012d323 100644 --- a/lib/tasks/migrate_config.rake +++ b/lib/tasks/migrate_config.rake @@ -28,7 +28,6 @@ namespace :data do dot_env.puts "OSEM_ICHAIN_ENABLED=\"#{CONFIG['authentication']['ichain']['enabled']}\"" if CONFIG.has_key?(:authentication) dot_env.puts "OSEM_TRANSIFEX_APIKEY=\"#{CONFIG['transifex_live_api_key']}\"" dot_env.puts "OSEM_ERRBIT_HOST=\"#{CONFIG['errbit_host']}\"" - dot_env.puts "OSEM_FACTORY_LINT=\"#{CONFIG['factory_bot_lint']}\"" dot_env.puts "OSEM_SMTP_ADDRESS=\"#{CONFIG['mail_address']}\"" dot_env.puts "OSEM_SMTP_PORT=\"#{CONFIG['mail_port']}\"" dot_env.puts "OSEM_SMTP_USERNAME=\"#{CONFIG['mail_username']}\"" diff --git a/spec/support/factory_bot.rb b/spec/support/factory_bot.rb deleted file mode 100644 index 75e2be51..00000000 --- a/spec/support/factory_bot.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require_relative 'external_request' - -RSpec.configure do |config| - - config.before(:suite) do - if ENV['OSEM_FACTORY_LINT'] != 'false' - DatabaseCleaner.strategy = :transaction - DatabaseCleaner.clean_with(:truncation) - begin - DatabaseCleaner.start - mock_commercial_request - FactoryBot.lint - ensure - DatabaseCleaner.clean - end - end - end -end