Add tests
This commit is contained in:
parent
b81fbb7fe6
commit
d9991f5fa7
|
@ -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
|
||||
|
|
|
@ -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,42 +41,13 @@ 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 })
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
expect { subject }.to raise_error(Pundit::NotAuthorizedError)
|
||||
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
|
Loading…
Reference in New Issue