Skip to content

Commit

Permalink
Do not use a collection as the default object. Fixes nesquena#142
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbrdo authored and simsalabim committed Nov 15, 2013
1 parent 5ed7091 commit bb7b5bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rabl/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ def default_object
if context_scope.respond_to?(:controller)
controller_name = context_scope.controller.controller_name
stripped_name = controller_name.split(%r{::|\/}).last
instance_variable_get("@#{stripped_name}")
object = instance_variable_get("@#{stripped_name}")
is_object?(object) ? object : nil
end
end

Expand Down
8 changes: 8 additions & 0 deletions test/engine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@
template.render(scope).split
end.equals "{\"name\":\"rabl\"}".split

asserts "that it does not set a collection as default object" do
template = rabl %{
attribute :name
}
scope = context_scope('user', [])
template.render(scope).split
end.equals "{}".split

asserts "that it sets data source" do
template = rabl %q{
object @user
Expand Down

0 comments on commit bb7b5bb

Please sign in to comment.