diff --git a/CHANGELOG.md b/CHANGELOG.md index ac7497b7..abed4914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - [#689](https://github.com/airblade/paper_trail/pull/689) - Rails 5 compatibility +- Added a rails config option: `config.paper_trail.enabled` ### Fixed @@ -29,6 +30,8 @@ - [#635](https://github.com/airblade/paper_trail/issues/635) - A bug where it was not possible to disable PT when using a multi-threaded webserver. +- [#584](https://github.com/airblade/paper_trail/issues/584) - + Fixed deprecation warning for Active Record after_callback / after_commit ## 4.1.0 (2016-01-30) diff --git a/README.md b/README.md index bdd2e01e..f6a8019c 100644 --- a/README.md +++ b/README.md @@ -418,6 +418,13 @@ PaperTrail.enabled = false This is commonly used to speed up tests. See [Testing](#testing) below. +There is also a rails config option that does the same thing. + +```ruby +# in config/environments/test.rb +config.paper_trail.enabled = false +``` + ### Per Request Add a `paper_trail_enabled_for_controller` method to your controller. diff --git a/lib/paper_trail.rb b/lib/paper_trail.rb index 296b2ef4..5d26faab 100644 --- a/lib/paper_trail.rb +++ b/lib/paper_trail.rb @@ -170,10 +170,6 @@ unless PaperTrail.active_record_protected_attributes? end end -ActiveSupport.on_load(:active_record) do - include PaperTrail::Model -end - # Require frameworks require "paper_trail/frameworks/sinatra" if defined?(::Rails) && ActiveRecord::VERSION::STRING >= "3.2" diff --git a/lib/paper_trail/frameworks/active_record.rb b/lib/paper_trail/frameworks/active_record.rb index d79e7c10..8e833acf 100644 --- a/lib/paper_trail/frameworks/active_record.rb +++ b/lib/paper_trail/frameworks/active_record.rb @@ -2,3 +2,7 @@ # since otherwise the model(s) will get loaded in via the `Rails::Engine`. require "paper_trail/frameworks/active_record/models/paper_trail/version_association" require "paper_trail/frameworks/active_record/models/paper_trail/version" + +ActiveSupport.on_load(:active_record) do + include PaperTrail::Model +end diff --git a/lib/paper_trail/frameworks/rails/engine.rb b/lib/paper_trail/frameworks/rails/engine.rb index 369e95ba..e0562212 100644 --- a/lib/paper_trail/frameworks/rails/engine.rb +++ b/lib/paper_trail/frameworks/rails/engine.rb @@ -2,6 +2,11 @@ module PaperTrail module Rails class Engine < ::Rails::Engine paths["app/models"] << "lib/paper_trail/frameworks/active_record/models" + config.paper_trail = ActiveSupport::OrderedOptions.new + initializer "paper_trail.initialisation" do |app| + ActiveRecord::Base.send :include, PaperTrail::Model + PaperTrail.enabled = app.config.paper_trail.fetch(:enabled, true) + end end end end