Skip to content

Commit

Permalink
Remove poorly named methods
Browse files Browse the repository at this point in the history
GenericWork is not part of the model. Let's not have methods that imply
otherwise.
  • Loading branch information
jcoyne committed May 2, 2016
1 parent b911ccb commit 0e14a70
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
1 change: 0 additions & 1 deletion app/indexers/curation_concerns/file_set_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def generate_solr_document
solr_doc[Solrizer.solr_name('file_format', :facetable)] = file_format
solr_doc[Solrizer.solr_name(:file_size, STORED_INTEGER)] = object.file_size[0]
solr_doc['all_text_timv'] = object.full_text.content
solr_doc[Solrizer.solr_name('generic_work_ids', :symbol)] = object.generic_work_ids unless object.generic_work_ids.empty?
solr_doc['height_is'] = Integer(object.height.first) if object.height.present?
solr_doc['width_is'] = Integer(object.width.first) if object.width.present?
solr_doc[Solrizer.solr_name('mime_type', :stored_sortable)] = object.mime_type
Expand Down
21 changes: 6 additions & 15 deletions app/models/concerns/curation_concerns/file_set/belongs_to_works.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ module BelongsToWorks
before_destroy :remove_representative_relationship
end

def generic_works
in_objects # in_objects is provided by Hydra::PCDM::ObjectBehavior
end

# OPTIMIZE: We can load this from Solr much faster than loading the objects
def generic_work_ids
generic_works.map(&:id)
end

# Returns the first parent object
# This is a hack to handle things like FileSets inheriting access controls from their parent. (see CurationConcerns::ParentContainer in app/controllers/concerns/curation_concers/parent_container.rb)
def parent
Expand All @@ -29,16 +20,16 @@ def parent
# Files with sibling relationships
# Returns all FileSets aggregated by any of the GenericWorks that aggregate the current object
def related_files
generic_works = self.generic_works
return [] if generic_works.empty?
generic_works.flat_map { |work| work.file_sets.select { |file_set| file_set.id != id } }
parents = in_objects
return [] if parents.empty?
parents.flat_map { |work| work.file_sets.select { |file_set| file_set.id != id } }
end

# If any parent works are pointing at this object as their representative, remove that pointer.
def remove_representative_relationship
generic_works = self.generic_works
return if generic_works.empty?
generic_works.each do |work|
parents = in_objects
return if parents.empty?
parents.each do |work|
work.update(representative_id: nil) if work.representative_id == id
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/actors/curation_concerns/file_set_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@

context 'when a work is not provided' do
it "leaves the association blank" do
expect(subject.generic_works).to be_empty
expect(subject.in_works).to be_empty
end
end

context 'when a work is provided' do
let(:work) { create(:generic_work) }

it 'adds the generic file to the parent work' do
expect(subject.generic_works).to eq [work]
expect(subject.in_works).to eq [work]
expect(work.reload.file_sets).to include(subject)

# Confirming that date_uploaded and date_modified were set
Expand Down
2 changes: 1 addition & 1 deletion spec/models/file_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def paranoid_edit_permissions
let(:work) { create(:work_with_one_file) }
subject { work.file_sets.first.reload }
it 'belongs to works' do
expect(subject.generic_works).to eq [work]
expect(subject.in_works).to eq [work]
end
end

Expand Down

0 comments on commit 0e14a70

Please sign in to comment.