From 63aec2d25d6cac1322df926689ec33daf491de0e Mon Sep 17 00:00:00 2001 From: fatkodima Date: Thu, 16 May 2024 21:21:26 +0300 Subject: [PATCH] Do not load `ActiveRecord` too early --- lib/database_cleaner/active_record.rb | 14 +++++++++----- lib/database_cleaner/active_record/base.rb | 1 - lib/database_cleaner/active_record/deletion.rb | 3 --- lib/database_cleaner/active_record/transaction.rb | 2 -- lib/database_cleaner/active_record/truncation.rb | 1 - spec/spec_helper.rb | 2 ++ 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/database_cleaner/active_record.rb b/lib/database_cleaner/active_record.rb index 274c001f..b3b60550 100644 --- a/lib/database_cleaner/active_record.rb +++ b/lib/database_cleaner/active_record.rb @@ -1,7 +1,11 @@ -require 'database_cleaner/active_record/version' +require 'active_record' require 'database_cleaner/core' -require 'database_cleaner/active_record/transaction' -require 'database_cleaner/active_record/truncation' -require 'database_cleaner/active_record/deletion' -DatabaseCleaner[:active_record].strategy = :transaction +ActiveSupport.on_load(:active_record) do + require 'database_cleaner/active_record/base' + require 'database_cleaner/active_record/transaction' + require 'database_cleaner/active_record/truncation' + require 'database_cleaner/active_record/deletion' + + DatabaseCleaner[:active_record].strategy = :transaction +end diff --git a/lib/database_cleaner/active_record/base.rb b/lib/database_cleaner/active_record/base.rb index e804a5b1..4ee61653 100644 --- a/lib/database_cleaner/active_record/base.rb +++ b/lib/database_cleaner/active_record/base.rb @@ -1,4 +1,3 @@ -require 'active_record' require 'database_cleaner/strategy' require 'erb' require 'yaml' diff --git a/lib/database_cleaner/active_record/deletion.rb b/lib/database_cleaner/active_record/deletion.rb index 17998867..ad282120 100644 --- a/lib/database_cleaner/active_record/deletion.rb +++ b/lib/database_cleaner/active_record/deletion.rb @@ -1,6 +1,3 @@ -require 'active_record' -require 'database_cleaner/active_record/truncation' - module DatabaseCleaner module ActiveRecord class Deletion < Truncation diff --git a/lib/database_cleaner/active_record/transaction.rb b/lib/database_cleaner/active_record/transaction.rb index 85e7c3df..6d3722ec 100644 --- a/lib/database_cleaner/active_record/transaction.rb +++ b/lib/database_cleaner/active_record/transaction.rb @@ -1,5 +1,3 @@ -require 'database_cleaner/active_record/base' - module DatabaseCleaner module ActiveRecord class Transaction < Base diff --git a/lib/database_cleaner/active_record/truncation.rb b/lib/database_cleaner/active_record/truncation.rb index a3758e6b..2e044a07 100644 --- a/lib/database_cleaner/active_record/truncation.rb +++ b/lib/database_cleaner/active_record/truncation.rb @@ -1,5 +1,4 @@ require "delegate" -require 'database_cleaner/active_record/base' module DatabaseCleaner module ActiveRecord diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7912aef4..f54dccf5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,6 +18,8 @@ require 'database_cleaner-active_record' +ActiveRecord::Base # load active record + RSpec.configure do |config| # These two settings work together to allow you to limit a spec run # to individual examples or groups you care about by tagging them with