Commit 2d06b286 authored by Benjamin Neff's avatar Benjamin Neff

Handle when the block to delete doesn't exist

closes #7542
parent a4d1ad16
......@@ -12,7 +12,7 @@ class BlocksController < ApplicationController
end
def destroy
notice = if current_user.blocks.find(params[:id]).delete
notice = if current_user.blocks.find_by(id: params[:id])&.delete
{notice: t("blocks.destroy.success")}
else
{error: t("blocks.destroy.failure")}
......@@ -20,7 +20,7 @@ class BlocksController < ApplicationController
respond_to do |format|
format.json { head :no_content }
format.any { redirect_back notice.merge(fallback_location: privacy_settings_path) }
format.any { redirect_back fallback_location: privacy_settings_path, flash: notice }
end
end
......
......@@ -33,7 +33,7 @@ describe BlocksController, :type => :controller do
it "notifies the user" do
delete :destroy, params: {id: @block.id}
expect(flash).not_to be_empty
expect(flash[:notice]).to eq(I18n.t("blocks.destroy.success"))
end
it "responds with 204 with json" do
......@@ -51,6 +51,11 @@ describe BlocksController, :type => :controller do
delete :destroy, params: {id: @block.id}, format: :json
}.to change { alice.blocks.count }.by(-1)
end
it "handles when the block to delete doesn't exist" do
delete :destroy, params: {id: -1}
expect(flash[:error]).to eq(I18n.t("blocks.destroy.failure"))
end
end
describe "#disconnect_if_contact" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment