From dbfd6185f1017e1af0c598d5431054630d5fda04 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 13 Aug 2019 21:30:21 -0500 Subject: [PATCH] posts: fix error on /posts?md5=. --- app/controllers/posts_controller.rb | 2 +- test/functional/posts_controller_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index c69cb898b..c87fe15c6 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -4,7 +4,7 @@ class PostsController < ApplicationController def index if params[:md5].present? - @post = Post.find_by_md5(params[:md5]) + @post = Post.find_by!(md5: params[:md5]) respond_with(@post) do |format| format.html { redirect_to(@post) } end diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index 0952bdcfa..8b6d87c82 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -132,6 +132,11 @@ class PostsControllerTest < ActionDispatch::IntegrationTest get posts_path, params: { md5: @post.md5 } assert_redirected_to(@post) end + + should "return error on nonexistent md5" do + get posts_path(md5: "foo") + assert_response 404 + end end context "with a random search" do