Remove vote method tests
This commit is contained in:
parent
5052bfb9b9
commit
840ae55198
|
@ -31,154 +31,6 @@ describe Ajax::ModerationController, :ajax_controller, type: :controller do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#vote" do
|
|
||||||
let(:params) do
|
|
||||||
{
|
|
||||||
id: report_id,
|
|
||||||
upvote: upvote
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
subject { post(:vote, params: params) }
|
|
||||||
|
|
||||||
context "when report exists" do
|
|
||||||
let(:report_id) { report.id }
|
|
||||||
let(:expected_response) do
|
|
||||||
{
|
|
||||||
"success" => true,
|
|
||||||
"status" => "okay",
|
|
||||||
"message" => anything,
|
|
||||||
"count" => expected_count
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when upvote is true" do
|
|
||||||
let(:upvote) { "true" }
|
|
||||||
let(:expected_count) { 1 }
|
|
||||||
|
|
||||||
it "creates a moderation vote" do
|
|
||||||
expect { subject }.to(change { ModerationVote.count }.by(1))
|
|
||||||
expect(report.moderation_votes.last.user).to eq(user)
|
|
||||||
expect(report.moderation_votes.last.upvote).to eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
|
||||||
|
|
||||||
context "when moderation vote already exists" do
|
|
||||||
let(:expected_response) do
|
|
||||||
{
|
|
||||||
"success" => false,
|
|
||||||
"status" => "fail",
|
|
||||||
"message" => anything
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
before { post(:vote, params: params) }
|
|
||||||
|
|
||||||
it "does not create a new moderation vote" do
|
|
||||||
expect { subject }.to_not(change { ModerationVote.count })
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when upvote is false" do
|
|
||||||
let(:upvote) { "false" }
|
|
||||||
let(:expected_count) { 0 }
|
|
||||||
|
|
||||||
it "creates a moderation vote" do
|
|
||||||
expect { subject }.to(change { ModerationVote.count }.by(1))
|
|
||||||
expect(report.moderation_votes.last.user).to eq(user)
|
|
||||||
expect(report.moderation_votes.last.upvote).to eq(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when moderation vote already exists" do
|
|
||||||
let(:expected_response) do
|
|
||||||
{
|
|
||||||
"success" => false,
|
|
||||||
"status" => "fail",
|
|
||||||
"message" => anything
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
before { post(:vote, params: params) }
|
|
||||||
|
|
||||||
it "does not create a new moderation vote" do
|
|
||||||
expect { subject }.to_not(change { ModerationVote.count })
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it_behaves_like "fails when report does not exist" do
|
|
||||||
let(:upvote) { "true" }
|
|
||||||
|
|
||||||
it "does not create a moderation vote" do
|
|
||||||
expect { subject }.to_not(change { ModerationVote.count })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#destroy_vote" do
|
|
||||||
let(:params) do
|
|
||||||
{
|
|
||||||
id: report_id
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
subject { post(:destroy_vote, params: params) }
|
|
||||||
|
|
||||||
context "when report exists" do
|
|
||||||
let(:report_id) { report.id }
|
|
||||||
let(:expected_response) do
|
|
||||||
{
|
|
||||||
"success" => true,
|
|
||||||
"status" => "okay",
|
|
||||||
"message" => anything,
|
|
||||||
"count" => expected_count
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the user already voted" do
|
|
||||||
let(:expected_count) { 0 }
|
|
||||||
|
|
||||||
before { post(:vote, params: params.merge("upvote" => true)) }
|
|
||||||
|
|
||||||
it "removes a moderation vote" do
|
|
||||||
expect { subject }.to(change { ModerationVote.count }.by(-1))
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "returns the expected response"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the user has not voted yet" do
|
|
||||||
let(:expected_count) { 0 }
|
|
||||||
let(:expected_response) do
|
|
||||||
{
|
|
||||||
"success" => false,
|
|
||||||
"status" => "fail",
|
|
||||||
"message" => anything
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not create a new moderation vote" do
|
|
||||||
expect { subject }.to_not(change { ModerationVote.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 vote" do
|
|
||||||
expect { subject }.to_not(change { ModerationVote.count })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#destroy_report" do
|
describe "#destroy_report" do
|
||||||
let(:params) do
|
let(:params) do
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue