Skip to content

Commit

Permalink
Deprecate public methods for removed collection size feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Johnson authored and mjgiarlo committed Jan 24, 2020
1 parent 84b4016 commit 623292f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/models/concerns/hyrax/collection_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 18 additions & 1 deletion app/presenters/hyrax/collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,40 @@ 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

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
solr_document.send 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
Expand Down
7 changes: 7 additions & 0 deletions spec/models/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion spec/presenters/hyrax/collection_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -78,6 +78,7 @@

it do
is_expected.to eq [:total_items,
:size,
:resource_type,
:keyword,
:date_created,
Expand Down Expand Up @@ -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 }

Expand Down

0 comments on commit 623292f

Please sign in to comment.