Skip to content

Commit

Permalink
Add support for ActiveModel::Dirty 5.2.x API
Browse files Browse the repository at this point in the history
Pieces taken from
#1310
samvera/rubydora#110
  • Loading branch information
cjcolvar committed Apr 27, 2018
1 parent c212ea0 commit 7c8bbbe
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion active-fedora.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.add_dependency 'rsolr', '>= 1.1.2', '< 3'
s.add_dependency 'solrizer', '>= 3.4', '< 5'
s.add_dependency "activesupport", '>= 4.2.4', '< 6'
s.add_dependency "activemodel", '>= 4.2', '< 6'
s.add_dependency "activemodel", '>= 4.2.10', '< 6'
s.add_dependency "active-triples", '>= 0.11.0', '< 2.0.0'
s.add_dependency "deprecation"
s.add_dependency "ldp", '~> 0.7.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/active_fedora/aggregation/list_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def save(*args)
# Overriding so that we don't track previously_changed, which was
# rather expensive.
def clear_changed_attributes
@changed_attributes.clear
clear_changes_information
end

def changed?
Expand Down
2 changes: 1 addition & 1 deletion lib/active_fedora/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def has_attribute?(attr_name)
# person.attribute_names
# # => ["id", "created_at", "updated_at", "name", "age"]
def attribute_names
@attributes.keys
@local_attributes.keys
end

# Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
Expand Down
2 changes: 1 addition & 1 deletion lib/active_fedora/attribute_methods/read.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def read_attribute(attr_name, &block)
end

def _read_attribute(attr_name) # :nodoc:
@attributes.fetch(attr_name.to_s) { |n| yield n if block_given? }
attributes.fetch(attr_name.to_s) { |n| yield n if block_given? }
end

alias attribute _read_attribute
Expand Down
2 changes: 1 addition & 1 deletion lib/active_fedora/attribute_methods/write.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __temp__#{safe_name}=(value)

def write_attribute(attribute_name, value)
if self.class.properties.key?(attribute_name)
@attributes[attribute_name] = value
attributes[attribute_name] = value
else
raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attribute_name}'"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_fedora/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Attributes
after_save :clear_changed_attributes
def clear_changed_attributes
@previously_changed = changes
@changed_attributes.clear
clear_attribute_changes(changes.keys)
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/active_fedora/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def initialize(identifier = nil, &_block)
raise "The first argument to #{self} must be a Hash, String or RDF::URI. You provided a #{identifier.class}"
end

@attributes = {}.with_indifferent_access
@local_attributes = {}.with_indifferent_access
@readonly = false
yield self if block_given?
end
Expand Down Expand Up @@ -86,20 +86,20 @@ def refresh
@content = nil
@metadata = nil
@ds_content = nil
changed_attributes.clear
clear_attribute_changes(changes.keys)
end

def check_fixity
FixityService.new(@ldp_source.subject).check
end

def datastream_will_change!
attribute_will_change! :profile
attribute_will_change! :ldp_source
end

def attribute_will_change!(attr)
return super unless attr == 'content'
changed_attributes['content'] = true
attributes_changed_by_setter[:content] = true
end

def remote_content
Expand Down
1 change: 1 addition & 0 deletions lib/active_fedora/inheritable_accessors.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Similar to ActiveSupport.class_attribute but with a setter that doesn't use the #{name}= syntax
# This preserves backward compatibility with the API in ActiveTriples
require "active_support/core_ext/module/remove_method"

module ActiveFedora
module InheritableAccessors
Expand Down
3 changes: 2 additions & 1 deletion lib/active_fedora/with_metadata/metadata_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def initialize(file)
@file = file
super(file.uri, ldp_source.graph)
return unless self.class.type && !type.include?(self.class.type)
attributes_changed_by_setter[:type] = true if type.present?
# Workaround for https://github.com/ActiveTriples/ActiveTriples/issues/123
get_values(:type) << self.class.type
end
Expand Down Expand Up @@ -54,7 +55,7 @@ def save

def changed_attributes
super.tap do |changed|
changed['type'] = true if type.present? && new_record?
changed.merge('type' => true) if type.present? && new_record?
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def content

describe "changed attributes are set" do
it "marks profile as changed" do
expect_any_instance_of(SampleResource).to receive(:attribute_will_change!).with(:profile)
expect_any_instance_of(SampleResource).to receive(:attribute_will_change!).with(:ldp_source)
test_object
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/support/an_active_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def assert_equal(the_other, one)
expect(one).to eq the_other
end

def assert_respond_to(obj, meth, _msg = nil)
expect(obj).to respond_to meth
end

include ActiveModel::Lint::Tests

ActiveModel::Lint::Tests.public_instance_methods.map(&:to_s).grep(/^test/).each do |m|
Expand Down

0 comments on commit 7c8bbbe

Please sign in to comment.