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 RablRails
module Renderer module Renderer
class TemplateNotFound < StandardError; end
mattr_reader :view_path mattr_reader :view_path
@@view_path = 'app/views' @@view_path = 'app/views'
@ -71,6 +73,7 @@ module RablRails
c.target_object = object c.target_object = object
t = c.lookup_context.find_template(template, [], false) t = c.lookup_context.find_template(template, [], false)
raise TemplateNotFound unless t
Library.instance.get_rendered_template(t.source, c) Library.instance.get_rendered_template(t.source, c)
end 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) assert_equal %q({"user":{"id":1,"name":"Marty"}}), RablRails.render(@user, 'show', view_path: @tmp_path)
end 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 test "handle path for extends" do
File.open(@tmp_path + "extend.json.rabl", "w") do |f| File.open(@tmp_path + "extend.json.rabl", "w") do |f|
f.puts %q{ f.puts %q{