Skip to content

Commit

Permalink
Merge pull request #732 from projecthydra-labs/delete_file_set
Browse files Browse the repository at this point in the history
Unlink file_set from work when file_set is deleted
  • Loading branch information
jcoyne committed Apr 19, 2016
2 parents 28053bf + 8595bed commit 8648414
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 13 additions & 0 deletions app/actors/curation_concerns/file_set_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def update_metadata(attributes)
end

def destroy
unlink_from_work
file_set.destroy
CurationConcerns.config.callback.run(:after_destroy, file_set.id, user)
end
Expand Down Expand Up @@ -142,5 +143,17 @@ def set_thumbnail(work, file_set)
return unless work.thumbnail_id.blank?
work.thumbnail = file_set
end

def unlink_from_work
work = file_set.in_works.first
return unless work && (work.thumbnail_id == file_set.id || work.representative_id == file_set.id)
# This is required to clear the thumbnail_id and representative_id fields on the work
# and force it to be re-solrized. Although ActiveFedora::Aggregation clears the
# children nodes it leaves the GenericWork.thumbnail_id and GenericWork.representative_id
# fields in Solr populated.
work.thumbnail = nil if work.thumbnail_id == file_set.id
work.representative = nil if work.representative_id == file_set.id
work.save!
end
end
end
13 changes: 9 additions & 4 deletions spec/actors/curation_concerns/file_set_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,26 @@
expect { file_set.reload }.to raise_error ActiveFedora::ObjectNotFoundError
end

context "representative of a work" do
context "representative and thumbnail of a work" do
let!(:work) do
work = create(:generic_work)
# this is not part of a block on the create, since the work must be saved
# before the representative can be assigned
work.ordered_members << file_set
work.representative = file_set
work.thumbnail = file_set
work.save
work
end

it "removes representative and the proxy association" do
expect(work.reload.representative_id).to eq(file_set.id)
it "removes representative, thumbnail, and the proxy association" do
gw = GenericWork.load_instance_from_solr(work.id)
expect(gw.representative_id).to eq(file_set.id)
expect(gw.thumbnail_id).to eq(file_set.id)
expect { actor.destroy }.to change { ActiveFedora::Aggregation::Proxy.count }.by(-1)
expect(work.reload.representative_id).to be_nil
gw = GenericWork.load_instance_from_solr(work.id)
expect(gw.representative_id).to be_nil
expect(gw.thumbnail_id).to be_nil
end
end
end
Expand Down

0 comments on commit 8648414

Please sign in to comment.