From 1c7018816f52fa903fab66b679094040823e530a Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Wed, 19 Dec 2018 14:59:31 -0200 Subject: [PATCH] Compatability with Rails 5.2's ActiveModel::Dirty * We're now expected to call `#reset_changes`, rather than manipulating `@changed_attributes` directly. * `ActiveRecord::Dirty` now assumes that any object it's included in which has an `@attributes` instance variable is database-backed, and has very specific API requirements for `@attributes` (must be an array of `ActiveModel::Attribute` instances). This conflicts with modis' `@attributes`, so we trivially renamed this to `@modis_attributes` to distinguish them. --- lib/modis/attribute.rb | 12 +++++------- lib/modis/model.rb | 2 +- lib/modis/persistence.rb | 2 +- modis.gemspec | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/modis/attribute.rb b/lib/modis/attribute.rb index eeb77d0..1e18942 100644 --- a/lib/modis/attribute.rb +++ b/lib/modis/attribute.rb @@ -19,8 +19,6 @@ def self.included(base) module ClassMethods def bootstrap_attributes(parent = nil) - attr_reader :attributes - class << self attr_accessor :attributes, :attributes_with_defaults end @@ -73,6 +71,10 @@ def #{name}=(value) end end + def attributes + @modis_attributes + end + def assign_attributes(hash) hash.each do |k, v| setter = "#{k}=" @@ -96,12 +98,8 @@ def set_sti_type write_attribute(:type, self.class.name) end - def reset_changes - @changed_attributes = nil - end - def apply_defaults - @attributes = Hash[self.class.attributes_with_defaults] + @modis_attributes = Hash[self.class.attributes_with_defaults] end end end diff --git a/lib/modis/model.rb b/lib/modis/model.rb index 07e3e25..2dbb765 100644 --- a/lib/modis/model.rb +++ b/lib/modis/model.rb @@ -35,7 +35,7 @@ def initialize(record = nil, options = {}) apply_defaults set_sti_type assign_attributes(record) if record - reset_changes + changes_applied return unless options.key?(:new_record) diff --git a/lib/modis/persistence.rb b/lib/modis/persistence.rb index 881d6a0..400425b 100644 --- a/lib/modis/persistence.rb +++ b/lib/modis/persistence.rb @@ -180,7 +180,7 @@ def create_or_update(args = {}) future = persist if future && (future == :unchanged || future.value == 'OK') - reset_changes + changes_applied @new_record = false true else diff --git a/modis.gemspec b/modis.gemspec index ff8528c..8706661 100644 --- a/modis.gemspec +++ b/modis.gemspec @@ -18,8 +18,8 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] - gem.add_runtime_dependency 'activemodel', ['>= 3.0', '< 5.2'] - gem.add_runtime_dependency 'activesupport', ['>= 3.0', '< 5.2'] + gem.add_runtime_dependency 'activemodel', ['>= 3.0'] + gem.add_runtime_dependency 'activesupport', ['>= 3.0'] gem.add_runtime_dependency 'redis', '>= 3.0' gem.add_runtime_dependency 'hiredis', '>= 0.5' gem.add_runtime_dependency 'connection_pool', '>= 2'