Raise error when template is not found

This commit is contained in:
ccocchi 2012-07-26 14:59:28 +02:00
parent d4c434e6b0
commit b42f63788f
2 changed files with 7 additions and 0 deletions

View File

@ -3,6 +3,8 @@ require 'rabl-rails/renderers/json'
module RablRails
module Renderer
class TemplateNotFound < StandardError; end
mattr_reader :view_path
@@view_path = 'app/views'
@ -71,6 +73,7 @@ module RablRails
c.target_object = object
t = c.lookup_context.find_template(template, [], false)
raise TemplateNotFound unless t
Library.instance.get_rendered_template(t.source, c)
end

View File

@ -32,6 +32,10 @@ class RenderTest < ActiveSupport::TestCase
assert_equal %q({"user":{"id":1,"name":"Marty"}}), RablRails.render(@user, 'show', view_path: @tmp_path)
end
test "raise error if template is not found" do
assert_raises(RablRails::Renderer::TemplateNotFound) { RablRails.render(@user, 'show') }
end
test "handle path for extends" do
File.open(@tmp_path + "extend.json.rabl", "w") do |f|
f.puts %q{