mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 10:09:53 +01:00
Add specs for Moderation::ReportsController
This commit is contained in:
parent
baa1f3f319
commit
c3d14c6786
1 changed files with 107 additions and 6 deletions
|
@ -6,15 +6,116 @@ describe Moderation::ReportsController, type: :controller do
|
|||
let(:user) { FactoryBot.create :user, roles: ["moderator"] }
|
||||
|
||||
describe "#index" do
|
||||
subject { get :index }
|
||||
shared_examples_for "sets the expected ivars" do
|
||||
let(:expected_assigns) { {} }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
it "sets the expected ivars" do
|
||||
subject
|
||||
|
||||
expected_assigns.each do |name, value|
|
||||
expect(assigns[name]).to eq(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "renders the moderation/reports/index template" do
|
||||
subject
|
||||
expect(response).to render_template("moderation/reports/index")
|
||||
context "template rendering" do
|
||||
let(:other_user) { FactoryBot.create :user }
|
||||
let(:report) { Report.create(user:, target_id: other_user.id, type: "Reports::User") }
|
||||
|
||||
subject { get :index }
|
||||
|
||||
before do
|
||||
report
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it "renders the moderation/reports/index template" do
|
||||
subject
|
||||
expect(response).to render_template("moderation/reports/index")
|
||||
end
|
||||
|
||||
include_examples "sets the expected ivars" do
|
||||
let(:expected_assigns) do
|
||||
{
|
||||
reports: [report],
|
||||
reports_last_id: report.id,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "filtering for target users" do
|
||||
let(:other_user) { FactoryBot.create :user }
|
||||
let(:question) { FactoryBot.create :question }
|
||||
let(:report) { Report.create(user:, target_id: other_user.id, target_user_id: other_user.id, type: "Reports::User") }
|
||||
let(:report2) { Report.create(user:, target_id: question.id, target_user_id: nil, type: "Reports::Question") }
|
||||
|
||||
subject { get :index, params: { target_user: other_user.screen_name } }
|
||||
|
||||
before do
|
||||
report
|
||||
report2
|
||||
sign_in user
|
||||
end
|
||||
|
||||
include_examples "sets the expected ivars" do
|
||||
let(:expected_assigns) do
|
||||
{
|
||||
reports: [report],
|
||||
reports_last_id: report.id,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "filtering for users" do
|
||||
let(:report_user) { FactoryBot.create :user }
|
||||
let(:other_user) { FactoryBot.create :user }
|
||||
let(:question) { FactoryBot.create :question }
|
||||
let(:report) { Report.create(user:, target_id: other_user.id, target_user_id: other_user.id, type: "Reports::User") }
|
||||
let(:report2) { Report.create(user: report_user, target_id: question.id, target_user_id: nil, type: "Reports::Question") }
|
||||
|
||||
subject { get :index, params: { user: report_user.screen_name } }
|
||||
|
||||
before do
|
||||
report
|
||||
report2
|
||||
sign_in user
|
||||
end
|
||||
|
||||
include_examples "sets the expected ivars" do
|
||||
let(:expected_assigns) do
|
||||
{
|
||||
reports: [report2],
|
||||
reports_last_id: report2.id,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "filtering for type" do
|
||||
let(:report_user) { FactoryBot.create :user }
|
||||
let(:other_user) { FactoryBot.create :user }
|
||||
let(:question) { FactoryBot.create :question }
|
||||
let(:report) { Report.create(user:, target_id: other_user.id, target_user_id: other_user.id, type: "Reports::User") }
|
||||
let(:report2) { Report.create(user: report_user, target_id: question.id, target_user_id: nil, type: "Reports::Question") }
|
||||
|
||||
subject { get :index, params: { type: "question" } }
|
||||
|
||||
before do
|
||||
report
|
||||
report2
|
||||
sign_in user
|
||||
end
|
||||
|
||||
include_examples "sets the expected ivars" do
|
||||
let(:expected_assigns) do
|
||||
{
|
||||
reports: [report2],
|
||||
reports_last_id: report2.id,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue