Merge pull request #1217 from paper-trail-gem/release-10.3.1
Release 10.3.1
This commit is contained in:
commit
ab0846a0f0
|
@ -88,22 +88,30 @@ markdown-toc -i --maxdepth 3 --bullets='-' README.md
|
||||||
|
|
||||||
## Releases
|
## Releases
|
||||||
|
|
||||||
1. Checkout the appropriate stable branch, eg. `10-stable`
|
1. Prepare the appropriate "stable" branch for release, eg. `10-stable`
|
||||||
1. Checkout a new branch, eg. `release-10.0.0`
|
1. git checkout 10-stable
|
||||||
1. Set the version in `lib/paper_trail/version_number.rb`
|
1. Checkout a new branch, eg. `release-10.3.0`
|
||||||
1. In the changelog,
|
1. Merge the relevant changes from `master`. This could be a plain merge, or
|
||||||
- Replace "Unreleased" with the date in ISO-8601 format
|
it could be cherry-picking. The later is more common in backports.
|
||||||
- Add a new "Unreleased" section
|
1. Set the version in `lib/paper_trail/version_number.rb`
|
||||||
1. In the readme, update references to version number, including
|
1. In the changelog,
|
||||||
- documentation links table
|
- Replace "Unreleased" with the date in ISO-8601 format
|
||||||
- compatability table, if necessary
|
- Add a new "Unreleased" section
|
||||||
1. git commit -am 'Release 10.0.0'
|
1. In the readme, update references to version number, including
|
||||||
1. git push origin release-10.0.0
|
- documentation links table
|
||||||
1. Pull request into `10-stable`
|
- compatability table, if necessary
|
||||||
1. git checkout 10-stable && git pull
|
1. git commit -am 'Release 10.3.0'
|
||||||
1. gem build paper_trail.gemspec
|
1. git push origin release-10.3.0
|
||||||
1. gem push paper_trail-10.0.0.gem
|
1. Pull request into `10-stable`, CI pass, merge PR
|
||||||
1. git tag -a -m "v10.0.0" "v10.0.0" # or whatever number
|
1. Release
|
||||||
1. git push --tags origin
|
1. git checkout 10-stable && git pull
|
||||||
|
1. gem build paper_trail.gemspec
|
||||||
|
1. gem push paper_trail-10.3.0.gem
|
||||||
|
1. git tag -a -m "v10.3.0" "v10.3.0" # or whatever number
|
||||||
|
1. git push --tags origin
|
||||||
|
1. Cleanup
|
||||||
|
1. git checkout master
|
||||||
|
1. cherry-pick the "Release 10.3.0" commit from the `10-stable` branch
|
||||||
|
1. git push origin master
|
||||||
|
|
||||||
[1]: https://github.com/paper-trail-gem/paper_trail/blob/master/.github/ISSUE_TEMPLATE/bug_report.md
|
[1]: https://github.com/paper-trail-gem/paper_trail/blob/master/.github/ISSUE_TEMPLATE/bug_report.md
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require:
|
require:
|
||||||
|
- rubocop-performance
|
||||||
- rubocop-rspec
|
- rubocop-rspec
|
||||||
|
|
||||||
inherit_from: .rubocop_todo.yml
|
inherit_from: .rubocop_todo.yml
|
||||||
|
|
|
@ -3,11 +3,14 @@ require: rubocop-rspec
|
||||||
# Remove these configuration records
|
# Remove these configuration records
|
||||||
# one by one as the offenses are removed from the code base.
|
# one by one as the offenses are removed from the code base.
|
||||||
|
|
||||||
|
Layout/AlignArguments:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Max: 21 # Goal: 15
|
Max: 20 # Goal: 15
|
||||||
|
|
||||||
Metrics/CyclomaticComplexity:
|
Metrics/CyclomaticComplexity:
|
||||||
Max: 8 # Goal: 6
|
Max: 7 # Goal: 6
|
||||||
|
|
||||||
Metrics/PerceivedComplexity:
|
Metrics/PerceivedComplexity:
|
||||||
Max: 9 # Goal: 7
|
Max: 9 # Goal: 7
|
||||||
|
@ -18,6 +21,18 @@ Naming/MemoizedInstanceVariableName:
|
||||||
RSpec/ContextWording:
|
RSpec/ContextWording:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
RSpec/HooksBeforeExamples:
|
||||||
|
Exclude:
|
||||||
|
- spec/controllers/articles_controller_spec.rb
|
||||||
|
- spec/models/version_spec.rb
|
||||||
|
- spec/paper_trail/config_spec.rb
|
||||||
|
- spec/paper_trail/request_spec.rb
|
||||||
|
- spec/paper_trail_spec.rb
|
||||||
|
|
||||||
|
RSpec/ImplicitSubject:
|
||||||
|
Exclude:
|
||||||
|
- spec/paper_trail/events/base_spec.rb
|
||||||
|
|
||||||
RSpec/InstanceVariable:
|
RSpec/InstanceVariable:
|
||||||
Exclude:
|
Exclude:
|
||||||
- spec/paper_trail/associations/belongs_to_spec.rb
|
- spec/paper_trail/associations/belongs_to_spec.rb
|
||||||
|
|
|
@ -34,6 +34,10 @@ gemfile:
|
||||||
- gemfiles/ar_5.2.gemfile
|
- gemfiles/ar_5.2.gemfile
|
||||||
- gemfiles/ar_6.0.gemfile
|
- gemfiles/ar_6.0.gemfile
|
||||||
matrix:
|
matrix:
|
||||||
|
allow_failures:
|
||||||
|
# We haven't changed anything, but mysql builds no longer work on TravisCI.
|
||||||
|
# Allow failures temporarily until we have time to troubleshoot this.
|
||||||
|
- env: DB=mysql
|
||||||
exclude:
|
exclude:
|
||||||
# rails 6 requires ruby >= 2.5.0
|
# rails 6 requires ruby >= 2.5.0
|
||||||
- rvm: 2.3.8
|
- rvm: 2.3.8
|
||||||
|
|
17
Appraisals
17
Appraisals
|
@ -10,7 +10,8 @@
|
||||||
# > https://github.com/thoughtbot/appraisal
|
# > https://github.com/thoughtbot/appraisal
|
||||||
|
|
||||||
appraise "ar-4.2" do
|
appraise "ar-4.2" do
|
||||||
gem "activerecord", [">= 4.2.11.1", "< 4.3"] # CVE-2019-5420
|
# >= 4.2.11.1 because CVE-2019-5420
|
||||||
|
gem "activerecord", [">= 4.2.11.1", "< 4.3"]
|
||||||
gem "database_cleaner", "~> 1.6"
|
gem "database_cleaner", "~> 1.6"
|
||||||
|
|
||||||
# not compatible with mysql2 0.5
|
# not compatible with mysql2 0.5
|
||||||
|
@ -22,16 +23,24 @@ appraise "ar-4.2" do
|
||||||
end
|
end
|
||||||
|
|
||||||
appraise "ar-5.1" do
|
appraise "ar-5.1" do
|
||||||
gem "activerecord", [">= 5.1.6.2", "< 5.2"] # CVE-2019-5420
|
# >= 5.1.6.2 because CVE-2019-5420
|
||||||
|
gem "activerecord", [">= 5.1.6.2", "< 5.2"]
|
||||||
gem "rails-controller-testing", "~> 1.0.2"
|
gem "rails-controller-testing", "~> 1.0.2"
|
||||||
end
|
end
|
||||||
|
|
||||||
appraise "ar-5.2" do
|
appraise "ar-5.2" do
|
||||||
gem "activerecord", [">= 5.2.2.1", "< 5.3"] # CVE-2019-5420
|
# >= 5.2.2.1 because CVE-2019-5420
|
||||||
|
gem "activerecord", [">= 5.2.2.1", "< 5.3"]
|
||||||
gem "rails-controller-testing", "~> 1.0.2"
|
gem "rails-controller-testing", "~> 1.0.2"
|
||||||
end
|
end
|
||||||
|
|
||||||
appraise "ar-6.0" do
|
appraise "ar-6.0" do
|
||||||
gem "activerecord", [">= 6.0.0.beta3", "< 6.1"] # CVE-2019-5420
|
# >= 6.0.0.beta3 because CVE-2019-5420
|
||||||
|
# < rc2 because there seem to have been breaking changes between rc1 and rc2
|
||||||
|
# re: MigrationContext
|
||||||
|
gem "activerecord", [">= 6.0.0.beta3", "< 6.0.0.rc2"]
|
||||||
gem "rails-controller-testing", "~> 1.0.3"
|
gem "rails-controller-testing", "~> 1.0.3"
|
||||||
|
|
||||||
|
# Must match `gem` call in active_record/connection_adapters/sqlite3_adapter.rb
|
||||||
|
gem "sqlite3", "~> 1.4"
|
||||||
end
|
end
|
||||||
|
|
34
CHANGELOG.md
34
CHANGELOG.md
|
@ -17,6 +17,26 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
||||||
|
|
||||||
- None
|
- None
|
||||||
|
|
||||||
|
## 10.3.1 (2019-07-31)
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
- None
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- None
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- None
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
- [#1213](https://github.com/paper-trail-gem/paper_trail/pull/1213) - Allow
|
||||||
|
contributors to install incompatible versions of ActiveRecord.
|
||||||
|
See discussion in paper_trail/compatibility.rb
|
||||||
|
|
||||||
## 10.3.0 (2019-04-09)
|
## 10.3.0 (2019-04-09)
|
||||||
|
|
||||||
### Breaking Changes
|
### Breaking Changes
|
||||||
|
@ -47,20 +67,6 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- None
|
|
||||||
|
|
||||||
## 10.2.1 (2019-03-14)
|
|
||||||
|
|
||||||
### Breaking Changes
|
|
||||||
|
|
||||||
- None
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- None
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- [#1184](https://github.com/paper-trail-gem/paper_trail/pull/1184) -
|
- [#1184](https://github.com/paper-trail-gem/paper_trail/pull/1184) -
|
||||||
No need to calculate previous values of skipped attributes
|
No need to calculate previous values of skipped attributes
|
||||||
- [#1188](https://github.com/paper-trail-gem/paper_trail/pull/1188) -
|
- [#1188](https://github.com/paper-trail-gem/paper_trail/pull/1188) -
|
||||||
|
|
55
README.md
55
README.md
|
@ -16,7 +16,7 @@ are welcome.
|
||||||
| Version | Documentation |
|
| Version | Documentation |
|
||||||
| -------------- | ------------- |
|
| -------------- | ------------- |
|
||||||
| Unreleased | https://github.com/paper-trail-gem/paper_trail/blob/master/README.md |
|
| Unreleased | https://github.com/paper-trail-gem/paper_trail/blob/master/README.md |
|
||||||
| 10.3.0 | https://github.com/paper-trail-gem/paper_trail/blob/v10.3.0/README.md |
|
| 10.3.1 | https://github.com/paper-trail-gem/paper_trail/blob/v10.3.1/README.md |
|
||||||
| 9.2.0 | https://github.com/paper-trail-gem/paper_trail/blob/v9.2.0/README.md |
|
| 9.2.0 | https://github.com/paper-trail-gem/paper_trail/blob/v9.2.0/README.md |
|
||||||
| 8.1.2 | https://github.com/paper-trail-gem/paper_trail/blob/v8.1.2/README.md |
|
| 8.1.2 | https://github.com/paper-trail-gem/paper_trail/blob/v8.1.2/README.md |
|
||||||
| 7.1.3 | https://github.com/paper-trail-gem/paper_trail/blob/v7.1.3/README.md |
|
| 7.1.3 | https://github.com/paper-trail-gem/paper_trail/blob/v7.1.3/README.md |
|
||||||
|
@ -97,6 +97,9 @@ are welcome.
|
||||||
| 2 | 2.7-stable | >= 1.8.7 | >= 3.0, < 4 |
|
| 2 | 2.7-stable | >= 1.8.7 | >= 3.0, < 4 |
|
||||||
| 1 | rails2 | >= 1.8.7 | >= 2.3, < 3 |
|
| 1 | rails2 | >= 1.8.7 | >= 2.3, < 3 |
|
||||||
|
|
||||||
|
Experts: to install incompatible versions of activerecord, see
|
||||||
|
`paper_trail/compatibility.rb`.
|
||||||
|
|
||||||
### 1.b. Installation
|
### 1.b. Installation
|
||||||
|
|
||||||
1. Add PaperTrail to your `Gemfile`.
|
1. Add PaperTrail to your `Gemfile`.
|
||||||
|
@ -115,6 +118,10 @@ are welcome.
|
||||||
If using [rails_admin][38], you must enable the
|
If using [rails_admin][38], you must enable the
|
||||||
experimental [Associations](#4b-associations) feature.
|
experimental [Associations](#4b-associations) feature.
|
||||||
|
|
||||||
|
If you're getting "Could not find generator 'paper_trail:install'" errors from
|
||||||
|
recent Ruby/Rails versions, try running `spring stop`
|
||||||
|
(see [this thread](https://github.com/paper-trail-gem/paper_trail/issues/459) for more details).
|
||||||
|
|
||||||
```
|
```
|
||||||
bundle exec rake db:migrate
|
bundle exec rake db:migrate
|
||||||
```
|
```
|
||||||
|
@ -1212,14 +1219,25 @@ loop over every record and parse it in Ruby, then write to a temporary column:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
add_column :versions, :new_object, :jsonb # or :json
|
add_column :versions, :new_object, :jsonb # or :json
|
||||||
|
# add_column :versions, :new_object_changes, :jsonb # or :json
|
||||||
|
|
||||||
PaperTrail::Version.reset_column_information
|
# PaperTrail::Version.reset_column_information # needed for rails < 6
|
||||||
PaperTrail::Version.find_each do |version|
|
|
||||||
version.update_column :new_object, YAML.load(version.object) if version.object
|
PaperTrail::Version.where.not(object: nil).find_each do |version|
|
||||||
|
version.update_column(:new_object, YAML.load(version.object))
|
||||||
|
|
||||||
|
# if version.object_changes
|
||||||
|
# version.update_column(
|
||||||
|
# :new_object_changes,
|
||||||
|
# YAML.load(version.object_changes)
|
||||||
|
# )
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_column :versions, :object
|
remove_column :versions, :object
|
||||||
|
# remove_column :versions, :object_changes
|
||||||
rename_column :versions, :new_object, :object
|
rename_column :versions, :new_object, :object
|
||||||
|
# rename_column :versions, :new_object_changes, :object_changes
|
||||||
```
|
```
|
||||||
|
|
||||||
This technique can be very slow if you have a lot of data. Though slow, it is
|
This technique can be very slow if you have a lot of data. Though slow, it is
|
||||||
|
@ -1286,22 +1304,35 @@ end
|
||||||
|
|
||||||
### 6.c. Custom Object Changes
|
### 6.c. Custom Object Changes
|
||||||
|
|
||||||
By default, PaperTrail stores object changes in a before/after array of objects
|
To fully control the contents of their `object_changes` column, expert users
|
||||||
containing keys of columns that have changed in that particular version. You can
|
can write an adapter.
|
||||||
override this behaviour by using the object_changes_adapter config option:
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
PaperTrail.config.object_changes_adapter = MyObjectChangesAdapter.new
|
PaperTrail.config.object_changes_adapter = MyObjectChangesAdapter.new
|
||||||
|
|
||||||
|
class MyObjectChangesAdapter
|
||||||
|
# @param changes Hash
|
||||||
|
# @return Hash
|
||||||
|
def diff(changes)
|
||||||
|
# ...
|
||||||
|
end
|
||||||
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
A valid adapter is a class that contains the following methods:
|
You should only use this feature if you are comfortable reading PT's source to
|
||||||
|
see exactly how the adapter is used. For example, see how `diff` is used by
|
||||||
|
reading `::PaperTrail::Events::Base#recordable_object_changes`.
|
||||||
|
|
||||||
|
An adapter can implement any or all of the following methods:
|
||||||
|
|
||||||
1. diff: Returns the changeset in the desired format given the changeset in the original format
|
1. diff: Returns the changeset in the desired format given the changeset in the original format
|
||||||
2. load_changeset: Returns the changeset for a given version object
|
2. load_changeset: Returns the changeset for a given version object
|
||||||
3. where_object_changes: Returns the records resulting from the given hash of attributes.
|
3. where_object_changes: Returns the records resulting from the given hash of attributes.
|
||||||
|
|
||||||
To preserve the default behavior for some of these, don't define them in your adapter.
|
Depending on what your adapter does, you may have to implement all three.
|
||||||
|
|
||||||
For an example of such an implementation, see [paper_trail-hashdiff](https://github.com/hashwin/paper_trail-hashdiff)
|
For an example of a complete and useful adapter, see
|
||||||
|
[paper_trail-hashdiff](https://github.com/hashwin/paper_trail-hashdiff)
|
||||||
|
|
||||||
### 6.d. Excluding the Object Column
|
### 6.d. Excluding the Object Column
|
||||||
|
|
||||||
|
@ -1588,8 +1619,8 @@ See our [contribution guidelines][43]
|
||||||
|
|
||||||
## Inspirations
|
## Inspirations
|
||||||
|
|
||||||
* [Simply Versioned](http://github.com/github/simply_versioned)
|
* [Simply Versioned](https://github.com/jerome/simply_versioned)
|
||||||
* [Acts As Audited](http://github.com/collectiveidea/acts_as_audited)
|
* [Acts As Audited](https://github.com/collectiveidea/audited)
|
||||||
|
|
||||||
## Intellectual Property
|
## Intellectual Property
|
||||||
|
|
||||||
|
|
|
@ -12,3 +12,5 @@ this problem.
|
||||||
|
|
||||||
Unfortunately, GitHub does not seem to offer a way of disabling the *creation*
|
Unfortunately, GitHub does not seem to offer a way of disabling the *creation*
|
||||||
of new issues without also hiding existing issues.
|
of new issues without also hiding existing issues.
|
||||||
|
|
||||||
|
You can go to [Stack Overflow](https://stackoverflow.com/questions/tagged/paper-trail-gem) and/or [use google cache to view some issues](https://www.google.com/?q=papertrail+gem+issues+site%3Agithub.com).
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
source "https://rubygems.org"
|
source "https://rubygems.org"
|
||||||
|
|
||||||
gem "activerecord", [">= 6.0.0.beta3", "< 6.1"]
|
gem "activerecord", [">= 6.0.0.beta3", "< 6.0.0.rc2"]
|
||||||
gem "rails-controller-testing", "~> 1.0.3"
|
gem "rails-controller-testing", "~> 1.0.3"
|
||||||
|
gem "sqlite3", "~> 1.4"
|
||||||
|
|
||||||
gemspec path: "../"
|
gemspec path: "../"
|
||||||
|
|
|
@ -1,99 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require "rails/generators"
|
|
||||||
require "rails/generators/active_record"
|
|
||||||
|
|
||||||
module PaperTrail
|
|
||||||
# Installs PaperTrail in a rails app.
|
|
||||||
class InstallGenerator < ::Rails::Generators::Base
|
|
||||||
include ::Rails::Generators::Migration
|
|
||||||
|
|
||||||
# Class names of MySQL adapters.
|
|
||||||
# - `MysqlAdapter` - Used by gems: `mysql`, `activerecord-jdbcmysql-adapter`.
|
|
||||||
# - `Mysql2Adapter` - Used by `mysql2` gem.
|
|
||||||
MYSQL_ADAPTERS = [
|
|
||||||
"ActiveRecord::ConnectionAdapters::MysqlAdapter",
|
|
||||||
"ActiveRecord::ConnectionAdapters::Mysql2Adapter"
|
|
||||||
].freeze
|
|
||||||
|
|
||||||
source_root File.expand_path("templates", __dir__)
|
|
||||||
class_option(
|
|
||||||
:with_changes,
|
|
||||||
type: :boolean,
|
|
||||||
default: false,
|
|
||||||
desc: "Store changeset (diff) with each version"
|
|
||||||
)
|
|
||||||
|
|
||||||
desc "Generates (but does not run) a migration to add a versions table."
|
|
||||||
|
|
||||||
def create_migration_file
|
|
||||||
add_paper_trail_migration("create_versions")
|
|
||||||
add_paper_trail_migration("add_object_changes_to_versions") if options.with_changes?
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.next_migration_number(dirname)
|
|
||||||
::ActiveRecord::Generators::Base.next_migration_number(dirname)
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def add_paper_trail_migration(template)
|
|
||||||
migration_dir = File.expand_path("db/migrate")
|
|
||||||
if self.class.migration_exists?(migration_dir, template)
|
|
||||||
::Kernel.warn "Migration already exists: #{template}"
|
|
||||||
else
|
|
||||||
migration_template(
|
|
||||||
"#{template}.rb.erb",
|
|
||||||
"db/migrate/#{template}.rb",
|
|
||||||
item_type_options: item_type_options,
|
|
||||||
migration_version: migration_version,
|
|
||||||
versions_table_options: versions_table_options
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# MySQL 5.6 utf8mb4 limit is 191 chars for keys used in indexes.
|
|
||||||
# See https://github.com/paper-trail-gem/paper_trail/issues/651
|
|
||||||
def item_type_options
|
|
||||||
opt = { null: false }
|
|
||||||
opt[:limit] = 191 if mysql?
|
|
||||||
", #{opt}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def migration_version
|
|
||||||
major = ActiveRecord::VERSION::MAJOR
|
|
||||||
if major >= 5
|
|
||||||
"[#{major}.#{ActiveRecord::VERSION::MINOR}]"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def mysql?
|
|
||||||
MYSQL_ADAPTERS.include?(ActiveRecord::Base.connection.class.name)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Even modern versions of MySQL still use `latin1` as the default character
|
|
||||||
# encoding. Many users are not aware of this, and run into trouble when they
|
|
||||||
# try to use PaperTrail in apps that otherwise tend to use UTF-8. Postgres, by
|
|
||||||
# comparison, uses UTF-8 except in the unusual case where the OS is configured
|
|
||||||
# with a custom locale.
|
|
||||||
#
|
|
||||||
# - https://dev.mysql.com/doc/refman/5.7/en/charset-applications.html
|
|
||||||
# - http://www.postgresql.org/docs/9.4/static/multibyte.html
|
|
||||||
#
|
|
||||||
# Furthermore, MySQL's original implementation of UTF-8 was flawed, and had
|
|
||||||
# to be fixed later by introducing a new charset, `utf8mb4`.
|
|
||||||
#
|
|
||||||
# - https://mathiasbynens.be/notes/mysql-utf8mb4
|
|
||||||
# - https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
|
|
||||||
#
|
|
||||||
def versions_table_options
|
|
||||||
if mysql?
|
|
||||||
', { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" }'
|
|
||||||
else
|
|
||||||
""
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -16,6 +16,7 @@ require "active_record"
|
||||||
|
|
||||||
require "request_store"
|
require "request_store"
|
||||||
require "paper_trail/cleaner"
|
require "paper_trail/cleaner"
|
||||||
|
require "paper_trail/compatibility"
|
||||||
require "paper_trail/config"
|
require "paper_trail/config"
|
||||||
require "paper_trail/has_paper_trail"
|
require "paper_trail/has_paper_trail"
|
||||||
require "paper_trail/record_history"
|
require "paper_trail/record_history"
|
||||||
|
@ -145,3 +146,7 @@ if defined?(::Rails)
|
||||||
else
|
else
|
||||||
require "paper_trail/frameworks/active_record"
|
require "paper_trail/frameworks/active_record"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if defined?(::ActiveRecord)
|
||||||
|
::PaperTrail::Compatibility.check_activerecord(::ActiveRecord.gem_version)
|
||||||
|
end
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module PaperTrail
|
||||||
|
# Rails does not follow SemVer, makes breaking changes in minor versions.
|
||||||
|
# Breaking changes are expected, and are generally good for the rails
|
||||||
|
# ecosystem. However, they often require dozens of hours to fix, even with the
|
||||||
|
# [help of experts](https://github.com/paper-trail-gem/paper_trail/pull/899).
|
||||||
|
#
|
||||||
|
# It is not safe to assume that a new version of rails will be compatible with
|
||||||
|
# PaperTrail. PT is only compatible with the versions of rails that it is
|
||||||
|
# tested against. See `.travis.yml`.
|
||||||
|
#
|
||||||
|
# However, as of
|
||||||
|
# [#1213](https://github.com/paper-trail-gem/paper_trail/pull/1213) our
|
||||||
|
# gemspec allows installation with newer, incompatible rails versions. We hope
|
||||||
|
# this will make it easier for contributors to work on compatibility with
|
||||||
|
# newer rails versions. Most PT users should avoid incompatible rails
|
||||||
|
# versions.
|
||||||
|
module Compatibility
|
||||||
|
ACTIVERECORD_GTE = ">= 4.2"
|
||||||
|
ACTIVERECORD_LT = "< 6.1"
|
||||||
|
|
||||||
|
E_INCOMPATIBLE_AR = <<-EOS
|
||||||
|
PaperTrail %s is not compatible with ActiveRecord %s. We allow PT
|
||||||
|
contributors to install incompatible versions of ActiveRecord, and this
|
||||||
|
warning can be silenced with an environment variable, but this is a bad
|
||||||
|
idea for normal use. Please install a compatible version of ActiveRecord
|
||||||
|
instead (%s). Please see the discussion in paper_trail/compatibility.rb
|
||||||
|
for details.
|
||||||
|
EOS
|
||||||
|
|
||||||
|
# Normal users need a warning if they accidentally install an incompatible
|
||||||
|
# version of ActiveRecord. Contributors can silence this warning with an
|
||||||
|
# environment variable.
|
||||||
|
def self.check_activerecord(ar_version)
|
||||||
|
raise ::TypeError unless ar_version.instance_of?(::Gem::Version)
|
||||||
|
return if ::ENV["PT_SILENCE_AR_COMPAT_WARNING"].present?
|
||||||
|
req = ::Gem::Requirement.new([ACTIVERECORD_GTE, ACTIVERECORD_LT])
|
||||||
|
unless req.satisfied_by?(ar_version)
|
||||||
|
::Kernel.warn(
|
||||||
|
format(
|
||||||
|
E_INCOMPATIBLE_AR,
|
||||||
|
::PaperTrail.gem_version,
|
||||||
|
ar_version,
|
||||||
|
req
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,7 +9,7 @@ module PaperTrail
|
||||||
module VERSION
|
module VERSION
|
||||||
MAJOR = 10
|
MAJOR = 10
|
||||||
MINOR = 3
|
MINOR = 3
|
||||||
TINY = 0
|
TINY = 1
|
||||||
|
|
||||||
# Set PRE to nil unless it's a pre-release (beta, rc, etc.)
|
# Set PRE to nil unless it's a pre-release (beta, rc, etc.)
|
||||||
PRE = nil
|
PRE = nil
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
$LOAD_PATH.unshift File.expand_path("lib", __dir__)
|
$LOAD_PATH.unshift File.expand_path("lib", __dir__)
|
||||||
|
require "paper_trail/compatibility"
|
||||||
require "paper_trail/version_number"
|
require "paper_trail/version_number"
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
|
@ -27,8 +28,9 @@ has been destroyed.
|
||||||
s.required_rubygems_version = ">= 1.3.6"
|
s.required_rubygems_version = ">= 1.3.6"
|
||||||
s.required_ruby_version = ">= 2.3.0"
|
s.required_ruby_version = ">= 2.3.0"
|
||||||
|
|
||||||
# Rails does not follow semver, makes breaking changes in minor versions.
|
# We no longer specify a maximum rails version.
|
||||||
s.add_dependency "activerecord", [">= 4.2", "< 6.1"]
|
# See discussion in paper_trail/compatibility.rb
|
||||||
|
s.add_dependency "activerecord", ::PaperTrail::Compatibility::ACTIVERECORD_GTE
|
||||||
s.add_dependency "request_store", "~> 1.1"
|
s.add_dependency "request_store", "~> 1.1"
|
||||||
|
|
||||||
s.add_development_dependency "appraisal", "~> 2.2"
|
s.add_development_dependency "appraisal", "~> 2.2"
|
||||||
|
@ -41,7 +43,8 @@ has been destroyed.
|
||||||
s.add_development_dependency "pg", "~> 1.0"
|
s.add_development_dependency "pg", "~> 1.0"
|
||||||
s.add_development_dependency "rake", "~> 12.3"
|
s.add_development_dependency "rake", "~> 12.3"
|
||||||
s.add_development_dependency "rspec-rails", "~> 3.8"
|
s.add_development_dependency "rspec-rails", "~> 3.8"
|
||||||
s.add_development_dependency "rubocop", "~> 0.62.0"
|
s.add_development_dependency "rubocop", "~> 0.71.0"
|
||||||
s.add_development_dependency "rubocop-rspec", "~> 1.28.0"
|
s.add_development_dependency "rubocop-performance", "~> 1.3.0"
|
||||||
|
s.add_development_dependency "rubocop-rspec", "~> 1.33.0"
|
||||||
s.add_development_dependency "sqlite3", "~> 1.3.13"
|
s.add_development_dependency "sqlite3", "~> 1.3.13"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module PaperTrail
|
||||||
|
::RSpec.describe(Compatibility) do
|
||||||
|
describe ".check_activerecord" do
|
||||||
|
context "when compatible" do
|
||||||
|
it "does not produce output" do
|
||||||
|
ar_version = ::Gem::Version.new("6.0.0")
|
||||||
|
expect {
|
||||||
|
described_class.check_activerecord(ar_version)
|
||||||
|
}.not_to output.to_stderr
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when incompatible" do
|
||||||
|
it "writes a warning to stderr" do
|
||||||
|
ar_version = ::Gem::Version.new("6.1.0")
|
||||||
|
expect {
|
||||||
|
described_class.check_activerecord(ar_version)
|
||||||
|
}.to output(/not compatible/).to_stderr
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue