mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
DEV: Add per_page as public param for TopicQuery (#30716)
This change allows controllers that construct TopicQuery parameters, to pass per_page into the TopicQuery constructor as an option. I can't see why this shouldn't be a public param, so long as we properly validate the value! Internal discussion at t/145686.
This commit is contained in:

committed by
GitHub

parent
473e37e7b3
commit
a89086f799
@ -89,6 +89,24 @@ RSpec.describe TopicQuery do
|
||||
end
|
||||
end
|
||||
|
||||
describe ".validate?" do
|
||||
describe "per_page" do
|
||||
it "only allows integers 1-100" do
|
||||
# Invalid values
|
||||
expect(TopicQuery.validate?(:per_page, -1)).to eq(false)
|
||||
expect(TopicQuery.validate?(:per_page, 0)).to eq(false)
|
||||
expect(TopicQuery.validate?(:per_page, 101)).to eq(false)
|
||||
expect(TopicQuery.validate?(:per_page, "invalid")).to eq(false)
|
||||
expect(TopicQuery.validate?(:per_page, [])).to eq(false)
|
||||
|
||||
# Valid values
|
||||
expect(TopicQuery.validate?(:per_page, 1)).to eq(true)
|
||||
expect(TopicQuery.validate?(:per_page, 100)).to eq(true)
|
||||
expect(TopicQuery.validate?(:per_page, "10")).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#list_topics_by" do
|
||||
it "allows users to view their own invisible topics" do
|
||||
_topic = Fabricate(:topic, user: user)
|
||||
|
Reference in New Issue
Block a user