posts/random: fix pundit exception when no post is found.
This commit is contained in:
@@ -80,8 +80,9 @@ class PostsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def random
|
def random
|
||||||
@post = authorize Post.tag_match(params[:tags]).random
|
@post = Post.tag_match(params[:tags]).random
|
||||||
raise ActiveRecord::RecordNotFound if @post.nil?
|
raise ActiveRecord::RecordNotFound if @post.nil?
|
||||||
|
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, :tags => params[:tags]) }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -205,6 +205,11 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
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, tags: "aaaa"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "return a 404 when no random posts can be found" do
|
||||||
|
get random_posts_path, params: { tags: "qoigjegoi" }
|
||||||
|
assert_response 404
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "show action" do
|
context "show action" do
|
||||||
|
|||||||
Reference in New Issue
Block a user