Do not track associations by default

[Fixes #740]
This commit is contained in:
Jared Beck 2016-04-26 22:06:22 -04:00
parent a55eb9b7a8
commit e36ba138a3
4 changed files with 30 additions and 3 deletions

View File

@ -5,6 +5,8 @@
- [#758](https://github.com/airblade/paper_trail/pull/758) -
`PaperTrail.config.track_associations` getter method removed,
use `track_associations?` instead.
- [#740](https://github.com/airblade/paper_trail/issues/740) -
`PaperTrail.config.track_associations?` now defaults to false
- [#723](https://github.com/airblade/paper_trail/pull/723) -
`PaperTrail.enabled=` now affects all threads
- [#556](https://github.com/airblade/paper_trail/pull/556) /

View File

@ -34,9 +34,19 @@ module PaperTrail
)
end
# Previously, we checked `PaperTrail::VersionAssociation.table_exists?`
# here, but that proved to be problematic in situations when the database
# connection had not been established, or when the database does not exist
# yet (as with `rake db:create`).
def track_associations?
if @track_associations.nil?
PaperTrail::VersionAssociation.table_exists?
ActiveSupport::Deprecation.warn <<-EOS.strip_heredoc.gsub(/\s+/, " ")
PaperTrail.track_associations has not been set. As of PaperTrail 5, it
defaults to false. Tracking associations is an experimental feature so
we recommend setting PaperTrail.config.track_associations = false in
your config/initializers/paper_trail.rb
EOS
false
else
@track_associations
end

View File

@ -13,5 +13,21 @@ module PaperTrail
expect { described_class.new }.to raise_error(NoMethodError)
end
end
describe "track_associations?" do
context "@track_associations is nil" do
after do
PaperTrail.config.track_associations = true
end
it "returns false and prints a deprecation warning" do
config = described_class.instance
config.track_associations = nil
expect {
expect(config.track_associations?).to eq(false)
}.to output(/DEPRECATION WARNING/).to_stderr
end
end
end
end
end

View File

@ -1,5 +1,4 @@
# Turn on associations tracking when the test suite is run on Travis CI
PaperTrail.config.track_associations = true if ENV["TRAVIS"]
PaperTrail.config.track_associations = true
module PaperTrail
class Version < ActiveRecord::Base