From bca15f7654b54a309f995b962ce90a2cd42821ac Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Thu, 26 Apr 2018 07:58:10 -0700 Subject: [PATCH] Add compatibility with Rubydora 2.1; drop support for Rails <= 4.2.9 --- .travis.yml | 4 +++- active-fedora.gemspec | 2 +- lib/active_fedora/attributes.rb | 2 +- lib/active_fedora/datastreams/nokogiri_datastreams.rb | 6 +++--- lib/active_fedora/om_datastream.rb | 11 ++++++++++- lib/active_fedora/rdf/rdf_datastream.rb | 6 +++++- spec/support/an_active_model.rb | 5 +++++ 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 210e807fd..e0e849ca9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,9 @@ rvm: matrix: include: - rvm: 2.5.1 - env: ACTIVEMODEL_VERSION=5.1.6 + env: RAILS_VERSION=5.2.0 + - rvm: 2.4.4 + env: RAILS_VERSION=5.1.6 - rvm: 2.3.7 env: RAILS_VERSION=5.0.7 - rvm: 2.2.10 diff --git a/active-fedora.gemspec b/active-fedora.gemspec index 2f9f9fcd8..e66fe1918 100644 --- a/active-fedora.gemspec +++ b/active-fedora.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |s| s.add_dependency 'rsolr', ">= 1.0.11", '< 3' s.add_dependency 'om', '~> 3.1' s.add_dependency 'nom-xml', '>= 0.5.1' - s.add_dependency "activesupport", '>= 3.0.0' + s.add_dependency "activesupport", '>= 4.2.10' s.add_dependency "rubydora", '>= 1.8.0', '< 3' s.add_dependency "active-triples", '~> 0.4.0' s.add_dependency "rdf-rdfxml", '~> 1.1' diff --git a/lib/active_fedora/attributes.rb b/lib/active_fedora/attributes.rb index 8012047df..7addad148 100644 --- a/lib/active_fedora/attributes.rb +++ b/lib/active_fedora/attributes.rb @@ -11,7 +11,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 diff --git a/lib/active_fedora/datastreams/nokogiri_datastreams.rb b/lib/active_fedora/datastreams/nokogiri_datastreams.rb index e8f76a066..e2e643edc 100644 --- a/lib/active_fedora/datastreams/nokogiri_datastreams.rb +++ b/lib/active_fedora/datastreams/nokogiri_datastreams.rb @@ -66,16 +66,16 @@ def ng_xml=(new_xml) # don't want content eagerly loaded by proxy, so implementing methods that would be implemented by define_attribute_methods def ng_xml_will_change! - changed_attributes['ng_xml'] = nil + attributes_changed_by_setter[:ng_xml] = nil end def ng_xml_doesnt_change! - changed_attributes.delete('ng_xml') + clear_attribute_changes([:ng_xml]) end # don't want content eagerly loaded by proxy, so implementing methods that would be implemented by define_attribute_methods def ng_xml_changed? - changed_attributes.has_key? 'ng_xml' + changed_attributes.has_key? :ng_xml end def datastream_content diff --git a/lib/active_fedora/om_datastream.rb b/lib/active_fedora/om_datastream.rb index 3ee71dbee..2811d65ca 100644 --- a/lib/active_fedora/om_datastream.rb +++ b/lib/active_fedora/om_datastream.rb @@ -6,7 +6,11 @@ class OmDatastream < Datastream before_save do if content.blank? ActiveFedora::Base.logger.warn "Cowardly refusing to save a datastream with empty content: #{self.inspect}" if ActiveFedora::Base.logger - false + if ActiveSupport.version >= Gem::Version.new('5.0') + throw(:abort) + else + false + end end end @@ -295,5 +299,10 @@ def term_values(*term_pointer) end end + def reset_profile_attributes + super + clear_attribute_changes([:ng_xml]) + end + end end diff --git a/lib/active_fedora/rdf/rdf_datastream.rb b/lib/active_fedora/rdf/rdf_datastream.rb index 80d9dffc2..98265cbe5 100644 --- a/lib/active_fedora/rdf/rdf_datastream.rb +++ b/lib/active_fedora/rdf/rdf_datastream.rb @@ -39,7 +39,11 @@ def resource_class(klass=nil) before_save do if content.blank? ActiveFedora::Base.logger.warn "Cowardly refusing to save a datastream with empty content: #{self.inspect}" if ActiveFedora::Base.logger - false + if ActiveSupport.version >= Gem::Version.new('5.0') + throw(:abort) + else + false + end end end diff --git a/spec/support/an_active_model.rb b/spec/support/an_active_model.rb index fd0def002..135ac5d7c 100644 --- a/spec/support/an_active_model.rb +++ b/spec/support/an_active_model.rb @@ -10,6 +10,11 @@ def assert_equal(test, obj) def assert_kind_of(klass, inspected_object) expect(inspected_object).to be_kind_of(klass) 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{|m| m.to_s}.grep(/^test/).each do |m|