Skip to content

Commit

Permalink
Defer loading when active record is properly loaded
Browse files Browse the repository at this point in the history
This is well known issue. We should prefer to code that reference active
record only when it's already lazy loaded.
It can break other gems initializing process

Related:
- rails/rails#46567
- paper-trail-gem/paper_trail@fc6c5f6
(inspiration)
- thoughtbot/factory_bot_rails#432

Fix: DatabaseCleaner#89
  • Loading branch information
benoittgt committed Nov 23, 2023
1 parent 7da2abe commit 781e435
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/database_cleaner-active_record.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require "database_cleaner/active_record"
require "database_cleaner/active_record/railtie"
11 changes: 11 additions & 0 deletions lib/database_cleaner/active_record/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module DatabaseCleaner::ActiveRecord
class Railtie < ::Rails::Railtie
initializer "database_cleaner-active_record" do
ActiveSupport.on_load(:active_record) do
require "database_cleaner/active_record"
end
end
end
end

0 comments on commit 781e435

Please sign in to comment.