From 5a03a1b7bb6f68bd0f510c12d298024a0c3fb05a Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 12 Jul 2015 22:27:58 -0400 Subject: [PATCH 1/9] Docs: Move console whodunnit example to wiki The readme is quite long already, and this example will not be useful to most people. Also, this example recommends an initializer, a technique that we no longer recommend. [ci skip] --- README.md | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 95bd6b818..5eea9a4ae 100644 --- a/README.md +++ b/README.md @@ -554,21 +554,7 @@ widget.update_attributes :name => 'Wibble' widget.versions.last.whodunnit # Andy Stewart ``` -You can avoid having to do this manually by setting your initializer to pick up -the username of the current user from the OS, like this: - -```ruby -# config/initializers/paper_trail.rb - -# the following line is required for PaperTrail >= 4.0.0 with Rails -PaperTrail::Rails::Engine.eager_load! - -if defined?(::Rails::Console) - PaperTrail.whodunnit = "#{`whoami`.strip}: console" -elsif File.basename($0) == "rake" - PaperTrail.whodunnit = "#{`whoami`.strip}: rake #{ARGV.join ' '}" -end -``` +See also: [Setting whodunnit in the rails console][33] Sometimes you want to define who is responsible for a change in a small scope without overwriting value of `PaperTrail.whodunnit`. It is possible to define @@ -1456,3 +1442,4 @@ Released under the MIT licence. [30]: https://github.com/burke/zeus [31]: https://github.com/rails/spring [32]: http://api.rubyonrails.org/classes/ActiveRecord/AutosaveAssociation.html#method-i-mark_for_destruction +[33]: https://github.com/airblade/paper_trail/wiki/Setting-whodunnit-in-the-rails-console From 71453f3b1f2d82f0bcc2e063c7c92bcd0d3e4d2d Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 12 Jul 2015 22:31:59 -0400 Subject: [PATCH 2/9] Docs: Rails initializer is no longer recommended [ci skip] --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c523a85c..c046aea1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,10 @@ ### Changes -- If you use a Rails initializer for PaperTrail add - `PaperTrail::Rails::Engine.eager_load!` to the beginning of it. - See the readme for an example. +- Using a Rails initializer to reopen PaperTrail::Version or otherwise extend + PaperTrail is no longer recommended. An alternative is described in the + readme. See https://github.com/airblade/paper_trail/pull/557 and + https://github.com/airblade/paper_trail/pull/492. ### Enhancements From 36d5b447120d9f3b2522ad50ea457d43c92f73fb Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 12 Jul 2015 22:39:04 -0400 Subject: [PATCH 3/9] Docs: Classify as change, not enhancement [ci skip] --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c046aea1f..0497b610d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,11 @@ PaperTrail is no longer recommended. An alternative is described in the readme. See https://github.com/airblade/paper_trail/pull/557 and https://github.com/airblade/paper_trail/pull/492. +- If you depend on the `RSpec` or `Cucumber` helpers, you must + [require them in your test helper](https://github.com/airblade/paper_trail#testing). ### Enhancements -If you depend on the `RSpec` or `Cucumber` helpers, you will need to [manually load them into your test helper](https://github.com/airblade/paper_trail#testing). - - [#563](https://github.com/airblade/paper_trail/pull/563) - Fixed a bug in `PaperTrail::Model::InstanceMethods#touch_with_version` so that it will trigger a version when the `on` option was set to `[:create]` From 234d00381d65d5ac2b52a4d06931fae9d66add88 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 12 Jul 2015 22:40:52 -0400 Subject: [PATCH 4/9] Docs: List bug fixes separately from new features [ci skip] --- CHANGELOG.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0497b610d..cf5a51645 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 4.0.0 (Unreleased) -### Changes +### Changed - Using a Rails initializer to reopen PaperTrail::Version or otherwise extend PaperTrail is no longer recommended. An alternative is described in the @@ -9,11 +9,8 @@ - If you depend on the `RSpec` or `Cucumber` helpers, you must [require them in your test helper](https://github.com/airblade/paper_trail#testing). -### Enhancements +### Added - - [#563](https://github.com/airblade/paper_trail/pull/563) - Fixed a bug in - `PaperTrail::Model::InstanceMethods#touch_with_version` so that it will trigger a version when the `on` option - was set to `[:create]` - [#541](https://github.com/airblade/paper_trail/pull/541) - `PaperTrail.config.enabled` should be Thread Safe - [#525](https://github.com/airblade/paper_trail/issues/525) / [#512](https://github.com/airblade/paper_trail/pull/512) - Support for virtual accessors and redefined setter and getter methods. @@ -73,6 +70,12 @@ - [#248](https://github.com/airblade/paper_trail/issues/248) - The migrations created by the generator now use `longtext` instead of `text` in MySQL. +### Fixed + + - [#563](https://github.com/airblade/paper_trail/pull/563) - Fixed a bug in + `touch_with_version` so that it will still create a version even when the + `on` option is, e.g. `[:create]`. + ## 3.0.8 - [#525](https://github.com/airblade/paper_trail/issues/525) / [#512](https://github.com/airblade/paper_trail/pull/512) - From 4ed899a20d2c91bcdd86ed370e05443ab41a989c Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 12 Jul 2015 22:48:30 -0400 Subject: [PATCH 5/9] Docs: Classify issue 248 as fixed, not added Given that this fixes an uncommon error, and will have little impact on new or existing apps, I prefer to classify this as a bug fix. [ci skip] --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf5a51645..7cc89194d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,14 +67,14 @@ to `PaperTrail::Serializers::YAML`. - Both `PaperTrail.config` and `PaperTrail.configure` are now identical, and will both return the `PaperTrail::Config` instance and also yield it if a block is provided. - - [#248](https://github.com/airblade/paper_trail/issues/248) - The migrations - created by the generator now use `longtext` instead of `text` in MySQL. ### Fixed - [#563](https://github.com/airblade/paper_trail/pull/563) - Fixed a bug in `touch_with_version` so that it will still create a version even when the `on` option is, e.g. `[:create]`. + - [#248](https://github.com/airblade/paper_trail/issues/248) - In MySQL, to + prevent truncation, generated migrations now use `longtext` instead of `text`. ## 3.0.8 From c60e12484c85145d3a706110efb6aa89ddaaccb2 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 12 Jul 2015 22:57:20 -0400 Subject: [PATCH 6/9] Docs: Break long lines [ci skip] --- CHANGELOG.md | 137 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 85 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cc89194d..d58532679 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,62 +11,95 @@ ### Added - - [#541](https://github.com/airblade/paper_trail/pull/541) - `PaperTrail.config.enabled` should be Thread Safe - - [#525](https://github.com/airblade/paper_trail/issues/525) / [#512](https://github.com/airblade/paper_trail/pull/512) - + - [#541](https://github.com/airblade/paper_trail/pull/541) - + `PaperTrail.config.enabled` should be Thread Safe + - [#525](https://github.com/airblade/paper_trail/issues/525) / + [#512](https://github.com/airblade/paper_trail/pull/512) - Support for virtual accessors and redefined setter and getter methods. - - [#518](https://github.com/airblade/paper_trail/pull/518) - Support for querying against PostgreSQL's - [`JSON` and `JSONB` column types](http://www.postgresql.org/docs/9.4/static/datatype-json.html) via - `PaperTrail::VersionConcern#where_object` and `PaperTrail::VersionConcern#where_object_changes` - - [#507](https://github.com/airblade/paper_trail/pull/507) - Support for opting out of saving changesets on models by choice - when the `object_changes` column exists on the default `versions` table. - - [#500](https://github.com/airblade/paper_trail/pull/500) - Support for passing `on: []` as an argument, with only manual - versioning via calls to `touch_with_version` - - [#494](https://github.com/airblade/paper_trail/issues/494) - The install generator will warn the user if the migration they are - attempting to generate already exists. + - [#518](https://github.com/airblade/paper_trail/pull/518) - Support for + querying against PostgreSQL's + [`JSON` and `JSONB` column types](http://www.postgresql.org/docs/9.4/static/datatype-json.html) + via `PaperTrail::VersionConcern#where_object` and + `PaperTrail::VersionConcern#where_object_changes` + - [#507](https://github.com/airblade/paper_trail/pull/507) - Support for + opting out of saving changesets on models by choice when the + `object_changes` column exists on the default `versions` table. + - [#500](https://github.com/airblade/paper_trail/pull/500) - Support for + passing `on: []` as an argument, with only manual versioning via calls to + `touch_with_version` + - [#494](https://github.com/airblade/paper_trail/issues/494) - The install + generator will warn the user if the migration they are attempting to + generate already exists. - [#484](https://github.com/airblade/paper_trail/pull/484) - Support for - [PostgreSQL's `JSONB` Type](http://www.postgresql.org/docs/9.4/static/datatype-json.html) for storing `object` - and `object_changes`. - - [#479](https://github.com/airblade/paper_trail/issues/479) - Deprecated `originator` method in favor of `paper_trail_originator` - Deprecation warning informs users that the `originator` of the methods will be removed in version `4.0` - - [#458](https://github.com/airblade/paper_trail/pull/458) - For `create` events, metadata pointing at attributes should attempt - to grab the current value instead of looking at the value prior to the change (which would always be `nil`) - - [#451](https://github.com/airblade/paper_trail/issues/451) - Fix `reify` method in context of model where the base class - has a default scope, and the live instance is not scoped within that default scope - - [#440](https://github.com/airblade/paper_trail/pull/440) - `versions` association should clear/reload after a transaction rollback. - - [#439](https://github.com/airblade/paper_trail/pull/439) / [#12](https://github.com/airblade/paper_trail/issues/12) - + [PostgreSQL's `JSONB` Type](http://www.postgresql.org/docs/9.4/static/datatype-json.html) + for storing `object` and `object_changes`. + - [#479](https://github.com/airblade/paper_trail/issues/479) - Deprecated + `originator` method in favor of `paper_trail_originator`. Deprecation + warning informs users that the `originator` of the methods will be removed + in version `4.0`. + - [#458](https://github.com/airblade/paper_trail/pull/458) - For `create` + events, metadata pointing at attributes should attempt to grab the current + value instead of looking at the value prior to the change (which would + always be `nil`) + - [#451](https://github.com/airblade/paper_trail/issues/451) - Fix `reify` + method in context of model where the base class has a default scope, and the + live instance is not scoped within that default scope. + - [#440](https://github.com/airblade/paper_trail/pull/440) - `versions` + association should clear/reload after a transaction rollback. + - [#439](https://github.com/airblade/paper_trail/pull/439) / + [#12](https://github.com/airblade/paper_trail/issues/12) - Support for versioning of associations (Has Many, Has One, HABTM, etc.) - - [#438](https://github.com/airblade/paper_trail/issues/438) - `ModelKlass.paper_trail_enabled_for_model?` should return `false` if + - [#438](https://github.com/airblade/paper_trail/issues/438) - + `ModelKlass.paper_trail_enabled_for_model?` should return `false` if `has_paper_trail` has not been declared on the class. - - [#404](https://github.com/airblade/paper_trail/issues/404) / [#428](https://github.com/airblade/paper_trail/issues/428) - - `model_instance.dup` does not need to be invoked when examining what the instance looked like before changes were persisted, - which avoids issues if a 3rd party has overriden the `dup` behavior. Also fixes errors occuring when a user attempts to - update the inheritance column on an STI model instance in `ActiveRecord` 4.1.x - - [#427](https://github.com/airblade/paper_trail/pull/427) - Fix `reify` method in context of model where a column has been removed. - - [#420](https://github.com/airblade/paper_trail/issues/420) - Add `VersionConcern#where_object_changes` instance method; - acts as a helper for querying against the `object_changes` column in versions table. - - [#416](https://github.com/airblade/paper_trail/issues/416) - Added a `config` option for enabling/disabling - utilization of `serialized_attributes` for `ActiveRecord`, necessary because `serialized_attributes` has been - deprecated in `ActiveRecord` version `4.2` and will be removed in version `5.0` - - [#414](https://github.com/airblade/paper_trail/issues/414) - Fix functionality `ignore` argument to `has_paper_trail` - in `ActiveRecord` 4. - - [#413](https://github.com/airblade/paper_trail/issues/413) - Utilize [RequestStore](https://github.com/steveklabnik/request_store) - to ensure that the `PaperTrail.whodunnit` is set in a thread safe manner within Rails & Sinatra. - - [#399](https://github.com/airblade/paper_trail/pull/399) - Add `:dup` argument for options hash to `reify` which forces a new model instance. - - [#394](https://github.com/airblade/paper_trail/pull/394) - Add RSpec matcher `have_a_version_with` for easier testing. - - [#391](https://github.com/airblade/paper_trail/issues/391) - `object_changes` value should dump to `YAML` as a normal `Hash` - instead of an `ActiveSupport::HashWithIndifferentAccess`. - - [#381](https://github.com/airblade/paper_trail/issues/381) - `Rspec` and `Cucumber` helpers should not be loaded by - default, regardless of whether those libraries are loaded. - - [#375](https://github.com/airblade/paper_trail/pull/375) / [#374](https://github.com/airblade/paper_trail/issues/374) / - [#354](https://github.com/airblade/paper_trail/issues/354) / [#131](https://github.com/airblade/paper_trail/issues/131) - - Versions should be built with `after_` callbacks so the timestamp field for a version can be forced to match the - corresponding timestamp in the database for the state persistence of a change to the base (versioned) model. - - [#347](https://github.com/airblade/paper_trail/pull/347) - Autoload `ActiveRecord` models in via a `Rails::Engine` when - the gem is used with `Rails`. - - Methods handling serialized attributes should fallback to the currently set Serializer instead of always falling back - to `PaperTrail::Serializers::YAML`. - - Both `PaperTrail.config` and `PaperTrail.configure` are now identical, and will both return the `PaperTrail::Config` - instance and also yield it if a block is provided. + - [#404](https://github.com/airblade/paper_trail/issues/404) / + [#428](https://github.com/airblade/paper_trail/issues/428) - + `model_instance.dup` does not need to be invoked when examining what the + instance looked like before changes were persisted, which avoids issues if a + 3rd party has overriden the `dup` behavior. Also fixes errors occuring when + a user attempts to update the inheritance column on an STI model instance in + `ActiveRecord` 4.1.x + - [#427](https://github.com/airblade/paper_trail/pull/427) - Fix `reify` + method in context of model where a column has been removed. + - [#420](https://github.com/airblade/paper_trail/issues/420) - Add + `VersionConcern#where_object_changes` instance method; acts as a helper for + querying against the `object_changes` column in versions table. + - [#416](https://github.com/airblade/paper_trail/issues/416) - Added a + `config` option for enabling/disabling utilization of + `serialized_attributes` for `ActiveRecord`, necessary because + `serialized_attributes` has been deprecated in `ActiveRecord` version `4.2` + and will be removed in version `5.0` + - [#414](https://github.com/airblade/paper_trail/issues/414) - Fix + functionality `ignore` argument to `has_paper_trail` in `ActiveRecord` 4. + - [#413](https://github.com/airblade/paper_trail/issues/413) - Utilize + [RequestStore](https://github.com/steveklabnik/request_store) to ensure that + the `PaperTrail.whodunnit` is set in a thread safe manner within Rails and + Sinatra. + - [#399](https://github.com/airblade/paper_trail/pull/399) - Add `:dup` + argument for options hash to `reify` which forces a new model instance. + - [#394](https://github.com/airblade/paper_trail/pull/394) - Add RSpec matcher + `have_a_version_with` for easier testing. + - [#391](https://github.com/airblade/paper_trail/issues/391) - `object_changes` + value should dump to `YAML` as a normal `Hash` instead of an + `ActiveSupport::HashWithIndifferentAccess`. + - [#381](https://github.com/airblade/paper_trail/issues/381) - `Rspec` + and `Cucumber` helpers should not be loaded by default, regardless of + whether those libraries are loaded. + - [#375](https://github.com/airblade/paper_trail/pull/375) / + [#374](https://github.com/airblade/paper_trail/issues/374) / + [#354](https://github.com/airblade/paper_trail/issues/354) / + [#131](https://github.com/airblade/paper_trail/issues/131) - + Versions should be built with `after_` callbacks so the timestamp field for + a version can be forced to match the corresponding timestamp in the database + for the state persistence of a change to the base (versioned) model. + - [#347](https://github.com/airblade/paper_trail/pull/347) - Autoload + `ActiveRecord` models in via a `Rails::Engine` when the gem is used with + `Rails`. + - Methods handling serialized attributes should fallback to the currently set + Serializer instead of always falling back to `PaperTrail::Serializers::YAML`. + - Both `PaperTrail.config` and `PaperTrail.configure` are now identical, and + will both return the `PaperTrail::Config` instance and also yield it if a + block is provided. ### Fixed From c0348a76f31e2ada9468840adde33cae8c9d67a5 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 12 Jul 2015 23:07:14 -0400 Subject: [PATCH 7/9] Fix incorrect deprecation message We just deprecated this method in 4.0, right? So, we can't also remove it in 4.0, or any 4.x for that matter. We either deprecate or remove, and I don't care which, but we can't do both in the same major version. :) [ci skip] --- CHANGELOG.md | 4 +--- lib/paper_trail/has_paper_trail.rb | 2 +- lib/paper_trail/version_concern.rb | 2 +- spec/models/version_spec.rb | 3 +-- spec/models/widget_spec.rb | 3 +-- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d58532679..fecd928a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,9 +34,7 @@ [PostgreSQL's `JSONB` Type](http://www.postgresql.org/docs/9.4/static/datatype-json.html) for storing `object` and `object_changes`. - [#479](https://github.com/airblade/paper_trail/issues/479) - Deprecated - `originator` method in favor of `paper_trail_originator`. Deprecation - warning informs users that the `originator` of the methods will be removed - in version `4.0`. + `originator` method, use `paper_trail_originator`. - [#458](https://github.com/airblade/paper_trail/pull/458) - For `create` events, metadata pointing at attributes should attempt to grab the current value instead of looking at the value prior to the change (which would diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index a74b1a90d..2b3f6baf5 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -192,7 +192,7 @@ def paper_trail_originator end def originator - warn "DEPRECATED: use `paper_trail_originator` instead of `originator`. Support for `originator` will be removed in PaperTrail 4.0" + warn "DEPRECATED: use paper_trail_originator instead of originator." self.paper_trail_originator end diff --git a/lib/paper_trail/version_concern.rb b/lib/paper_trail/version_concern.rb index a0e38151c..57ea4021a 100644 --- a/lib/paper_trail/version_concern.rb +++ b/lib/paper_trail/version_concern.rb @@ -257,7 +257,7 @@ def paper_trail_originator end def originator - warn "DEPRECATED: use `paper_trail_originator` instead of `originator`. Support for `originator` will be removed in PaperTrail 4.0" + warn "DEPRECATED: use paper_trail_originator instead of originator." self.paper_trail_originator end diff --git a/spec/models/version_spec.rb b/spec/models/version_spec.rb index be9488dd9..702abfae0 100644 --- a/spec/models/version_spec.rb +++ b/spec/models/version_spec.rb @@ -76,8 +76,7 @@ describe "#originator" do it { is_expected.to respond_to(:originator) } let(:warning_msg) do - "DEPRECATED: use `paper_trail_originator` instead of `originator`." + - " Support for `originator` will be removed in PaperTrail 4.0" + "DEPRECATED: use paper_trail_originator instead of originator." end it 'should set the invoke `paper_trail_originator`' do diff --git a/spec/models/widget_spec.rb b/spec/models/widget_spec.rb index c0226301d..afde7d463 100644 --- a/spec/models/widget_spec.rb +++ b/spec/models/widget_spec.rb @@ -178,8 +178,7 @@ it { is_expected.to respond_to(:originator) } let(:warning_msg) do - "DEPRECATED: use `paper_trail_originator` instead of `originator`." + - " Support for `originator` will be removed in PaperTrail 4.0" + "DEPRECATED: use paper_trail_originator instead of originator." end it 'should set the invoke `paper_trail_originator`' do From 748226b9a539664dd9ee1e1c019f57fb2c1dfba7 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sun, 12 Jul 2015 23:43:25 -0400 Subject: [PATCH 8/9] Use ActiveSupport::Deprecation.warn, not Kernel#warn - Provides helpful stack trace - Can be silenced - We already have a dependency on activesupport - Available in all versions of rails we support: 3 - 5 --- lib/paper_trail/config.rb | 10 ++++++---- lib/paper_trail/has_paper_trail.rb | 2 +- lib/paper_trail/version_concern.rb | 2 +- spec/models/version_spec.rb | 8 +++----- spec/models/widget_spec.rb | 8 +++----- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/paper_trail/config.rb b/lib/paper_trail/config.rb index acfc0225e..7d1e869c4 100644 --- a/lib/paper_trail/config.rb +++ b/lib/paper_trail/config.rb @@ -22,9 +22,11 @@ def initialize def serialized_attributes=(value) if ::ActiveRecord::VERSION::MAJOR >= 5 - warn("DEPRECATED: ActiveRecord 5.0 deprecated `serialized_attributes` " + + ::ActiveSupport::Deprecation.warn( + "ActiveRecord 5.0 deprecated `serialized_attributes` " + "without replacement, so this PaperTrail config setting does " + - "nothing with this version, and is always turned off") + "nothing with this version, and is always turned off" + ) end @serialized_attributes = value end @@ -33,12 +35,12 @@ def track_associations @track_associations ||= PaperTrail::VersionAssociation.table_exists? end alias_method :track_associations?, :track_associations - + # Indicates whether PaperTrail is on or off. def enabled PaperTrail.paper_trail_store[:paper_trail_enabled].nil? || PaperTrail.paper_trail_store[:paper_trail_enabled] end - + def enabled= enable PaperTrail.paper_trail_store[:paper_trail_enabled] = enable end diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 2b3f6baf5..b62017136 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -192,7 +192,7 @@ def paper_trail_originator end def originator - warn "DEPRECATED: use paper_trail_originator instead of originator." + ActiveSupport::Deprecation.warn "Use paper_trail_originator instead of originator." self.paper_trail_originator end diff --git a/lib/paper_trail/version_concern.rb b/lib/paper_trail/version_concern.rb index 57ea4021a..2e99d1e81 100644 --- a/lib/paper_trail/version_concern.rb +++ b/lib/paper_trail/version_concern.rb @@ -257,7 +257,7 @@ def paper_trail_originator end def originator - warn "DEPRECATED: use paper_trail_originator instead of originator." + ActiveSupport::Deprecation.warn "Use paper_trail_originator instead of originator." self.paper_trail_originator end diff --git a/spec/models/version_spec.rb b/spec/models/version_spec.rb index 702abfae0..557a489bf 100644 --- a/spec/models/version_spec.rb +++ b/spec/models/version_spec.rb @@ -75,18 +75,16 @@ describe "#originator" do it { is_expected.to respond_to(:originator) } - let(:warning_msg) do - "DEPRECATED: use paper_trail_originator instead of originator." - end it 'should set the invoke `paper_trail_originator`' do - is_expected.to receive(:warn) + allow(ActiveSupport::Deprecation).to receive(:warn) is_expected.to receive(:paper_trail_originator) subject.originator end it 'should display a deprecation warning' do - is_expected.to receive(:warn).with(warning_msg) + expect(ActiveSupport::Deprecation).to receive(:warn). + with(/Use paper_trail_originator instead of originator/) subject.originator end end diff --git a/spec/models/widget_spec.rb b/spec/models/widget_spec.rb index afde7d463..73319a03e 100644 --- a/spec/models/widget_spec.rb +++ b/spec/models/widget_spec.rb @@ -177,18 +177,16 @@ subject { widget } it { is_expected.to respond_to(:originator) } - let(:warning_msg) do - "DEPRECATED: use paper_trail_originator instead of originator." - end it 'should set the invoke `paper_trail_originator`' do - is_expected.to receive(:warn) + allow(ActiveSupport::Deprecation).to receive(:warn) is_expected.to receive(:paper_trail_originator) subject.originator end it 'should display a deprecation warning' do - is_expected.to receive(:warn).with(warning_msg) + expect(ActiveSupport::Deprecation).to receive(:warn). + with(/Use paper_trail_originator instead of originator/) subject.originator end end From c9406c016e2f5e2ccf6991e33be85e70a0c9ecd7 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Mon, 13 Jul 2015 13:36:34 -0400 Subject: [PATCH 9/9] Fully-qualify ::ActiveSupport::Deprecation constant > .. just in case we later add an ActiveSupport module within the gem. > https://github.com/airblade/paper_trail/pull/567/files#r34470343 --- lib/paper_trail/has_paper_trail.rb | 2 +- lib/paper_trail/version_concern.rb | 2 +- spec/models/widget_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index b62017136..411f87518 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -192,7 +192,7 @@ def paper_trail_originator end def originator - ActiveSupport::Deprecation.warn "Use paper_trail_originator instead of originator." + ::ActiveSupport::Deprecation.warn "Use paper_trail_originator instead of originator." self.paper_trail_originator end diff --git a/lib/paper_trail/version_concern.rb b/lib/paper_trail/version_concern.rb index 2e99d1e81..3582e1701 100644 --- a/lib/paper_trail/version_concern.rb +++ b/lib/paper_trail/version_concern.rb @@ -257,7 +257,7 @@ def paper_trail_originator end def originator - ActiveSupport::Deprecation.warn "Use paper_trail_originator instead of originator." + ::ActiveSupport::Deprecation.warn "Use paper_trail_originator instead of originator." self.paper_trail_originator end diff --git a/spec/models/widget_spec.rb b/spec/models/widget_spec.rb index 73319a03e..71aec4125 100644 --- a/spec/models/widget_spec.rb +++ b/spec/models/widget_spec.rb @@ -179,13 +179,13 @@ it { is_expected.to respond_to(:originator) } it 'should set the invoke `paper_trail_originator`' do - allow(ActiveSupport::Deprecation).to receive(:warn) + allow(::ActiveSupport::Deprecation).to receive(:warn) is_expected.to receive(:paper_trail_originator) subject.originator end it 'should display a deprecation warning' do - expect(ActiveSupport::Deprecation).to receive(:warn). + expect(::ActiveSupport::Deprecation).to receive(:warn). with(/Use paper_trail_originator instead of originator/) subject.originator end