posts: fix /posts/random?tags=... redirect.

Fix /posts/random?tags=touhou to redirect to /posts/1234?q=touhou instead of /posts/1234?tags=touhou.

Fixes the search bar on random posts not containing the current search.
This commit is contained in:
evazion
2022-11-15 19:34:27 -06:00
parent bc169fc98c
commit d791924aad
2 changed files with 3 additions and 3 deletions

View File

@@ -132,7 +132,7 @@ class PostsController < ApplicationController
raise ActiveRecord::RecordNotFound if @post.nil? raise ActiveRecord::RecordNotFound if @post.nil?
authorize @post authorize @post
respond_with(@post) do |format| respond_with(@post) do |format|
format.html { redirect_to post_path(@post, :tags => params[:tags]) } format.html { redirect_to post_path(@post, q: params[:tags]) }
end end
end end

View File

@@ -498,14 +498,14 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
context "random action" do context "random action" do
should "render" do should "render" do
get random_posts_path, params: { tags: "aaaa" } get random_posts_path, params: { tags: "aaaa" }
assert_redirected_to(post_path(@post, tags: "aaaa")) assert_redirected_to(post_path(@post, q: "aaaa"))
end end
should "render for a ordfav: search" do should "render for a ordfav: search" do
@post = as(@user) { create(:post, tag_string: "fav:me") } @post = as(@user) { create(:post, tag_string: "fav:me") }
get random_posts_path, params: { tags: "ordfav:#{@user.name}" } get random_posts_path, params: { tags: "ordfav:#{@user.name}" }
assert_redirected_to(post_path(@post, tags: "ordfav:#{@user.name}")) assert_redirected_to(post_path(@post, q: "ordfav:#{@user.name}"))
end end
should "return a 404 when no random posts can be found" do should "return a 404 when no random posts can be found" do