Remove moderation comment tests
This commit is contained in:
parent
05986a124b
commit
bdf409de1f
|
@ -66,160 +66,6 @@ describe Ajax::ModerationController, :ajax_controller, type: :controller do
|
|||
it_behaves_like "fails when report does not exist"
|
||||
end
|
||||
|
||||
describe "#create_comment" do
|
||||
let(:params) do
|
||||
{
|
||||
id: report_id,
|
||||
comment: comment
|
||||
}
|
||||
end
|
||||
let(:comment) { "ZEFIX NUAMOI!" }
|
||||
|
||||
subject { post(:create_comment, params: params) }
|
||||
|
||||
context "when report exists" do
|
||||
let(:report_id) { report.id }
|
||||
let(:expected_response) do
|
||||
{
|
||||
"success" => true,
|
||||
"status" => "okay",
|
||||
"message" => anything,
|
||||
"render" => anything,
|
||||
"count" => 1
|
||||
}
|
||||
end
|
||||
|
||||
it "creates a moderation comment" do
|
||||
expect { subject }.to(change { ModerationComment.count }.by(1))
|
||||
expect(report.moderation_comments.last.user).to eq(user)
|
||||
expect(report.moderation_comments.last.content).to eq(comment)
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
|
||||
context "when comment is blank" do
|
||||
let(:comment) { "" }
|
||||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "parameter_error",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
||||
it "does not create a moderation comment" do
|
||||
expect { subject }.to_not(change { ModerationComment.count })
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
end
|
||||
|
||||
context "when comment is the letter E 621 times" do
|
||||
let(:comment) { "E" * 621 }
|
||||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "rec_inv",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
||||
it "does not create a moderation comment" do
|
||||
expect { subject }.to_not(change { ModerationComment.count })
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like "fails when report does not exist" do
|
||||
it "does not create a moderation comment" do
|
||||
expect { subject }.to_not(change { ModerationComment.count })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#destroy_comment" do
|
||||
let(:comment) { ModerationComment.create!(user: comment_user, report: report, content: "sigh") }
|
||||
let(:params) do
|
||||
{
|
||||
comment: comment_id
|
||||
}
|
||||
end
|
||||
|
||||
subject { post(:destroy_comment, params: params) }
|
||||
|
||||
context "when comment exists" do
|
||||
let(:comment_id) { comment.id }
|
||||
|
||||
before { comment }
|
||||
|
||||
context "when comment was made by the current user" do
|
||||
let(:comment_user) { user }
|
||||
let(:expected_response) do
|
||||
{
|
||||
"success" => true,
|
||||
"status" => "okay",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
||||
it "destroys the comment" do
|
||||
expect { subject }.to(change { ModerationComment.count }.by(-1))
|
||||
expect { comment.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
end
|
||||
|
||||
context "when comment was made by someone else" do
|
||||
let(:comment_user) { FactoryBot.create(:user) }
|
||||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "nopriv",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
||||
it "does not destroy the comment" do
|
||||
expect { subject }.not_to(change { ModerationComment.count })
|
||||
expect { comment.reload }.not_to raise_error
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
|
||||
context "when current user is an administrator" do
|
||||
let(:user_role) { :administrator }
|
||||
|
||||
it "does not destroy the comment" do
|
||||
expect { subject }.not_to(change { ModerationComment.count })
|
||||
expect { comment.reload }.not_to raise_error
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when comment does not exist" do
|
||||
let(:comment_id) { "Rügenwalder" }
|
||||
let(:expected_response) do
|
||||
{
|
||||
"success" => false,
|
||||
"status" => "not_found",
|
||||
"message" => anything
|
||||
}
|
||||
end
|
||||
|
||||
it "does not destroy any comment" do
|
||||
expect { subject }.not_to(change { ModerationComment.count })
|
||||
end
|
||||
|
||||
include_examples "returns the expected response"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ban" do
|
||||
let(:params) do
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue