Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #766 from psu-stewardship/redirect
Browse files Browse the repository at this point in the history
Redirect to user's collections dashboard upon delete, ref #740
  • Loading branch information
carolyncole authored Apr 17, 2017
2 parents 37e7983 + afe3b62 commit 967bdbd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
18 changes: 18 additions & 0 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/collections_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions spec/features/collection/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 967bdbd

Please sign in to comment.