Add tests

This commit is contained in:
Andreas Nedbal 2022-11-21 23:05:04 +01:00
parent b81fbb7fe6
commit d9991f5fa7
2 changed files with 10 additions and 57 deletions

View File

@ -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

View File

@ -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