diff --git a/active-fedora.gemspec b/active-fedora.gemspec index 487cad762..f7fd7dc92 100644 --- a/active-fedora.gemspec +++ b/active-fedora.gemspec @@ -25,18 +25,20 @@ Gem::Specification.new do |s| s.add_dependency 'faraday', '~> 0.12' s.add_dependency 'faraday-encoding', '0.0.4' - s.add_development_dependency "rails" + s.add_development_dependency "equivalent-xml" + s.add_development_dependency 'fcrepo_wrapper', '~> 0.2' + s.add_development_dependency "github_changelog_generator" s.add_development_dependency "rdoc" - s.add_development_dependency "yard" + s.add_development_dependency "psych", "< 4" # Restricted because 4.0+ do not work with rubocop 0.56.x + s.add_development_dependency "rails" s.add_development_dependency "rake" - s.add_development_dependency "solr_wrapper", "~> 2.0" - s.add_development_dependency 'fcrepo_wrapper', '~> 0.2' s.add_development_dependency "rspec", "~> 3.5" s.add_development_dependency "rspec-its" - s.add_development_dependency "equivalent-xml" - s.add_development_dependency "simplecov", '~> 0.8' s.add_development_dependency "rubocop", '~> 0.56.0' s.add_development_dependency "rubocop-rspec", '~> 1.12.0' + s.add_development_dependency "simplecov", '~> 0.8' + s.add_development_dependency "solr_wrapper", "~> 2.0" + s.add_development_dependency "yard" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {spec}/*`.split("\n") diff --git a/lib/active_fedora.rb b/lib/active_fedora.rb index 0e25523af..a21b61c29 100644 --- a/lib/active_fedora.rb +++ b/lib/active_fedora.rb @@ -11,9 +11,11 @@ # Monkey patching RDF::Literal::DateTime to support fractional seconds. # See https://github.com/samvera/active_fedora/issues/497 # Also monkey patches in a fix for timezones to be stored properly. +# This is needed in both RDF <= 3.2.4 and RDF >= 3.2.5 +# TODO: Figure out how to contribute something upstream to avoid monkey-patching module RDF class Literal - class DateTime < Literal + class DateTime ALTERNATIVE_FORMAT = '%Y-%m-%dT%H:%M:%S'.freeze DOT = '.'.freeze EMPTY = ''.freeze diff --git a/lib/active_fedora/core/fedora_id_translator.rb b/lib/active_fedora/core/fedora_id_translator.rb index a2b47b1eb..1c9d1cf12 100644 --- a/lib/active_fedora/core/fedora_id_translator.rb +++ b/lib/active_fedora/core/fedora_id_translator.rb @@ -2,7 +2,7 @@ module ActiveFedora::Core class FedoraIdTranslator SLASH = '/'.freeze def self.call(id) - id = URI.escape(id, '[]'.freeze) + id = URI::DEFAULT_PARSER.escape(id, '[]'.freeze) id = "/#{id}" unless id.start_with? SLASH unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/") id = ActiveFedora.fedora.base_path + id diff --git a/lib/active_fedora/file.rb b/lib/active_fedora/file.rb index e5d924c2b..f201bb564 100644 --- a/lib/active_fedora/file.rb +++ b/lib/active_fedora/file.rb @@ -179,7 +179,7 @@ def retrieve_content def ldp_headers headers = { 'Content-Type'.freeze => mime_type, 'Content-Length'.freeze => content.size.to_s } - headers['Content-Disposition'.freeze] = "attachment; filename=\"#{URI.encode(@original_name)}\"" if @original_name + headers['Content-Disposition'.freeze] = "attachment; filename=\"#{URI::DEFAULT_PARSER.escape(@original_name)}\"" if @original_name headers end diff --git a/spec/integration/date_time_properties_spec.rb b/spec/integration/date_time_properties_spec.rb index fa58f4cea..202716ab7 100644 --- a/spec/integration/date_time_properties_spec.rb +++ b/spec/integration/date_time_properties_spec.rb @@ -33,9 +33,33 @@ class Foo < ActiveFedora::Base describe 'serializing' do let(:object) { Foo.new(date: [date]) } - let(:triple) { object.resource.query(predicate: ::RDF::Vocab::DC.date).to_a.first } + let(:triple) { object.resource.query(predicate: ::RDF::Vocab::DC.date).to_a.first.object } it 'time zone must have semicolin to be a cannonical XMLSchema#dateTime' do expect(triple.to_s).to match(/\+01:00/) end + + context 'nanoseconds' do + let(:date) { DateTime.parse("2015-10-22T10:20:03.653991025+01:00") } + + it 'includes nanosecond precision' do + expect(triple.to_s).to eq "2015-10-22T10:20:03.653991025+01:00" + end + + context 'with trailing zeros' do + let(:date) { DateTime.parse("2015-10-22T15:34:20.97800000-11:00") } + + it 'trims trailing zeros' do + expect(triple.to_s).to eq "2015-10-22T15:34:20.978-11:00" + end + + context 'and only zero nanoseconds' do + let(:date) { DateTime.parse("2015-10-22T15:34:20.000000000-11:00") } + + it 'trims trailing zeros and dot if nanoseconds are all 0' do + expect(triple.to_s).to eq "2015-10-22T15:34:20-11:00" + end + end + end + end end end