diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 7c976673..f839620f 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -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 diff --git a/.travis.yml b/.travis.yml index 503805b8..386f3560 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Appraisals b/Appraisals index 17762f0a..b4051e70 100644 --- a/Appraisals +++ b/Appraisals @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f6ee78c..86e2c3e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 8cad36b0..f88eb7f1 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/gemfiles/ar_5.2.gemfile b/gemfiles/rails_5.2.gemfile similarity index 100% rename from gemfiles/ar_5.2.gemfile rename to gemfiles/rails_5.2.gemfile diff --git a/gemfiles/ar_6.0.gemfile b/gemfiles/rails_6.0.gemfile similarity index 100% rename from gemfiles/ar_6.0.gemfile rename to gemfiles/rails_6.0.gemfile diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile new file mode 100644 index 00000000..9d88e7a4 --- /dev/null +++ b/gemfiles/rails_6.1.gemfile @@ -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: "../" diff --git a/lib/paper_trail/compatibility.rb b/lib/paper_trail/compatibility.rb index e7bd25e7..d27031da 100644 --- a/lib/paper_trail/compatibility.rb +++ b/lib/paper_trail/compatibility.rb @@ -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 diff --git a/spec/models/gadget_spec.rb b/spec/models/gadget_spec.rb index 0e1e90f8..61295fa1 100644 --- a/spec/models/gadget_spec.rb +++ b/spec/models/gadget_spec.rb @@ -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 diff --git a/spec/models/no_object_spec.rb b/spec/models/no_object_spec.rb index 06feddab..4c4e9e7b 100644 --- a/spec/models/no_object_spec.rb +++ b/spec/models/no_object_spec.rb @@ -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 diff --git a/spec/paper_trail/compatibility_spec.rb b/spec/paper_trail/compatibility_spec.rb index d2dfb23e..ecd2105f 100644 --- a/spec/paper_trail/compatibility_spec.rb +++ b/spec/paper_trail/compatibility_spec.rb @@ -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 diff --git a/spec/paper_trail/serializers/json_spec.rb b/spec/paper_trail/serializers/json_spec.rb index 34e702d7..2608369e 100644 --- a/spec/paper_trail/serializers/json_spec.rb +++ b/spec/paper_trail/serializers/json_spec.rb @@ -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 diff --git a/spec/paper_trail/serializers/yaml_spec.rb b/spec/paper_trail/serializers/yaml_spec.rb index 5b0ec052..92ef85a7 100644 --- a/spec/paper_trail/serializers/yaml_spec.rb +++ b/spec/paper_trail/serializers/yaml_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3240e579..17c84868 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/support/paper_trail_spec_migrator.rb b/spec/support/paper_trail_spec_migrator.rb index 3d5b886b..1a30de9b 100644 --- a/spec/support/paper_trail_spec_migrator.rb +++ b/spec/support/paper_trail_spec_migrator.rb @@ -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 diff --git a/spec/support/pt_arel_helpers.rb b/spec/support/pt_arel_helpers.rb new file mode 100644 index 00000000..66763eab --- /dev/null +++ b/spec/support/pt_arel_helpers.rb @@ -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