search: make order:random truly random; add random:N metatag.
Make the `order:random` metatag truly randomize the search. Add a `random:N` metatag that returns up to N random posts, like what `order:random` did before. `order:random` now returns the entire search in random order. Before it just returned a pageful of pseudorandom posts. This will be more accurate for small searches, but slower for large searches. If `order:random` times out, try `random:N` instead. The `random:N` metatag returns up to N pseudorandom posts. This is faster than `order:random` for large searches, but for small searches, it may return less than N posts, and the randomness may be biased. Some posts may be more likely than others to appear. N must be between 0 and 200. Also, `/posts?tags=touhou&random=1` now redirects to `/posts?tags=touhou+random:N`. Before the `random=1` param acted like a free `order:random` tag; now it redirects to a `random:N` search, so it counts against your tag limit.
This commit is contained in:
@@ -309,18 +309,21 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
get posts_path, params: { tags: "order:random" }
|
||||
assert_response :success
|
||||
|
||||
get posts_path, params: { random: "1" }
|
||||
assert_response :success
|
||||
get posts_path(random: "1")
|
||||
assert_redirected_to posts_path(tags: "random:20", format: :html)
|
||||
|
||||
get posts_path(format: :json), params: { random: "1" }
|
||||
assert_response :success
|
||||
get posts_path(random: "1"), as: :json
|
||||
assert_redirected_to posts_path(tags: "random:20", format: :json)
|
||||
|
||||
get posts_path(tags: "touhou", random: "true")
|
||||
assert_redirected_to posts_path(tags: "touhou random:20", format: :html)
|
||||
end
|
||||
|
||||
should "render with multiple posts" do
|
||||
@posts = create_list(:post, 2)
|
||||
|
||||
get posts_path, params: { random: "1" }
|
||||
assert_response :success
|
||||
get posts_path(random: "1")
|
||||
assert_redirected_to posts_path(tags: "random:20", format: :html)
|
||||
end
|
||||
|
||||
should "return all posts for a .json response" do
|
||||
|
||||
Reference in New Issue
Block a user