Use explicit error
This commit is contained in:
parent
4e6142602f
commit
e1e5ec6f23
|
@ -1,5 +1,7 @@
|
||||||
module RablFastJson
|
module RablFastJson
|
||||||
module Renderers
|
module Renderers
|
||||||
|
class PartialError < StandardError; end
|
||||||
|
|
||||||
class Base
|
class Base
|
||||||
|
|
||||||
def initialize(context) # :nodoc:
|
def initialize(context) # :nodoc:
|
||||||
|
@ -79,7 +81,7 @@ module RablFastJson
|
||||||
# rendering time.
|
# rendering time.
|
||||||
#
|
#
|
||||||
def partial(template_path, options = {})
|
def partial(template_path, options = {})
|
||||||
raise "No object was given to partial" unless options[:object]
|
raise PartialError.new("No object was given to partial") unless options[:object]
|
||||||
object = options[:object]
|
object = options[:object]
|
||||||
|
|
||||||
return [] if object.respond_to?(:empty?) && object.empty?
|
return [] if object.respond_to?(:empty?) && object.empty?
|
||||||
|
|
|
@ -98,7 +98,7 @@ class TestJsonRenderer < ActiveSupport::TestCase
|
||||||
@template.data = false
|
@template.data = false
|
||||||
@template.source = { :user => ->(s) { partial('users/base') } }
|
@template.source = { :user => ->(s) { partial('users/base') } }
|
||||||
|
|
||||||
assert_raises(RuntimeError) { render_json_output }
|
assert_raises(RablFastJson::Renderers::PartialError) { render_json_output }
|
||||||
end
|
end
|
||||||
|
|
||||||
test "partial with empty values should not raise an error" do
|
test "partial with empty values should not raise an error" do
|
||||||
|
|
Loading…
Reference in New Issue