From 1cabaf0f60996bd841ab9caa7b6bfdfdcc33a995 Mon Sep 17 00:00:00 2001 From: James Mead Date: Thu, 13 Sep 2012 22:02:06 +0100 Subject: [PATCH] Respond with 404 instead of 500 when snip part does not exist. --- lib/vanilla/renderers/base.rb | 7 ++++++- test/pristine_app/current_snip_test.rb | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/vanilla/renderers/base.rb b/lib/vanilla/renderers/base.rb index 11b23b0..e4a7db7 100644 --- a/lib/vanilla/renderers/base.rb +++ b/lib/vanilla/renderers/base.rb @@ -95,7 +95,12 @@ def prepare(snip, part, args, enclosing_snip) end def render_without_including_snips(snip, part=:content) - process_text(raw_content(snip, part)) + if content = raw_content(snip, part) + process_text(content) + else + app.response.status = 404 + %{Couldn't find part "#{part}" for snip "#{snip.name}"} + end end # Handles processing the text of the content. diff --git a/test/pristine_app/current_snip_test.rb b/test/pristine_app/current_snip_test.rb index e2dc3a0..312f63b 100644 --- a/test/pristine_app/current_snip_test.rb +++ b/test/pristine_app/current_snip_test.rb @@ -54,4 +54,21 @@ assert_equal 404, page.status_code end end + + context "when the requested part of a snip is missing" do + setup do + set_main_template "{current_snip}" + create_snip :name => "test", :content => "test" + + visit "/test/monkey" + end + + should "render an explanatory message" do + assert page.has_content?(%{Couldn't find part "monkey" for snip "test"}) + end + + should "set the response code to 404" do + assert_equal 404, page.status_code + end + end end \ No newline at end of file