diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index f5dc825f7..8fe926593 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -34,6 +34,24 @@ def after_create end end + # Overrides CurationConcerns::CollectionsControllerBehavior + # Redirects to the user's collections dashboard page + def after_destroy(id) + respond_to do |format| + format.html { redirect_to sufia.dashboard_collections_path, notice: 'Collection was successfully deleted.' } + format.json { render json: { id: id }, status: :destroyed, location: @collection } + end + end + + # Overrides CurationConcerns::CollectionsControllerBehavior + # Redirects to the user's collections dashboard page + def after_destroy_error(id) + respond_to do |format| + format.html { redirect_to sufia.dashboard_collections_path, notice: 'Collection could not be deleted.' } + format.json { render json: { id: id }, status: :destroy_error, location: @collection } + end + end + protected # Override CurationConcerns::CollectionsControllerBehavior to build a form with ability and request diff --git a/spec/controllers/collections_controller_spec.rb b/spec/controllers/collections_controller_spec.rb index d3dd50b82..ba724f0c9 100644 --- a/spec/controllers/collections_controller_spec.rb +++ b/spec/controllers/collections_controller_spec.rb @@ -27,4 +27,28 @@ subject { described_class } its(:form_class) { is_expected.to be(CollectionForm) } end + + describe "#delete" do + let(:user) { create(:user) } + let(:collection) { create(:collection, depositor: user.login) } + + before do + allow_any_instance_of(Devise::Strategies::HttpHeaderAuthenticatable).to receive(:remote_user).and_return(user.login) + allow_any_instance_of(User).to receive(:groups).and_return([]) + end + + context "when the collection is successfully deleted" do + before { delete :destroy, id: collection } + it { is_expected.to redirect_to("/dashboard/collections") } + end + + context "when the collection is not successfully deleted" do + before do + controller.instance_variable_set(:@collection, collection) + allow(collection).to receive(:destroy).and_return(false) + delete :destroy, id: collection + end + it { is_expected.to redirect_to("/dashboard/collections") } + end + end end diff --git a/spec/features/collection/delete_spec.rb b/spec/features/collection/delete_spec.rb index 2c2b6f725..13743e4a4 100644 --- a/spec/features/collection/delete_spec.rb +++ b/spec/features/collection/delete_spec.rb @@ -17,8 +17,12 @@ db_item_actions_toggle(collection).click click_link 'Delete Collection' expect(page).to have_content 'Collection was successfully deleted' - expect(page).to have_css '#documents' - expect(page).not_to have_content title + within("#my_nav") do + expect(page).to have_content("My Collections") + end + within("#documents") do + expect(page).not_to have_content title + end end end end