diff --git a/app/controllers/anonymous_block_controller.rb b/app/controllers/anonymous_block_controller.rb index 80c64799..4fdda8cd 100644 --- a/app/controllers/anonymous_block_controller.rb +++ b/app/controllers/anonymous_block_controller.rb @@ -23,6 +23,8 @@ class AnonymousBlockController < ApplicationController format.turbo_stream do render turbo_stream: turbo_stream.remove("inbox_#{inbox_id}") end + + format.html { redirect_back(fallback_location: inbox_path) } end end @@ -38,6 +40,8 @@ class AnonymousBlockController < ApplicationController format.turbo_stream do render turbo_stream: turbo_stream.remove("block_#{params[:id]}") end + + format.html { redirect_back(fallback_location: settings_blocks_path) } end end end diff --git a/spec/controllers/ajax/anonymous_block_controller_spec.rb b/spec/controllers/anonymous_block_controller_spec.rb similarity index 56% rename from spec/controllers/ajax/anonymous_block_controller_spec.rb rename to spec/controllers/anonymous_block_controller_spec.rb index 689916d8..76b737cb 100644 --- a/spec/controllers/ajax/anonymous_block_controller_spec.rb +++ b/spec/controllers/anonymous_block_controller_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" -describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do +describe AnonymousBlockController, type: :controller do describe "#create" do subject { post(:create, params: params) } @@ -20,19 +20,9 @@ describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do { question: question.id } end - let(:expected_response) do - { - "success" => true, - "status" => "okay", - "message" => anything - } - end - it "creates an anonymous block" do expect { subject }.to(change { AnonymousBlock.count }.by(1)) end - - include_examples "returns the expected response" end context "when blocking a user globally" do @@ -43,14 +33,6 @@ describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do end context "as a moderator" do - let(:expected_response) do - { - "success" => true, - "status" => "okay", - "message" => anything - } - end - before do user.add_role(:moderator) end @@ -59,43 +41,14 @@ describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do expect { subject }.to(change { AnonymousBlock.count }.by(1)) expect(AnonymousBlock.last.user_id).to be_nil end - - include_examples "returns the expected response" end context "as a regular user" do - let(:expected_response) do - { - "success" => false, - "status" => "forbidden", - "message" => anything - } - end - it "does not create an anonymous block" do - expect { subject }.not_to(change { AnonymousBlock.count }) + expect { subject }.to raise_error(Pundit::NotAuthorizedError) end - - include_examples "returns the expected response" end end - - context "when parameters are missing" do - let(:params) { {} } - let(:expected_response) do - { - "success" => false, - "status" => "parameter_error", - "message" => anything - } - end - - it "does not create an anonymous block" do - expect { subject }.not_to(change { AnonymousBlock.count }) - end - - include_examples "returns the expected response" - end end end @@ -116,15 +69,11 @@ describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do { id: block.id } end - let(:expected_response) do - { - "success" => true, - "status" => "okay", - "message" => anything - } - end + it "destroys the anonymous block" do + subject - include_examples "returns the expected response" + expect(AnonymousBlock.exists?(block.id)).to eq(false) + end end end end