From 52d3c0a03c11ac3fc0dc6cf3f7a8bb15142b2283 Mon Sep 17 00:00:00 2001 From: "Michael J. Giarlo" Date: Mon, 23 Jan 2017 15:52:10 -0800 Subject: [PATCH] =?UTF-8?q?Quick=20na=C3=AFve=20attempt=20to=20fix=20redir?= =?UTF-8?q?ects=20after=20deleting=20collections.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2858. Based on #3014 and psu-stewardship/scholarsphere#401, thanks to @hortongn and @awead. --- .../sufia/collections_controller_behavior.rb | 7 +++++++ .../controllers/collections_controller_spec.rb | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/controllers/concerns/sufia/collections_controller_behavior.rb b/app/controllers/concerns/sufia/collections_controller_behavior.rb index f70587ae37..dd3ee2f577 100644 --- a/app/controllers/concerns/sufia/collections_controller_behavior.rb +++ b/app/controllers/concerns/sufia/collections_controller_behavior.rb @@ -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 diff --git a/spec/controllers/collections_controller_spec.rb b/spec/controllers/collections_controller_spec.rb index 6b1a8e2936..5d82de401e 100644 --- a/spec/controllers/collections_controller_spec.rb +++ b/spec/controllers/collections_controller_spec.rb @@ -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 }