Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #300 from braddunbar/object

Pass data object to rendered block.
  • Loading branch information...
commit 017c1bb86a6cda08e4e64257aa7bdeb207e45d04 2 parents b22ff37 + a895fcc
@databyte databyte authored
Showing with 16 additions and 4 deletions.
  1. +1 −1  lib/rabl/engine.rb
  2. +15 −3 test/engine_test.rb
View
2  lib/rabl/engine.rb
@@ -31,7 +31,7 @@ def render(scope, locals, &block)
else # without source location
instance_eval(@_source) if @_source.present?
end
- instance_eval(&block) if block_given?
+ instance_exec(data_object(@_data), &block) if block_given?
cache_results { self.send("to_" + @_options[:format].to_s) }
end
View
18 test/engine_test.rb
@@ -263,6 +263,18 @@
template.render(scope).split('').sort
end.equals "{\"user\":{\"name\":\"leo\",\"person\":{\"city\":\"LA\"}}}".split('').sort
+
+ asserts "that it passes the data object to the block" do
+ template = rabl %{
+ object @user
+ child(@user => :person) do |user|
+ attribute :name if user.name == 'leo'
+ end
+ }
+ scope = Object.new
+ scope.instance_variable_set :@user, User.new(:name => 'leo')
+ template.render(scope)
+ end.equals "{\"user\":{\"person\":{\"name\":\"leo\"}}}"
end
context "#glue" do
@@ -475,7 +487,7 @@
Rabl.reset_configuration!
end
end
-
+
context "without child root" do
setup do
Rabl.configure do |config|
@@ -484,9 +496,9 @@
config.enable_json_callbacks = false
end
end
-
+
context "#child" do
-
+
asserts "that it can create a child node without child root" do
template = rabl %{
child @users
Please sign in to comment.
Something went wrong with that request. Please try again.