posts index: clean up limit:<n> / order:random parsing (#2894)
* Move the limit:<n> / order:random metatag parsing from the controller to the post set. * Introduce `Tag.has_metatag?` and use it to parse these metatags instead of using a regex (#2894).
This commit is contained in:
@@ -89,6 +89,16 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to(@post)
|
||||
end
|
||||
end
|
||||
|
||||
context "with a random search" do
|
||||
should "render" do
|
||||
get posts_path, params: { tags: "order:random" }
|
||||
assert_response :success
|
||||
|
||||
get posts_path, params: { random: "1" }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "show_seq action" do
|
||||
|
||||
@@ -161,6 +161,19 @@ module PostSets
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#per_page method" do
|
||||
should "take the limit from the params first, then the limit:<n> metatag, then the account settings" do
|
||||
set = PostSets::Post.new("a limit:23 b", 1, 42)
|
||||
assert_equal(42, set.per_page)
|
||||
|
||||
set = PostSets::Post.new("a limit:23 b", 1, nil)
|
||||
assert_equal(23, set.per_page)
|
||||
|
||||
set = PostSets::Post.new("a", 1, nil)
|
||||
assert_equal(CurrentUser.user.per_page, set.per_page)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user