rabl 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -1
- data/lib/rabl/builder.rb +1 -1
- data/lib/rabl/engine.rb +1 -1
- data/lib/rabl/version.rb +1 -1
- data/test/engine_test.rb +8 -3
- data/test/renderer_test.rb +9 -1
- metadata +1 -1
data/CHANGELOG.md
CHANGED
data/lib/rabl/builder.rb
CHANGED
@@ -110,7 +110,7 @@ module Rabl
|
|
110
110
|
def extends(file, options={}, &block)
|
111
111
|
options = @options.slice(:child_root).merge(:object => @_object).merge(options)
|
112
112
|
result = self.partial(file, options, &block)
|
113
|
-
@_result.merge!(result) if result
|
113
|
+
@_result.merge!(result) if result.is_a?(Hash)
|
114
114
|
end
|
115
115
|
|
116
116
|
# resolve_condition(:if => true) => true
|
data/lib/rabl/engine.rb
CHANGED
@@ -26,7 +26,7 @@ module Rabl
|
|
26
26
|
locals.each { |k,v| instance_variable_set(:"@#{k}", v) }
|
27
27
|
@_options[:scope] = @_scope
|
28
28
|
@_options[:format] ||= self.request_format
|
29
|
-
@_data = locals[:object]
|
29
|
+
@_data = locals[:object].nil? ? self.default_object : locals[:object]
|
30
30
|
if @_options[:source_location]
|
31
31
|
instance_eval(@_source, @_options[:source_location]) if @_source.present?
|
32
32
|
else # without source location
|
data/lib/rabl/version.rb
CHANGED
data/test/engine_test.rb
CHANGED
@@ -5,6 +5,13 @@ require File.expand_path('../models/ormless', __FILE__)
|
|
5
5
|
|
6
6
|
context "Rabl::Engine" do
|
7
7
|
helper(:rabl) { |t| RablTemplate.new { t } }
|
8
|
+
# context_scope 'users', [@user]
|
9
|
+
helper(:context_scope) { |name, value|
|
10
|
+
scope = Object.new
|
11
|
+
stub(scope).controller { stub(Object).controller_name { name } }
|
12
|
+
scope.instance_variable_set :"@#{name}", value
|
13
|
+
scope
|
14
|
+
}
|
8
15
|
|
9
16
|
context "#initialize" do
|
10
17
|
setup do
|
@@ -318,9 +325,7 @@ context "Rabl::Engine" do
|
|
318
325
|
template = rabl %{
|
319
326
|
attribute :name
|
320
327
|
}
|
321
|
-
scope =
|
322
|
-
stub(scope).controller { stub(Object).controller_name { "a/b/c::d/user" } }
|
323
|
-
scope.instance_variable_set :@user, User.new
|
328
|
+
scope = context_scope('user', User.new)
|
324
329
|
template.render(scope).split
|
325
330
|
end.equals "{\"name\":\"rabl\"}".split
|
326
331
|
|
data/test/renderer_test.rb
CHANGED
@@ -5,6 +5,13 @@ require File.expand_path('../teststrap', __FILE__)
|
|
5
5
|
|
6
6
|
context "Rabl::Renderer" do
|
7
7
|
helper(:tmp_path) { @tmp_path ||= Pathname.new(Dir.mktmpdir) }
|
8
|
+
# context_scope 'users', [@user]
|
9
|
+
helper(:context_scope) { |name, value|
|
10
|
+
scope = Object.new
|
11
|
+
stub(scope).controller { stub(Object).controller_name { name } }
|
12
|
+
scope.instance_variable_set :"@#{name}", value
|
13
|
+
scope
|
14
|
+
}
|
8
15
|
|
9
16
|
context "#render" do
|
10
17
|
asserts 'renders empty array' do
|
@@ -137,7 +144,8 @@ context "Rabl::Renderer" do
|
|
137
144
|
)
|
138
145
|
end
|
139
146
|
|
140
|
-
|
147
|
+
scope = context_scope('users', [User.new, User.new, User.new])
|
148
|
+
renderer = Rabl::Renderer.new('user', false, :view_path => tmp_path, :scope => scope)
|
141
149
|
JSON.parse(renderer.render)
|
142
150
|
end.equals(JSON.parse(%Q^{"foo":"baz", "baz":"bar" }^))
|
143
151
|
|