Merge pull request #1275 from paper-trail-gem/rails-6-1-jared
Rails 6.1
This commit is contained in:
commit
799b590c2b
|
@ -51,26 +51,26 @@ Testing is a little awkward because the test suite:
|
|||
### Test sqlite, AR 6
|
||||
|
||||
```
|
||||
DB=sqlite bundle exec appraisal ar-6.0 rake
|
||||
DB=sqlite bundle exec appraisal rails-6.0 rake
|
||||
```
|
||||
|
||||
### Test sqlite, AR 5
|
||||
|
||||
```
|
||||
DB=sqlite bundle exec appraisal ar-5.2 rake
|
||||
DB=sqlite bundle exec appraisal rails-5.2 rake
|
||||
```
|
||||
|
||||
### Test mysql, AR 5
|
||||
|
||||
```
|
||||
DB=mysql bundle exec appraisal ar-5.2 rake
|
||||
DB=mysql bundle exec appraisal rails-5.2 rake
|
||||
```
|
||||
|
||||
### Test postgres, AR 5
|
||||
|
||||
```
|
||||
createuser --superuser postgres
|
||||
DB=postgres bundle exec appraisal ar-5.2 rake
|
||||
DB=postgres bundle exec appraisal rails-5.2 rake
|
||||
```
|
||||
|
||||
## Adding new schema
|
||||
|
|
|
@ -21,13 +21,16 @@ before_install:
|
|||
- gem update bundler
|
||||
|
||||
gemfile:
|
||||
- gemfiles/ar_5.2.gemfile
|
||||
- gemfiles/ar_6.0.gemfile
|
||||
- gemfiles/rails_5.2.gemfile
|
||||
- gemfiles/rails_6.0.gemfile
|
||||
- gemfiles/rails_6.1.gemfile
|
||||
matrix:
|
||||
exclude:
|
||||
# rails 6 requires ruby >= 2.5.0
|
||||
- rvm: 2.4
|
||||
gemfile: gemfiles/ar_6.0.gemfile
|
||||
gemfile: gemfiles/rails_6.0.gemfile
|
||||
- rvm: 2.4
|
||||
gemfile: gemfiles/rails_6.1.gemfile
|
||||
fast_finish: true
|
||||
services:
|
||||
- mysql
|
||||
|
|
|
@ -10,12 +10,17 @@
|
|||
# > https://github.com/thoughtbot/appraisal
|
||||
#
|
||||
#
|
||||
appraise "ar-5.2" do
|
||||
appraise "rails-5.2" do
|
||||
gem "rails", "~> 5.2.4"
|
||||
gem "rails-controller-testing", "~> 1.0.2"
|
||||
end
|
||||
|
||||
appraise "ar-6.0" do
|
||||
appraise "rails-6.0" do
|
||||
gem "rails", "~> 6.0.3"
|
||||
gem "rails-controller-testing", "~> 1.0.3"
|
||||
end
|
||||
|
||||
appraise "rails-6.1" do
|
||||
gem "rails", "~> 6.1.0"
|
||||
gem "rails-controller-testing", "~> 1.0.5"
|
||||
end
|
||||
|
|
|
@ -11,7 +11,8 @@ recommendations of [keepachangelog.com](http://keepachangelog.com/).
|
|||
|
||||
### Added
|
||||
|
||||
- None
|
||||
- [#1272](https://github.com/paper-trail-gem/paper_trail/issues/1272) -
|
||||
Rails 6.1 compatibility
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ has been destroyed.
|
|||
|
||||
| paper_trail | branch | ruby | activerecord |
|
||||
| -------------- | ---------- | -------- | ------------- |
|
||||
| unreleased | master | >= 2.4.0 | >= 5.2, < 6.1 |
|
||||
| unreleased | master | >= 2.4.0 | >= 5.2, < 6.2 |
|
||||
| 11 | master | >= 2.4.0 | >= 5.2, < 6.1 |
|
||||
| 10 | 10-stable | >= 2.3.0 | >= 4.2, < 6.1 |
|
||||
| 9 | 9-stable | >= 2.3.0 | >= 4.2, < 5.3 |
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# This file was generated by Appraisal
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "rails", "~> 6.1.0"
|
||||
gem "rails-controller-testing", "~> 1.0.5"
|
||||
|
||||
gemspec path: "../"
|
|
@ -18,7 +18,7 @@ module PaperTrail
|
|||
# versions.
|
||||
module Compatibility
|
||||
ACTIVERECORD_GTE = ">= 5.2" # enforced in gemspec
|
||||
ACTIVERECORD_LT = "< 6.1" # not enforced in gemspec
|
||||
ACTIVERECORD_LT = "< 6.2" # not enforced in gemspec
|
||||
|
||||
E_INCOMPATIBLE_AR = <<-EOS
|
||||
PaperTrail %s is not compatible with ActiveRecord %s. We allow PT
|
||||
|
|
|
@ -35,7 +35,7 @@ RSpec.describe Gadget, type: :model do
|
|||
gadget.update_attribute(:updated_at, Time.now + 1)
|
||||
}.to(change { gadget.versions.size }.by(1))
|
||||
expect(
|
||||
YAML.safe_load(gadget.versions.last.object_changes, [::Time]).keys
|
||||
YAML.load(gadget.versions.last.object_changes).keys
|
||||
).to eq(["updated_at"])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ RSpec.describe NoObject, versioning: true do
|
|||
|
||||
# New feature: destroy populates object_changes
|
||||
# https://github.com/paper-trail-gem/paper_trail/pull/1123
|
||||
h = YAML.safe_load(a["object_changes"], [::Time])
|
||||
h = YAML.load a["object_changes"]
|
||||
expect(h["id"]).to eq([n.id, nil])
|
||||
expect(h["letter"]).to eq([n.letter, nil])
|
||||
expect(h["created_at"][0]).to be_present
|
||||
|
|
|
@ -14,7 +14,7 @@ module PaperTrail
|
|||
|
||||
context "when incompatible" do
|
||||
it "writes a warning to stderr" do
|
||||
ar_version = ::Gem::Version.new("6.1.0")
|
||||
ar_version = ::Gem::Version.new("6.2.0")
|
||||
expect {
|
||||
described_class.check_activerecord(ar_version)
|
||||
}.to output(/not compatible/).to_stderr
|
||||
|
|
|
@ -30,7 +30,7 @@ module PaperTrail
|
|||
matches = described_class.
|
||||
where_object_condition(PaperTrail::Version.arel_table[:object], :arg1, "Val 1")
|
||||
expect(matches.instance_of?(Arel::Nodes::Matches)).to(eq(true))
|
||||
expect(matches.right.val).to eq("%\"arg1\":\"Val 1\"%")
|
||||
expect(arel_value(matches.right)).to eq("%\"arg1\":\"Val 1\"%")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -39,7 +39,7 @@ module PaperTrail
|
|||
matches = described_class.
|
||||
where_object_condition(PaperTrail::Version.arel_table[:object], :arg1, nil)
|
||||
expect(matches.instance_of?(Arel::Nodes::Matches)).to(eq(true))
|
||||
expect(matches.right.val).to(eq("%\"arg1\":null%"))
|
||||
expect(arel_value(matches.right)).to(eq("%\"arg1\":null%"))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -48,9 +48,14 @@ module PaperTrail
|
|||
grouping = described_class.
|
||||
where_object_condition(PaperTrail::Version.arel_table[:object], :arg1, -3.5)
|
||||
expect(grouping.instance_of?(Arel::Nodes::Grouping)).to(eq(true))
|
||||
matches = grouping.select { |v| v.instance_of?(Arel::Nodes::Matches) }
|
||||
expect(matches.first.right.val).to eq("%\"arg1\":-3.5,%")
|
||||
expect(matches.last.right.val).to eq("%\"arg1\":-3.5}%")
|
||||
disjunction = grouping.expr
|
||||
expect(disjunction).to be_an(Arel::Nodes::Or)
|
||||
dj_left = disjunction.left
|
||||
expect(dj_left).to be_an(Arel::Nodes::Matches)
|
||||
expect(arel_value(dj_left.right)).to eq("%\"arg1\":-3.5,%")
|
||||
dj_right = disjunction.right
|
||||
expect(dj_right).to be_an(Arel::Nodes::Matches)
|
||||
expect(arel_value(dj_right.right)).to eq("%\"arg1\":-3.5}%")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ module PaperTrail
|
|||
::PaperTrail::Version.arel_table[:object], :arg1, "Val 1"
|
||||
)
|
||||
expect(matches.instance_of?(Arel::Nodes::Matches)).to(eq(true))
|
||||
expect(matches.right.val).to eq("%\narg1: Val 1\n%")
|
||||
expect(arel_value(matches.right)).to eq("%\narg1: Val 1\n%")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ ENV["RAILS_ENV"] ||= "test"
|
|||
ENV["DB"] ||= "sqlite"
|
||||
|
||||
require "byebug"
|
||||
require_relative "support/pt_arel_helpers"
|
||||
|
||||
unless File.exist?(File.expand_path("dummy_app/config/database.yml", __dir__))
|
||||
warn "No database.yml detected for the dummy app, please run `rake prepare` first"
|
||||
|
@ -25,6 +26,7 @@ RSpec.configure do |config|
|
|||
config.default_formatter = "doc"
|
||||
end
|
||||
config.order = :random
|
||||
config.include PTArelHelpers
|
||||
Kernel.srand config.seed
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# AR 6.1 does not autoload MigrationContext, so we must `require` it.
|
||||
#
|
||||
# ```
|
||||
# # lib/active_record.rb
|
||||
# autoload :Migration
|
||||
# autoload :Migrator, "active_record/migration"
|
||||
# ```
|
||||
#
|
||||
# The above may indicate that we should use `Migrator` instead of
|
||||
# MigrationContext.
|
||||
require "active_record/migration"
|
||||
|
||||
# Manage migrations including running generators to build them, and cleaning up strays
|
||||
class PaperTrailSpecMigrator
|
||||
def initialize
|
||||
|
@ -31,12 +43,13 @@ class PaperTrailSpecMigrator
|
|||
# - generator [String] - name of generator, eg. "paper_trail:update_sti"
|
||||
# - generator_invoke_args [Array] - arguments to `Generators#invoke`
|
||||
def generate_and_migrate(generator, generator_invoke_args)
|
||||
files = generate(generator, generator_invoke_args)
|
||||
generate(generator, generator_invoke_args)
|
||||
begin
|
||||
migrate
|
||||
ensure
|
||||
files.each do |file|
|
||||
File.delete(Rails.root.join(file))
|
||||
cmd = "git clean -x --force --quiet " + dummy_app_migrations_dir.to_s
|
||||
unless system(cmd)
|
||||
raise "Unable to clean up after PT migration generator test"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module PTArelHelpers
|
||||
def arel_value(node)
|
||||
if node.respond_to?(:val) # rails < 6.1
|
||||
node.val
|
||||
else
|
||||
node.value
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue