Skip to content

Commit

Permalink
Merge pull request #855 from njaffer/DestroyActor
Browse files Browse the repository at this point in the history
Add DestroyActor to remove work from collection and destroy the work
  • Loading branch information
mjgiarlo authored Jun 21, 2016
2 parents 7da73f8 + 6dda192 commit bf0c76b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app/actors/curation_concerns/actors/actor_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ def create(attributes)
def update(attributes)
actor.update(attributes.with_indifferent_access)
end

def destroy
curation_concern.in_collection_ids.each do |id|
destination_collection = ::Collection.find(id)
destination_collection.members.delete(curation_concern)
destination_collection.update_index
end
curation_concern.destroy
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ def update

def destroy
title = curation_concern.to_s
curation_concern.destroy
CurationConcerns.config.callback.run(:after_destroy, curation_concern.id, current_user)
after_destroy_response(title)
if actor.destroy
CurationConcerns.config.callback.run(:after_destroy, curation_concern.id, current_user)
after_destroy_response(title)
end
end

def file_manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,27 @@

describe '#destroy' do
let(:work_to_be_deleted) { create(:private_generic_work, user: user) }
let(:parent_collection) { create(:collection) }

it 'deletes the work' do
delete :destroy, id: work_to_be_deleted
expect(response).to redirect_to main_app.search_catalog_path
expect(GenericWork).not_to exist(work_to_be_deleted.id)
end

context "when work is a member of a collection" do
before do
parent_collection.members = [work_to_be_deleted]
parent_collection.save!
end
it 'deletes the work and updates the parent collection' do
delete :destroy, id: work_to_be_deleted
expect(GenericWork).not_to exist(work_to_be_deleted.id)
expect(response).to redirect_to main_app.search_catalog_path
expect(parent_collection.reload.members).to eq []
end
end

it "invokes the after_destroy callback" do
expect(CurationConcerns.config.callback).to receive(:run)
.with(:after_destroy, work_to_be_deleted.id, user)
Expand Down

0 comments on commit bf0c76b

Please sign in to comment.