Add Railtie config option: config.paper_trail.enabled

This commit is contained in:
Herman verschooten 2016-01-16 22:48:27 +01:00 committed by Jared Beck
parent 534aa778fb
commit 2029ea37ac
5 changed files with 19 additions and 4 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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"

View File

@ -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

View File

@ -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