From 623292f05722042bfd4f04d931d8313960f96179 Mon Sep 17 00:00:00 2001 From: Tom Johnson Date: Fri, 24 Jan 2020 00:08:15 -0800 Subject: [PATCH] Deprecate public methods for removed collection size feature --- .../concerns/hyrax/collection_behavior.rb | 11 +++++++++++ app/presenters/hyrax/collection_presenter.rb | 19 ++++++++++++++++++- spec/models/collection_spec.rb | 7 +++++++ .../hyrax/collection_presenter_spec.rb | 10 +++++++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/hyrax/collection_behavior.rb b/app/models/concerns/hyrax/collection_behavior.rb index 83cf0826af..3593af150d 100644 --- a/app/models/concerns/hyrax/collection_behavior.rb +++ b/app/models/concerns/hyrax/collection_behavior.rb @@ -111,6 +111,17 @@ def collection_type_gid_document_field_name end end + # @deprecated to be removed in 4.0.0; this feature was replaced with a + # hard-coded null implementation + # @return [Fixnum] 0 + def bytes + Deprecation.warn('#bytes has been deprecated for removal in Hyrax 4.0.0; ' \ + 'The implementation of the indexed Collection size ' \ + 'feature is extremely inefficient, so it has been removed. ' \ + 'This method now returns a hard-coded `0` for compatibility.') + 0 + end + # @api public # Retrieve the permission template for this collection. # @return [Hyrax::PermissionTemplate] diff --git a/app/presenters/hyrax/collection_presenter.rb b/app/presenters/hyrax/collection_presenter.rb index 9031e89ef5..a91919b781 100644 --- a/app/presenters/hyrax/collection_presenter.rb +++ b/app/presenters/hyrax/collection_presenter.rb @@ -41,7 +41,7 @@ def collection_type # Terms is the list of fields displayed by # app/views/collections/_show_descriptions.html.erb def self.terms - [:total_items, :resource_type, :creator, :contributor, :keyword, :license, :publisher, :date_created, :subject, + [:total_items, :size, :resource_type, :creator, :contributor, :keyword, :license, :publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url] end @@ -49,8 +49,13 @@ def terms_with_values self.class.terms.select { |t| self[t].present? } end + ## + # @param [Symbol] key + # @return [Object] def [](key) case key + when :size + size when :total_items total_items else @@ -58,6 +63,18 @@ def [](key) end end + # @deprecated to be removed in 4.0.0; this feature was replaced with a + # hard-coded null implementation + # @return [String] 'unknown' + def size + Deprecation.warn('#size has been deprecated for removal in Hyrax 4.0.0; ' \ + 'The implementation of the indexed Collection size ' \ + 'feature is extremely inefficient, so it has been removed. ' \ + 'This method now returns a hard-coded `"unknown"` for ' \ + 'compatibility.') + 'unknown' + end + def total_items ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id}").count end diff --git a/spec/models/collection_spec.rb b/spec/models/collection_spec.rb index 4ee5bf8161..efcbb587c6 100644 --- a/spec/models/collection_spec.rb +++ b/spec/models/collection_spec.rb @@ -5,6 +5,13 @@ expect(collection.read_groups).to eq ['public'] end + describe '#bytes' do + it 'returns a hard-coded integer and issues a deprecation warning' do + expect(Deprecation).to receive(:warn).once + expect(collection.bytes).to eq(0) + end + end + describe "#validates_with" do before { collection.title = nil } it "ensures the collection has a title" do diff --git a/spec/presenters/hyrax/collection_presenter_spec.rb b/spec/presenters/hyrax/collection_presenter_spec.rb index 0346da6609..4bd5cf1337 100644 --- a/spec/presenters/hyrax/collection_presenter_spec.rb +++ b/spec/presenters/hyrax/collection_presenter_spec.rb @@ -3,7 +3,7 @@ subject { described_class.terms } it do - is_expected.to eq [:total_items, :resource_type, :creator, + is_expected.to eq [:total_items, :size, :resource_type, :creator, :contributor, :keyword, :license, :publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url] @@ -78,6 +78,7 @@ it do is_expected.to eq [:total_items, + :size, :resource_type, :keyword, :date_created, @@ -122,6 +123,13 @@ it { is_expected.to eq ['adc12v'] } end + describe '#size' do + it 'returns a hard-coded string and issues a deprecation warning' do + expect(Deprecation).to receive(:warn).once + expect(presenter.size).to eq('unknown') + end + end + describe "#total_items", :clean_repo do subject { presenter.total_items }