Add tests
This commit is contained in:
parent
b81fbb7fe6
commit
d9991f5fa7
|
@ -23,6 +23,8 @@ class AnonymousBlockController < ApplicationController
|
||||||
format.turbo_stream do
|
format.turbo_stream do
|
||||||
render turbo_stream: turbo_stream.remove("inbox_#{inbox_id}")
|
render turbo_stream: turbo_stream.remove("inbox_#{inbox_id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
format.html { redirect_back(fallback_location: inbox_path) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,6 +40,8 @@ class AnonymousBlockController < ApplicationController
|
||||||
format.turbo_stream do
|
format.turbo_stream do
|
||||||
render turbo_stream: turbo_stream.remove("block_#{params[:id]}")
|
render turbo_stream: turbo_stream.remove("block_#{params[:id]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
format.html { redirect_back(fallback_location: settings_blocks_path) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do
|
describe AnonymousBlockController, type: :controller do
|
||||||
describe "#create" do
|
describe "#create" do
|
||||||
subject { post(:create, params: params) }
|
subject { post(:create, params: params) }
|
||||||
|
|
||||||
|
@ -20,19 +20,9 @@ describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do
|
||||||
{ question: question.id }
|
{ question: question.id }
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:expected_response) do
|
|
||||||
{
|
|
||||||
"success" => true,
|
|
||||||
"status" => "okay",
|
|
||||||
"message" => anything
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
it "creates an anonymous block" do
|
it "creates an anonymous block" do
|
||||||
expect { subject }.to(change { AnonymousBlock.count }.by(1))
|
expect { subject }.to(change { AnonymousBlock.count }.by(1))
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when blocking a user globally" do
|
context "when blocking a user globally" do
|
||||||
|
@ -43,14 +33,6 @@ describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "as a moderator" do
|
context "as a moderator" do
|
||||||
let(:expected_response) do
|
|
||||||
{
|
|
||||||
"success" => true,
|
|
||||||
"status" => "okay",
|
|
||||||
"message" => anything
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
user.add_role(:moderator)
|
user.add_role(:moderator)
|
||||||
end
|
end
|
||||||
|
@ -59,43 +41,14 @@ describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do
|
||||||
expect { subject }.to(change { AnonymousBlock.count }.by(1))
|
expect { subject }.to(change { AnonymousBlock.count }.by(1))
|
||||||
expect(AnonymousBlock.last.user_id).to be_nil
|
expect(AnonymousBlock.last.user_id).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "as a regular user" do
|
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
|
it "does not create an anonymous block" do
|
||||||
expect { subject }.not_to(change { AnonymousBlock.count })
|
expect { subject }.to raise_error(Pundit::NotAuthorizedError)
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -116,15 +69,11 @@ describe Ajax::AnonymousBlockController, :ajax_controller, type: :controller do
|
||||||
{ id: block.id }
|
{ id: block.id }
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:expected_response) do
|
it "destroys the anonymous block" do
|
||||||
{
|
subject
|
||||||
"success" => true,
|
|
||||||
"status" => "okay",
|
|
||||||
"message" => anything
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
expect(AnonymousBlock.exists?(block.id)).to eq(false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue