Skip to content

Commit

Permalink
Compatability with Rails 5.2's ActiveModel::Dirty
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
benlangfeld committed Dec 19, 2018
1 parent 6fb177a commit b6118a0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ gemfile:
- gemfiles/rails_51.gemfile
- gemfiles/rails_52.gemfile

allow_failures:
- gemfile: gemfiles/rails_52.gemfile

env:
global:
secure: LrTz0Pq2ibNZuKDhdzcrvEUSNxUpPopEq9aJeCxy3UpV0v4vpHBtWV0S6zofvf98g/RkZ6cGI1u+0H578dHgE6pWTo+iR8LAwqPKofrFIWRkeo+M77Vs5swahb3mQyPOcig1hfVWDm25MsojePYm70eBIcBU55NWImtdePXfiU0=
12 changes: 5 additions & 7 deletions lib/modis/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}="
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/modis/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion lib/modis/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit b6118a0

Please sign in to comment.