parent
a4d1ad160c
commit
2d06b2865f
2 changed files with 8 additions and 3 deletions
|
|
@ -12,7 +12,7 @@ class BlocksController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
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")}
|
{notice: t("blocks.destroy.success")}
|
||||||
else
|
else
|
||||||
{error: t("blocks.destroy.failure")}
|
{error: t("blocks.destroy.failure")}
|
||||||
|
|
@ -20,7 +20,7 @@ class BlocksController < ApplicationController
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { head :no_content }
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ describe BlocksController, :type => :controller do
|
||||||
|
|
||||||
it "notifies the user" do
|
it "notifies the user" do
|
||||||
delete :destroy, params: {id: @block.id}
|
delete :destroy, params: {id: @block.id}
|
||||||
expect(flash).not_to be_empty
|
expect(flash[:notice]).to eq(I18n.t("blocks.destroy.success"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "responds with 204 with json" do
|
it "responds with 204 with json" do
|
||||||
|
|
@ -51,6 +51,11 @@ describe BlocksController, :type => :controller do
|
||||||
delete :destroy, params: {id: @block.id}, format: :json
|
delete :destroy, params: {id: @block.id}, format: :json
|
||||||
}.to change { alice.blocks.count }.by(-1)
|
}.to change { alice.blocks.count }.by(-1)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "#disconnect_if_contact" do
|
describe "#disconnect_if_contact" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue