From f3eb7702970f3a77bcda8bc35b6f3e1573187d14 Mon Sep 17 00:00:00 2001 From: Sean Linsley Date: Fri, 10 Aug 2018 12:53:51 -0500 Subject: [PATCH] remove `save_changes` setting --- CHANGELOG.md | 4 ++++ README.md | 4 ---- lib/paper_trail/events/base.rb | 3 +-- lib/paper_trail/has_paper_trail.rb | 2 -- lib/paper_trail/model_config.rb | 3 --- spec/dummy_app/app/models/thing.rb | 2 +- spec/models/thing_spec.rb | 13 ------------- 7 files changed, 6 insertions(+), 25 deletions(-) delete mode 100644 spec/models/thing_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e3f4201c..71a3a4b09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/). - Removed `touch_with_version`, was deprecated in 9.0.0 - [#1121](https://github.com/paper-trail-gem/paper_trail/issues/1121) - `touch` now always inserts `null` in `object_changes`. +- [#1099](https://github.com/paper-trail-gem/paper_trail/issues/1099) - + Removed `save_changes`. For those wanting to save space, it's more effective + to drop the `object` column. To preserve the old behavior you can add an + `object_changes_adapter`. ### Added diff --git a/README.md b/README.md index f680d2aad..d1eae956d 100644 --- a/README.md +++ b/README.md @@ -723,10 +723,6 @@ For diffing two ActiveRecord objects: * [activerecord-diff][23]: rather like ActiveRecord::Dirty but also allows you to specify which columns to compare. -If you want to selectively record changes for some models but not others you -can opt out of recording changes by passing `save_changes: false` to your -`has_paper_trail` method declaration. - ### 3.d. Deleting Old Versions Over time your `versions` table will grow to an unwieldy size. Because each diff --git a/lib/paper_trail/events/base.rb b/lib/paper_trail/events/base.rb index 425f1cad8..2fdbef95e 100644 --- a/lib/paper_trail/events/base.rb +++ b/lib/paper_trail/events/base.rb @@ -249,8 +249,7 @@ def recordable_object_changes(changes) # # @api private def record_object_changes? - @record.paper_trail_options[:save_changes] && - @record.class.paper_trail.version_class.column_names.include?("object_changes") + @record.class.paper_trail.version_class.column_names.include?("object_changes") end # Returns a boolean indicating whether to store the original object during save. diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 758c329f8..fb7804513 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -51,8 +51,6 @@ module ClassMethods # is `:versions`. # - :version - The name to use for the method which returns the version # the instance was reified from. Default is `:version`. - # - :save_changes - Whether or not to save changes to the object_changes - # column if it exists. Default is true # - :join_tables - If the model has a has_and_belongs_to_many relation # with an unpapertrailed model, passing the name of the association to # the join_tables option will paper trail the join table but not save diff --git a/lib/paper_trail/model_config.rb b/lib/paper_trail/model_config.rb index 2b746f615..c043fae48 100644 --- a/lib/paper_trail/model_config.rb +++ b/lib/paper_trail/model_config.rb @@ -231,9 +231,6 @@ def setup_options(options) end @model_class.paper_trail_options[:meta] ||= {} - if @model_class.paper_trail_options[:save_changes].nil? - @model_class.paper_trail_options[:save_changes] = true - end end end end diff --git a/spec/dummy_app/app/models/thing.rb b/spec/dummy_app/app/models/thing.rb index 2d2c5e98d..2d1a8dd91 100644 --- a/spec/dummy_app/app/models/thing.rb +++ b/spec/dummy_app/app/models/thing.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Thing < ActiveRecord::Base - has_paper_trail save_changes: false + has_paper_trail if ActiveRecord.gem_version >= Gem::Version.new("5.0") belongs_to :person, optional: true diff --git a/spec/models/thing_spec.rb b/spec/models/thing_spec.rb deleted file mode 100644 index bfad5e2ef..000000000 --- a/spec/models/thing_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -RSpec.describe Thing, type: :model do - it { is_expected.to be_versioned } - - describe "does not store object_changes", versioning: true do - let(:thing) { Thing.create(name: "pencil") } - - it { expect(thing.versions.last.object_changes).to be_nil } - end -end