Tests: various updates for rails 6.1
This commit is contained in:
parent
ea618650c2
commit
fbe05cf13f
|
@ -21,6 +21,6 @@ appraise "ar-6.0" do
|
|||
end
|
||||
|
||||
appraise "ar-6.1" do
|
||||
gem "activerecord", "~> 6.1.0"
|
||||
gem "rails", "~> 6.1.0"
|
||||
gem "rails-controller-testing", "~> 1.0.5"
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "activerecord", "~> 6.1.0"
|
||||
gem "rails", "~> 6.1.0"
|
||||
gem "rails-controller-testing", "~> 1.0.5"
|
||||
|
||||
gemspec path: "../"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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