Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/staff_taggings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def update
def destroy
authorize! @staff_tagging
@staff_tagging.destroy
redirect_to staff_taggings_path, notice: "Staff tagging was successfully removed.", status: :see_other
redirect_to staff_tagging_return_path, notice: "Staff tagging was successfully removed.", status: :see_other
end

def toggle_marked
Expand Down
6 changes: 4 additions & 2 deletions app/views/staff_taggings/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@

<div class="mt-8 flex flex-wrap justify-center gap-3">
<% if allowed_to?(:destroy?, @staff_tagging) %>
<%= link_to "Remove tagging", staff_tagging_path(@staff_tagging), class: button_classes(:danger_outline),
data: { turbo_method: :delete, turbo_confirm: "Remove this tag from #{taggable&.name}?" } %>
<%= link_to "Remove tagging",
staff_tagging_path(@staff_tagging, return_to: params[:return_to].presence, origin_id: params[:origin_id].presence, admin: params[:admin].presence),
class: button_classes(:danger_outline),
data: { turbo: true, turbo_method: :delete, turbo_confirm: "Remove this tag from #{taggable&.name}?" } %>
<% end %>
<%= link_to "Cancel", back_path, class: button_classes(:secondary_outline) %>
<%= f.button :submit, "Save changes", class: button_classes(:primary) %>
Expand Down
21 changes: 19 additions & 2 deletions spec/requests/staff_taggings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,30 @@
describe "DELETE /staff_taggings/:id" do
before { sign_in admin }

it "removes a tagging" do
it "removes a tagging and returns to the staff taggings list" do
tagging = create(:staff_tagging)

expect {
delete staff_tagging_path(tagging)
delete staff_tagging_path(tagging, return_to: "staff_taggings")
}.to change(StaffTagging, :count).by(-1)
expect(response).to redirect_to(staff_taggings_path)
end

it "returns to the staff tag it was removed from" do
tagging = create(:staff_tagging)

delete staff_tagging_path(tagging, return_to: "staff_tag")

expect(response).to redirect_to(staff_tag_path(tagging.staff_tag))
end

it "returns to the person's edit page by default" do
person = create(:person)
tagging = create(:staff_tagging, staff_taggable: person)

delete staff_tagging_path(tagging)

expect(response).to redirect_to(edit_person_path(person, anchor: "staff_tagging_#{tagging.id}"))
end
end
end
18 changes: 18 additions & 0 deletions spec/system/staff_tagging_removal_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "rails_helper"

RSpec.describe "Removing a staff tagging", type: :system, js: true do
let(:admin) { create(:user, :admin) }
let(:person) { create(:person, first_name: "Alma", last_name: "Alphason") }
let!(:tagging) { create(:staff_tagging, staff_taggable: person) }

before { sign_in admin }

it "deletes the tagging from its edit page" do
visit edit_staff_tagging_path(tagging, return_to: "staff_taggings")

accept_confirm { click_link "Remove tagging" }

expect(page).to have_content("Staff tagging was successfully removed.")
expect(StaffTagging.exists?(tagging.id)).to be(false)
end
end
Loading