mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 04:38:47 +08:00
DEV: Apply syntax_tree formatting to spec/*
This commit is contained in:
@ -5,19 +5,24 @@ RSpec.describe Admin::ReportsController do
|
||||
fab!(:moderator) { Fabricate(:moderator) }
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
describe '#bulk' do
|
||||
describe "#bulk" do
|
||||
context "when logged in as an admin" do
|
||||
before { sign_in(admin) }
|
||||
|
||||
context "with valid params" do
|
||||
it "renders the reports as JSON" do
|
||||
Fabricate(:topic)
|
||||
get "/admin/reports/bulk.json", params: {
|
||||
reports: {
|
||||
topics: { limit: 10 },
|
||||
likes: { limit: 10 }
|
||||
}
|
||||
}
|
||||
get "/admin/reports/bulk.json",
|
||||
params: {
|
||||
reports: {
|
||||
topics: {
|
||||
limit: 10,
|
||||
},
|
||||
likes: {
|
||||
limit: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["reports"].count).to eq(2)
|
||||
@ -27,12 +32,17 @@ RSpec.describe Admin::ReportsController do
|
||||
context "with invalid params" do
|
||||
context "with nonexistent report" do
|
||||
it "returns not found reports" do
|
||||
get "/admin/reports/bulk.json", params: {
|
||||
reports: {
|
||||
topics: { limit: 10 },
|
||||
not_found: { limit: 10 }
|
||||
}
|
||||
}
|
||||
get "/admin/reports/bulk.json",
|
||||
params: {
|
||||
reports: {
|
||||
topics: {
|
||||
limit: 10,
|
||||
},
|
||||
not_found: {
|
||||
limit: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["reports"].count).to eq(2)
|
||||
@ -43,18 +53,26 @@ RSpec.describe Admin::ReportsController do
|
||||
|
||||
context "with invalid start or end dates" do
|
||||
it "doesn't return 500 error" do
|
||||
get "/admin/reports/bulk.json", params: {
|
||||
reports: {
|
||||
topics: { limit: 10, start_date: "2015-0-1" }
|
||||
}
|
||||
}
|
||||
get "/admin/reports/bulk.json",
|
||||
params: {
|
||||
reports: {
|
||||
topics: {
|
||||
limit: 10,
|
||||
start_date: "2015-0-1",
|
||||
},
|
||||
},
|
||||
}
|
||||
expect(response.status).to eq(400)
|
||||
|
||||
get "/admin/reports/bulk.json", params: {
|
||||
reports: {
|
||||
topics: { limit: 10, end_date: "2015-0-1" }
|
||||
}
|
||||
}
|
||||
get "/admin/reports/bulk.json",
|
||||
params: {
|
||||
reports: {
|
||||
topics: {
|
||||
limit: 10,
|
||||
end_date: "2015-0-1",
|
||||
},
|
||||
},
|
||||
}
|
||||
expect(response.status).to eq(400)
|
||||
end
|
||||
end
|
||||
@ -67,12 +85,17 @@ RSpec.describe Admin::ReportsController do
|
||||
it "returns report" do
|
||||
Fabricate(:topic)
|
||||
|
||||
get "/admin/reports/bulk.json", params: {
|
||||
reports: {
|
||||
topics: { limit: 10 },
|
||||
likes: { limit: 10 }
|
||||
}
|
||||
}
|
||||
get "/admin/reports/bulk.json",
|
||||
params: {
|
||||
reports: {
|
||||
topics: {
|
||||
limit: 10,
|
||||
},
|
||||
likes: {
|
||||
limit: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.parsed_body["reports"].count).to eq(2)
|
||||
@ -80,15 +103,20 @@ RSpec.describe Admin::ReportsController do
|
||||
end
|
||||
|
||||
context "when logged in as a non-staff user" do
|
||||
before { sign_in(user) }
|
||||
before { sign_in(user) }
|
||||
|
||||
it "denies access with a 404 response" do
|
||||
get "/admin/reports/bulk.json", params: {
|
||||
reports: {
|
||||
topics: { limit: 10 },
|
||||
not_found: { limit: 10 }
|
||||
}
|
||||
}
|
||||
get "/admin/reports/bulk.json",
|
||||
params: {
|
||||
reports: {
|
||||
topics: {
|
||||
limit: 10,
|
||||
},
|
||||
not_found: {
|
||||
limit: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(response.status).to eq(404)
|
||||
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
|
||||
@ -96,7 +124,7 @@ RSpec.describe Admin::ReportsController do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
describe "#show" do
|
||||
context "when logged in as an admin" do
|
||||
before { sign_in(admin) }
|
||||
|
||||
@ -110,14 +138,14 @@ RSpec.describe Admin::ReportsController do
|
||||
end
|
||||
|
||||
context "with valid type form" do
|
||||
context 'with missing report' do
|
||||
context "with missing report" do
|
||||
it "returns a 404 error" do
|
||||
get "/admin/reports/nonexistent.json"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a report is found' do
|
||||
context "when a report is found" do
|
||||
it "renders the report as JSON" do
|
||||
Fabricate(:topic)
|
||||
get "/admin/reports/topics.json"
|
||||
@ -128,29 +156,29 @@ RSpec.describe Admin::ReportsController do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when report is scoped to a category' do
|
||||
describe "when report is scoped to a category" do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:other_topic) { Fabricate(:topic) }
|
||||
|
||||
it 'should render the report as JSON' do
|
||||
it "should render the report as JSON" do
|
||||
get "/admin/reports/topics.json", params: { category_id: category.id }
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
report = response.parsed_body["report"]
|
||||
|
||||
expect(report["type"]).to eq('topics')
|
||||
expect(report["type"]).to eq("topics")
|
||||
expect(report["data"].count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when report is scoped to a group' do
|
||||
describe "when report is scoped to a group" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:other_user) { Fabricate(:user) }
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
|
||||
it 'should render the report as JSON' do
|
||||
it "should render the report as JSON" do
|
||||
group.add(user)
|
||||
|
||||
get "/admin/reports/signups.json", params: { group_id: group.id }
|
||||
@ -159,14 +187,14 @@ RSpec.describe Admin::ReportsController do
|
||||
|
||||
report = response.parsed_body["report"]
|
||||
|
||||
expect(report["type"]).to eq('signups')
|
||||
expect(report["type"]).to eq("signups")
|
||||
expect(report["data"].count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in as a moderator" do
|
||||
before { sign_in(moderator) }
|
||||
before { sign_in(moderator) }
|
||||
|
||||
it "returns report" do
|
||||
Fabricate(:topic)
|
||||
@ -179,7 +207,7 @@ RSpec.describe Admin::ReportsController do
|
||||
end
|
||||
|
||||
context "when logged in as a non-staff user" do
|
||||
before { sign_in(user) }
|
||||
before { sign_in(user) }
|
||||
|
||||
it "denies access with a 404 response" do
|
||||
get "/admin/reports/topics.json"
|
||||
|
Reference in New Issue
Block a user