From 16e1f5e0fa3cb0e04e046170bf0d7693bafcfe37 Mon Sep 17 00:00:00 2001 From: Tom Johnson Date: Fri, 13 Sep 2019 12:13:03 -0700 Subject: [PATCH] Rails 6 (#1403) * Avoid private `ActiveModel::Dirty#attributes_changed_by_setter` This method is removed in ActiveModel 6.0, and is private anyway. Avoid calling it for upgradability. * Drop support for Rails 5.1 Rails 5.1 support is ended. ActiveFedora 14 will drop support. * Rely on `ActiveModel::Dirty` to track previous changes We used to manually set `ActiveModel::Dirty` internals to track "previous changes". In Rails 6, these internals are completely rewritten and much more efficient. We can rely on the provided implementation instead of rolling our own. * Add support for Rails 6 Rails 6 is here. :tada: * Drop support for Ruby 2.4 --- .circleci/config.yml | 16 ++++------------ active-fedora.gemspec | 6 +++--- lib/active_fedora/aggregation/list_source.rb | 6 ------ lib/active_fedora/attributes.rb | 6 +----- lib/active_fedora/file.rb | 5 ----- lib/active_fedora/with_metadata/metadata_node.rb | 2 +- spec/unit/with_metadata/metadata_node_spec.rb | 2 +- 7 files changed, 10 insertions(+), 33 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 88c0b5080..d0abcf91a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,18 +46,10 @@ workflows: ruby_version: 2.5.5 rails_version: 5.2.3 - bundle_lint_test: - name: ruby2-4_rails5-2 - ruby_version: 2.4.6 - rails_version: 5.2.3 - - bundle_lint_test: - name: ruby2-6_rails5-1 + name: ruby2-6_rails6-0 ruby_version: 2.6.3 - rails_version: 5.1.7 + rails_version: 6.0.0 - bundle_lint_test: - name: ruby2-5_rails5.1 + name: ruby2-5_rails6.0 ruby_version: 2.5.5 - rails_version: 5.1.7 - - bundle_lint_test: - name: ruby2-4_rails5-1 - ruby_version: 2.4.6 - rails_version: 5.1.7 + rails_version: 6.0.0 diff --git a/active-fedora.gemspec b/active-fedora.gemspec index 61a4dc5ec..d5fb94287 100644 --- a/active-fedora.gemspec +++ b/active-fedora.gemspec @@ -12,11 +12,11 @@ Gem::Specification.new do |s| s.summary = %q{A convenience libary for manipulating documents in the Fedora Repository.} s.description = %q{ActiveFedora provides for creating and managing objects in the Fedora Repository Architecture.} s.license = "Apache-2.0" - s.required_ruby_version = '~> 2.0' + s.required_ruby_version = '~> 2.5' s.add_dependency 'rsolr', '>= 1.1.2', '< 3' - s.add_dependency "activesupport", '>= 4.2.4', '< 5.3' - s.add_dependency "activemodel", '>= 4.2.10', '< 5.3' + s.add_dependency "activesupport", '>= 5.2' + s.add_dependency "activemodel", '>= 5.2' s.add_dependency "active-triples", '>= 0.11.0', '< 2.0.0' s.add_dependency "deprecation" s.add_dependency "ldp", '>= 0.7.0', '< 2' diff --git a/lib/active_fedora/aggregation/list_source.rb b/lib/active_fedora/aggregation/list_source.rb index a42207b06..097324628 100644 --- a/lib/active_fedora/aggregation/list_source.rb +++ b/lib/active_fedora/aggregation/list_source.rb @@ -12,12 +12,6 @@ def save(*args) super end - # Overriding so that we don't track previously_changed, which was - # rather expensive. - def clear_changed_attributes - clear_changes_information - end - def changed? super || ordered_self.changed? end diff --git a/lib/active_fedora/attributes.rb b/lib/active_fedora/attributes.rb index ab4aabb60..eb2c86f3a 100644 --- a/lib/active_fedora/attributes.rb +++ b/lib/active_fedora/attributes.rb @@ -9,11 +9,7 @@ module Attributes include Serializers include PrimaryKey - after_save :clear_changed_attributes - def clear_changed_attributes - @previously_changed = changes - clear_attribute_changes(changes.keys) - end + after_save :changes_applied end def attribute_names diff --git a/lib/active_fedora/file.rb b/lib/active_fedora/file.rb index 6ac88b22a..dbd9a9384 100644 --- a/lib/active_fedora/file.rb +++ b/lib/active_fedora/file.rb @@ -97,11 +97,6 @@ def datastream_will_change! attribute_will_change! :ldp_source end - def attribute_will_change!(attr) - return super unless attr == 'content' - attributes_changed_by_setter[:content] = true - end - def remote_content return if new_record? @ds_content ||= retrieve_content diff --git a/lib/active_fedora/with_metadata/metadata_node.rb b/lib/active_fedora/with_metadata/metadata_node.rb index 98ed94e77..6f7f49b85 100644 --- a/lib/active_fedora/with_metadata/metadata_node.rb +++ b/lib/active_fedora/with_metadata/metadata_node.rb @@ -15,7 +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? + attribute_will_change!(:type) if type.present? # Workaround for https://github.com/ActiveTriples/ActiveTriples/issues/123 get_values(:type) << self.class.type end diff --git a/spec/unit/with_metadata/metadata_node_spec.rb b/spec/unit/with_metadata/metadata_node_spec.rb index 7a762dd55..90e1d47be 100644 --- a/spec/unit/with_metadata/metadata_node_spec.rb +++ b/spec/unit/with_metadata/metadata_node_spec.rb @@ -19,7 +19,7 @@ generated_schema.configure type: book end - it { is_expected.to eq('type' => true) } + it { is_expected.to match('type' => be_truthy) } end end