Remove vestigial version conditionals
This commit is contained in:
parent
e5c913859f
commit
de1dda4f79
|
@ -27,6 +27,9 @@ Bundler/OrderedGems:
|
||||||
Exclude:
|
Exclude:
|
||||||
- gemfiles/* # generated by Appraisal
|
- gemfiles/* # generated by Appraisal
|
||||||
|
|
||||||
|
Layout/ArgumentAlignment:
|
||||||
|
EnforcedStyle: with_fixed_indentation
|
||||||
|
|
||||||
Layout/DotPosition:
|
Layout/DotPosition:
|
||||||
EnforcedStyle: trailing
|
EnforcedStyle: trailing
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,6 @@ module PaperTrail
|
||||||
# The `CastAttributeSerializer` (de)serializes model attribute values. For
|
# The `CastAttributeSerializer` (de)serializes model attribute values. For
|
||||||
# example, the string "1.99" serializes into the integer `1` when assigned
|
# example, the string "1.99" serializes into the integer `1` when assigned
|
||||||
# to an attribute of type `ActiveRecord::Type::Integer`.
|
# to an attribute of type `ActiveRecord::Type::Integer`.
|
||||||
#
|
|
||||||
# This implementation depends on the `type_for_attribute` method, which was
|
|
||||||
# introduced in rails 4.2. As of PT 8, we no longer support rails < 4.2.
|
|
||||||
class CastAttributeSerializer
|
class CastAttributeSerializer
|
||||||
def initialize(klass)
|
def initialize(klass)
|
||||||
@klass = klass
|
@klass = klass
|
||||||
|
@ -30,13 +27,6 @@ module PaperTrail
|
||||||
def defined_enums
|
def defined_enums
|
||||||
@defined_enums ||= (@klass.respond_to?(:defined_enums) ? @klass.defined_enums : {})
|
@defined_enums ||= (@klass.respond_to?(:defined_enums) ? @klass.defined_enums : {})
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Uses AR 5's `serialize` and `deserialize`.
|
|
||||||
class CastAttributeSerializer
|
|
||||||
def serialize(attr, val)
|
|
||||||
AttributeSerializerFactory.for(@klass, attr).serialize(val)
|
|
||||||
end
|
|
||||||
|
|
||||||
def deserialize(attr, val)
|
def deserialize(attr, val)
|
||||||
if defined_enums[attr] && val.is_a?(::String)
|
if defined_enums[attr] && val.is_a?(::String)
|
||||||
|
@ -46,6 +36,10 @@ module PaperTrail
|
||||||
AttributeSerializerFactory.for(@klass, attr).deserialize(val)
|
AttributeSerializerFactory.for(@klass, attr).deserialize(val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def serialize(attr, val)
|
||||||
|
AttributeSerializerFactory.for(@klass, attr).serialize(val)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,8 +22,6 @@ module PaperTrail
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
class Base
|
class Base
|
||||||
RAILS_GTE_5_1 = ::ActiveRecord.gem_version >= ::Gem::Version.new("5.1.0.beta1")
|
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
def initialize(record, in_after_callback)
|
def initialize(record, in_after_callback)
|
||||||
@record = record
|
@record = record
|
||||||
|
@ -51,7 +49,7 @@ module PaperTrail
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
def attribute_changed_in_latest_version?(attr_name)
|
def attribute_changed_in_latest_version?(attr_name)
|
||||||
if @in_after_callback && RAILS_GTE_5_1
|
if @in_after_callback
|
||||||
@record.saved_change_to_attribute?(attr_name.to_s)
|
@record.saved_change_to_attribute?(attr_name.to_s)
|
||||||
else
|
else
|
||||||
@record.attribute_changed?(attr_name.to_s)
|
@record.attribute_changed?(attr_name.to_s)
|
||||||
|
@ -60,30 +58,14 @@ module PaperTrail
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
def nonskipped_attributes_before_change(is_touch)
|
def nonskipped_attributes_before_change(is_touch)
|
||||||
cache_changed_attributes do
|
record_attributes = @record.attributes.except(*@record.paper_trail_options[:skip])
|
||||||
record_attributes = @record.attributes.except(*@record.paper_trail_options[:skip])
|
record_attributes.each_key do |k|
|
||||||
|
if @record.class.column_names.include?(k)
|
||||||
record_attributes.each_key do |k|
|
record_attributes[k] = attribute_in_previous_version(k, is_touch)
|
||||||
if @record.class.column_names.include?(k)
|
|
||||||
record_attributes[k] = attribute_in_previous_version(k, is_touch)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rails 5.1 changed the API of `ActiveRecord::Dirty`.
|
|
||||||
# @api private
|
|
||||||
def cache_changed_attributes(&block)
|
|
||||||
if RAILS_GTE_5_1
|
|
||||||
# Everything works fine as it is
|
|
||||||
yield
|
|
||||||
else
|
|
||||||
# Any particular call to `changed_attributes` produces the huge memory allocation.
|
|
||||||
# Lets use the generic AR workaround for that.
|
|
||||||
@record.send(:cache_changed_attributes, &block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Rails 5.1 changed the API of `ActiveRecord::Dirty`. See
|
# Rails 5.1 changed the API of `ActiveRecord::Dirty`. See
|
||||||
# https://github.com/paper-trail-gem/paper_trail/pull/899
|
# https://github.com/paper-trail-gem/paper_trail/pull/899
|
||||||
#
|
#
|
||||||
|
@ -91,18 +73,14 @@ module PaperTrail
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
def attribute_in_previous_version(attr_name, is_touch)
|
def attribute_in_previous_version(attr_name, is_touch)
|
||||||
if RAILS_GTE_5_1
|
if @in_after_callback && !is_touch
|
||||||
if @in_after_callback && !is_touch
|
# For most events, we want the original value of the attribute, before
|
||||||
# For most events, we want the original value of the attribute, before
|
# the last save.
|
||||||
# the last save.
|
@record.attribute_before_last_save(attr_name.to_s)
|
||||||
@record.attribute_before_last_save(attr_name.to_s)
|
|
||||||
else
|
|
||||||
# We are either performing a `record_destroy` or a
|
|
||||||
# `record_update(is_touch: true)`.
|
|
||||||
@record.attribute_in_database(attr_name.to_s)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
@record.attribute_was(attr_name.to_s)
|
# We are either performing a `record_destroy` or a
|
||||||
|
# `record_update(is_touch: true)`.
|
||||||
|
@record.attribute_in_database(attr_name.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -138,7 +116,7 @@ module PaperTrail
|
||||||
def changes_in_latest_version
|
def changes_in_latest_version
|
||||||
# Memoized to reduce memory usage
|
# Memoized to reduce memory usage
|
||||||
@changes_in_latest_version ||= begin
|
@changes_in_latest_version ||= begin
|
||||||
if @in_after_callback && RAILS_GTE_5_1
|
if @in_after_callback
|
||||||
@record.saved_changes
|
@record.saved_changes
|
||||||
else
|
else
|
||||||
@record.changes
|
@record.changes
|
||||||
|
|
|
@ -7,8 +7,6 @@ require "paper_trail/events/update"
|
||||||
module PaperTrail
|
module PaperTrail
|
||||||
# Represents the "paper trail" for a single record.
|
# Represents the "paper trail" for a single record.
|
||||||
class RecordTrail
|
class RecordTrail
|
||||||
RAILS_GTE_5_1 = ::ActiveRecord.gem_version >= ::Gem::Version.new("5.1.0.beta1")
|
|
||||||
|
|
||||||
def initialize(record)
|
def initialize(record)
|
||||||
@record = record
|
@record = record
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,15 +11,12 @@ module PaperTrail
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialize(array)
|
def serialize(array)
|
||||||
return serialize_with_ar(array) if active_record_pre_502?
|
|
||||||
array
|
array
|
||||||
end
|
end
|
||||||
|
|
||||||
def deserialize(array)
|
def deserialize(array)
|
||||||
return deserialize_with_ar(array) if active_record_pre_502?
|
|
||||||
|
|
||||||
case array
|
case array
|
||||||
# Needed for legacy reasons. If serialized array is a string
|
# Needed for legacy data. If serialized array is a string
|
||||||
# then it was serialized with Rails < 5.0.2.
|
# then it was serialized with Rails < 5.0.2.
|
||||||
when ::String then deserialize_with_ar(array)
|
when ::String then deserialize_with_ar(array)
|
||||||
else array
|
else array
|
||||||
|
@ -28,16 +25,6 @@ module PaperTrail
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def active_record_pre_502?
|
|
||||||
::ActiveRecord.gem_version < Gem::Version.new("5.0.2")
|
|
||||||
end
|
|
||||||
|
|
||||||
def serialize_with_ar(array)
|
|
||||||
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.
|
|
||||||
new(@subtype, @delimiter).
|
|
||||||
serialize(array)
|
|
||||||
end
|
|
||||||
|
|
||||||
def deserialize_with_ar(array)
|
def deserialize_with_ar(array)
|
||||||
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.
|
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.
|
||||||
new(@subtype, @delimiter).
|
new(@subtype, @delimiter).
|
||||||
|
|
|
@ -14,12 +14,7 @@ module PaperTrail
|
||||||
extend ::ActiveSupport::Concern
|
extend ::ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
if ::ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
belongs_to :item, polymorphic: true, optional: true
|
||||||
belongs_to :item, polymorphic: true, optional: true
|
|
||||||
else
|
|
||||||
belongs_to :item, polymorphic: true
|
|
||||||
end
|
|
||||||
|
|
||||||
validates_presence_of :event
|
validates_presence_of :event
|
||||||
after_create :enforce_version_limit!
|
after_create :enforce_version_limit!
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,14 +22,11 @@ class BeforeDestroyModifier < CallbackModifier
|
||||||
paper_trail.on_destroy :before
|
paper_trail.on_destroy :before
|
||||||
end
|
end
|
||||||
|
|
||||||
if ActiveRecord.gem_version < Gem::Version.new("5") ||
|
unless ActiveRecord::Base.belongs_to_required_by_default
|
||||||
!ActiveRecord::Base.belongs_to_required_by_default
|
|
||||||
|
|
||||||
class AfterDestroyModifier < CallbackModifier
|
class AfterDestroyModifier < CallbackModifier
|
||||||
has_paper_trail on: []
|
has_paper_trail on: []
|
||||||
paper_trail.on_destroy :after
|
paper_trail.on_destroy :after
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class NoArgDestroyModifier < CallbackModifier
|
class NoArgDestroyModifier < CallbackModifier
|
||||||
|
|
|
@ -8,16 +8,8 @@ module Family
|
||||||
has_many :children, class_name: "::Family::Family", foreign_key: :parent_id
|
has_many :children, class_name: "::Family::Family", foreign_key: :parent_id
|
||||||
has_many :grandsons, through: :familie_lines
|
has_many :grandsons, through: :familie_lines
|
||||||
has_one :mentee, class_name: "::Family::Family", foreign_key: :partner_id
|
has_one :mentee, class_name: "::Family::Family", foreign_key: :partner_id
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
belongs_to :parent, class_name: "::Family::Family", foreign_key: :parent_id, optional: true
|
||||||
belongs_to :parent, class_name: "::Family::Family", foreign_key: :parent_id, optional: true
|
belongs_to :mentor, class_name: "::Family::Family", foreign_key: :partner_id, optional: true
|
||||||
else
|
|
||||||
belongs_to :parent, class_name: "::Family::Family", foreign_key: :parent_id
|
|
||||||
end
|
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
|
||||||
belongs_to :mentor, class_name: "::Family::Family", foreign_key: :partner_id, optional: true
|
|
||||||
else
|
|
||||||
belongs_to :mentor, class_name: "::Family::Family", foreign_key: :partner_id
|
|
||||||
end
|
|
||||||
|
|
||||||
accepts_nested_attributes_for :mentee
|
accepts_nested_attributes_for :mentee
|
||||||
accepts_nested_attributes_for :children
|
accepts_nested_attributes_for :children
|
||||||
|
|
|
@ -3,19 +3,13 @@
|
||||||
module Family
|
module Family
|
||||||
class FamilyLine < ActiveRecord::Base
|
class FamilyLine < ActiveRecord::Base
|
||||||
has_paper_trail
|
has_paper_trail
|
||||||
|
belongs_to :parent,
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
class_name: "::Family::Family",
|
||||||
belongs_to :parent, class_name: "::Family::Family", foreign_key: :parent_id, optional: true
|
foreign_key: :parent_id,
|
||||||
else
|
optional: true
|
||||||
belongs_to :parent, class_name: "::Family::Family", foreign_key: :parent_id
|
belongs_to :grandson,
|
||||||
end
|
class_name: "::Family::Family",
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
foreign_key: :grandson_id,
|
||||||
belongs_to :grandson, class_name: "::Family::Family",
|
optional: true
|
||||||
foreign_key: :grandson_id,
|
|
||||||
optional: true
|
|
||||||
else
|
|
||||||
belongs_to :grandson, class_name: "::Family::Family",
|
|
||||||
foreign_key: :grandson_id
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Fluxor < ActiveRecord::Base
|
class Fluxor < ActiveRecord::Base
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
belongs_to :widget, optional: true
|
||||||
belongs_to :widget, optional: true
|
|
||||||
else
|
|
||||||
belongs_to :widget
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,11 +14,7 @@ class Person < ActiveRecord::Base
|
||||||
|
|
||||||
has_one :thing
|
has_one :thing
|
||||||
|
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
belongs_to :mentor, class_name: "Person", foreign_key: :mentor_id, optional: true
|
||||||
belongs_to :mentor, class_name: "Person", foreign_key: :mentor_id, optional: true
|
|
||||||
else
|
|
||||||
belongs_to :mentor, class_name: "Person", foreign_key: :mentor_id
|
|
||||||
end
|
|
||||||
|
|
||||||
has_paper_trail
|
has_paper_trail
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Pet < ActiveRecord::Base
|
class Pet < ActiveRecord::Base
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
belongs_to :owner, class_name: "Person", optional: true
|
||||||
belongs_to :owner, class_name: "Person", optional: true
|
belongs_to :animal, optional: true
|
||||||
else
|
|
||||||
belongs_to :owner, class_name: "Person"
|
|
||||||
end
|
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
|
||||||
belongs_to :animal, optional: true
|
|
||||||
else
|
|
||||||
belongs_to :animal
|
|
||||||
end
|
|
||||||
|
|
||||||
has_paper_trail
|
has_paper_trail
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,25 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module OverrideSongAttributesTheRails4Way
|
|
||||||
def attributes
|
|
||||||
if name
|
|
||||||
super.merge(name: name)
|
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def changed_attributes
|
|
||||||
if name
|
|
||||||
super.merge(name: name)
|
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Song < ActiveRecord::Base
|
class Song < ActiveRecord::Base
|
||||||
has_paper_trail
|
has_paper_trail
|
||||||
|
attribute :name, :string
|
||||||
|
|
||||||
# Uses an integer of seconds to hold the length of the song
|
# Uses an integer of seconds to hold the length of the song
|
||||||
def length=(minutes)
|
def length=(minutes)
|
||||||
|
@ -29,12 +12,4 @@ class Song < ActiveRecord::Base
|
||||||
def length
|
def length
|
||||||
read_attribute(:length) / 60
|
read_attribute(:length) / 60
|
||||||
end
|
end
|
||||||
|
|
||||||
if ActiveRecord::VERSION::MAJOR >= 5
|
|
||||||
attribute :name, :string
|
|
||||||
else
|
|
||||||
attr_accessor :name
|
|
||||||
|
|
||||||
prepend OverrideSongAttributesTheRails4Way
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,10 +5,5 @@ class Thing < ActiveRecord::Base
|
||||||
scope: -> { order("id desc") },
|
scope: -> { order("id desc") },
|
||||||
extend: PrefixVersionsInspectWithCount
|
extend: PrefixVersionsInspectWithCount
|
||||||
}
|
}
|
||||||
|
belongs_to :person, optional: true
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
|
||||||
belongs_to :person, optional: true
|
|
||||||
else
|
|
||||||
belongs_to :person
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,10 +3,5 @@
|
||||||
class Vehicle < ActiveRecord::Base
|
class Vehicle < ActiveRecord::Base
|
||||||
# This STI parent class specifically does not call `has_paper_trail`.
|
# This STI parent class specifically does not call `has_paper_trail`.
|
||||||
# Of its sub-classes, only `Car` and `Bicycle` are versioned.
|
# Of its sub-classes, only `Car` and `Bicycle` are versioned.
|
||||||
|
belongs_to :owner, class_name: "Person", optional: true
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
|
||||||
belongs_to :owner, class_name: "Person", optional: true
|
|
||||||
else
|
|
||||||
belongs_to :owner, class_name: "Person"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,10 +2,5 @@
|
||||||
|
|
||||||
class Whatchamajigger < ActiveRecord::Base
|
class Whatchamajigger < ActiveRecord::Base
|
||||||
has_paper_trail
|
has_paper_trail
|
||||||
|
belongs_to :owner, polymorphic: true, optional: true
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
|
||||||
belongs_to :owner, polymorphic: true, optional: true
|
|
||||||
else
|
|
||||||
belongs_to :owner, polymorphic: true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,11 +3,7 @@
|
||||||
class Wotsit < ActiveRecord::Base
|
class Wotsit < ActiveRecord::Base
|
||||||
has_paper_trail
|
has_paper_trail
|
||||||
|
|
||||||
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
belongs_to :widget, optional: true
|
||||||
belongs_to :widget, optional: true
|
|
||||||
else
|
|
||||||
belongs_to :widget
|
|
||||||
end
|
|
||||||
|
|
||||||
def created_on
|
def created_on
|
||||||
created_at.to_date
|
created_at.to_date
|
||||||
|
|
|
@ -22,11 +22,7 @@ RSpec.describe PaperTrail::InstallGenerator, type: :generator do
|
||||||
expected_parent_class = lambda {
|
expected_parent_class = lambda {
|
||||||
old_school = "ActiveRecord::Migration"
|
old_school = "ActiveRecord::Migration"
|
||||||
ar_version = ActiveRecord::VERSION
|
ar_version = ActiveRecord::VERSION
|
||||||
if ar_version::MAJOR >= 5
|
format("%s[%d.%d]", old_school, ar_version::MAJOR, ar_version::MINOR)
|
||||||
format("%s[%d.%d]", old_school, ar_version::MAJOR, ar_version::MINOR)
|
|
||||||
else
|
|
||||||
old_school
|
|
||||||
end
|
|
||||||
}.call
|
}.call
|
||||||
expected_create_table_options = lambda {
|
expected_create_table_options = lambda {
|
||||||
if described_class::MYSQL_ADAPTERS.include?(ActiveRecord::Base.connection.class.name)
|
if described_class::MYSQL_ADAPTERS.include?(ActiveRecord::Base.connection.class.name)
|
||||||
|
|
|
@ -17,9 +17,7 @@ RSpec.describe CallbackModifier, type: :model, versioning: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if ActiveRecord.gem_version < Gem::Version.new("5") ||
|
unless ActiveRecord::Base.belongs_to_required_by_default
|
||||||
!ActiveRecord::Base.belongs_to_required_by_default
|
|
||||||
|
|
||||||
context "when :after" do
|
context "when :after" do
|
||||||
it "creates the version after destroy" do
|
it "creates the version after destroy" do
|
||||||
modifier = AfterDestroyModifier.create!(some_content: FFaker::Lorem.sentence)
|
modifier = AfterDestroyModifier.create!(some_content: FFaker::Lorem.sentence)
|
||||||
|
@ -27,7 +25,6 @@ RSpec.describe CallbackModifier, type: :model, versioning: true do
|
||||||
expect(modifier.versions.last.reify).to be_flagged_deleted
|
expect(modifier.versions.last.reify).to be_flagged_deleted
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when no argument" do
|
context "when no argument" do
|
||||||
|
|
|
@ -74,9 +74,8 @@ RSpec.describe Person, type: :model, versioning: true do
|
||||||
person.save!
|
person.save!
|
||||||
person.assign_attributes(time_zone: "Pacific Time (US & Canada)")
|
person.assign_attributes(time_zone: "Pacific Time (US & Canada)")
|
||||||
person.save!
|
person.save!
|
||||||
max_len = ActiveRecord::VERSION::MAJOR < 4 ? 105 : 118
|
|
||||||
len = person.versions.last.object_changes.length
|
len = person.versions.last.object_changes.length
|
||||||
expect((len < max_len)).to(be_truthy)
|
expect(len < 118).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "version.object attribute should have stored value from serializer" do
|
it "version.object attribute should have stored value from serializer" do
|
||||||
|
|
|
@ -110,14 +110,12 @@ module PaperTrail
|
||||||
|
|
||||||
context "changing the data type of database columns on the fly" do
|
context "changing the data type of database columns on the fly" do
|
||||||
# TODO: Changing the data type of these database columns in the middle
|
# TODO: Changing the data type of these database columns in the middle
|
||||||
# of the test suite adds a fair amount of complication. Is there a better
|
# of the test suite adds a fair amount of complexity. Is there a better
|
||||||
# way? We already have a `json_versions` table in our tests, maybe we
|
# way? We already have a `json_versions` table in our tests, maybe we
|
||||||
# could use that and add a `jsonb_versions` table?
|
# could use that and add a `jsonb_versions` table?
|
||||||
column_overrides = [false]
|
column_overrides = [false]
|
||||||
if ENV["DB"] == "postgres" && ::ActiveRecord::VERSION::MAJOR >= 4
|
if ENV["DB"] == "postgres"
|
||||||
column_overrides << "json"
|
column_overrides += %w[json jsonb]
|
||||||
# 'jsonb' column types are only supported for ActiveRecord 4.2+
|
|
||||||
column_overrides << "jsonb" if ::ActiveRecord::VERSION::STRING >= "4.2"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
column_overrides.shuffle.each do |column_datatype_override|
|
column_overrides.shuffle.each do |column_datatype_override|
|
||||||
|
|
|
@ -5,7 +5,7 @@ require "spec_helper"
|
||||||
module PaperTrail
|
module PaperTrail
|
||||||
module AttributeSerializers
|
module AttributeSerializers
|
||||||
::RSpec.describe ObjectAttribute do
|
::RSpec.describe ObjectAttribute do
|
||||||
if ENV["DB"] == "postgres" && ::ActiveRecord::VERSION::MAJOR >= 5
|
if ENV["DB"] == "postgres"
|
||||||
describe "postgres-specific column types" do
|
describe "postgres-specific column types" do
|
||||||
describe "#serialize" do
|
describe "#serialize" do
|
||||||
it "serializes a postgres array into a plain array" do
|
it "serializes a postgres array into a plain array" do
|
||||||
|
|
|
@ -477,9 +477,6 @@ RSpec.describe(::PaperTrail, versioning: true) do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reify with the correct type" do
|
it "reify with the correct type" do
|
||||||
if ActiveRecord::VERSION::MAJOR < 4
|
|
||||||
assert_kind_of(FooWidget, foo.versions.last.reify)
|
|
||||||
end
|
|
||||||
expect(PaperTrail::Version.last.previous).to(eq(foo.versions.first))
|
expect(PaperTrail::Version.last.previous).to(eq(foo.versions.first))
|
||||||
expect(PaperTrail::Version.last.next).to(be_nil)
|
expect(PaperTrail::Version.last.next).to(be_nil)
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,17 +22,17 @@ class PaperTrailSpecMigrator
|
||||||
# in rails 5.2. This is an undocumented change, AFAICT. Then again,
|
# in rails 5.2. This is an undocumented change, AFAICT. Then again,
|
||||||
# how many people use the programmatic interface? Most people probably
|
# how many people use the programmatic interface? Most people probably
|
||||||
# just use rake. Maybe we're doing it wrong.
|
# just use rake. Maybe we're doing it wrong.
|
||||||
|
#
|
||||||
|
# See also discussion in https://github.com/rails/rails/pull/40806, when
|
||||||
|
# MigrationContext#migrate became public.
|
||||||
def migrate
|
def migrate
|
||||||
v = ::ActiveRecord.gem_version
|
if ::ActiveRecord.gem_version >= ::Gem::Version.new("6.0.0.rc2")
|
||||||
if v >= ::Gem::Version.new("6.0.0.rc2")
|
|
||||||
::ActiveRecord::MigrationContext.new(
|
::ActiveRecord::MigrationContext.new(
|
||||||
@migrations_path,
|
@migrations_path,
|
||||||
::ActiveRecord::Base.connection.schema_migration
|
::ActiveRecord::Base.connection.schema_migration
|
||||||
).migrate
|
).migrate
|
||||||
elsif ::Gem::Requirement.new([">= 5.2.0.rc1", "< 6.0.0.rc2"]).satisfied_by?(v)
|
|
||||||
::ActiveRecord::MigrationContext.new(@migrations_path).migrate
|
|
||||||
else
|
else
|
||||||
::ActiveRecord::Migrator.migrate(@migrations_path)
|
::ActiveRecord::MigrationContext.new(@migrations_path).migrate
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue