Skip to content

Commit

Permalink
Quick naïve attempt to fix redirects after deleting collections.
Browse files Browse the repository at this point in the history
Fixes #2858.

Based on #3014 and psu-libraries/scholarsphere#401, thanks to @hortongn and @awead.
  • Loading branch information
mjgiarlo committed Jan 24, 2017
1 parent 1de7cd6 commit 52d3c0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ module CollectionsControllerBehavior

protected

def after_destroy_response(title)
respond_to do |wants|
wants.html { redirect_to sufia.dashboard_collections_path, notice: "Deleted #{title}" }
wants.json { render_json_response(respond_type: :deleted, message: "Deleted #{params['id']}") }
end
end

def add_breadcrumb_for_controller
add_breadcrumb I18n.t('sufia.dashboard.my.collections'), sufia.dashboard_collections_path
end
Expand Down
18 changes: 18 additions & 0 deletions spec/controllers/collections_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,24 @@
end
end

describe "#delete" do
before { sign_in user }
context "after deletion" do
it "redirects to My Collections" do
delete :destroy, params: { id: collection }
expect(response).to redirect_to(Sufia::Engine.routes.url_helpers.dashboard_collections_path)
expect(flash[:notice]).to eq "Deleted My Collection"
end

it "returns json" do
delete :destroy, params: { format: :json, id: collection }
json = JSON.parse(response.body)
json_description = json['description']
expect(json_description).to eq "Deleted #{collection.id}"
end
end
end

describe "#edit" do
before { sign_in user }

Expand Down

0 comments on commit 52d3c0a

Please sign in to comment.