From 26496bba8de219c9166b6a5f6ed0d584c8aeeb85 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 1 Apr 2021 18:24:26 -0500 Subject: [PATCH] posts: fix error when viewing nonexistent post IDs. --- app/views/layouts/default.html.erb | 2 +- test/functional/posts_controller_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index 6346e1ed2..b170fd51e 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -18,7 +18,7 @@ <% end %> <%# XXX hack to only load Ruffle on Flash posts %> - <% if controller_name == "posts" && action_name == "show" && @post.is_flash? %> + <% if controller_name == "posts" && action_name == "show" && @post&.is_flash? %> <%= javascript_pack_tag "application", "flash" %> <% else %> <%= javascript_pack_tag "application" %> diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index 097e03dac..bc97bc278 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -567,6 +567,14 @@ class PostsControllerTest < ActionDispatch::IntegrationTest end end + context "a nonexistent post id" do + should "return 404" do + get post_path(id: 9_999_999) + + assert_response 404 + end + end + context "with pools" do should "render the pool list" do as(@user) { @post.update(tag_string: "newpool:comic") }