Skip to content

Commit

Permalink
Respond with 404 instead of 500 when snip part does not exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
floehopper authored and lazyatom committed Dec 26, 2012
1 parent 00f8033 commit 1cabaf0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/vanilla/renderers/base.rb
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions test/pristine_app/current_snip_test.rb
Expand Up @@ -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 "<layout>{current_snip}</layout>"
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

0 comments on commit 1cabaf0

Please sign in to comment.