Skip to content

Commit

Permalink
Merge pull request #467 from mrbrdo/default_object_fix
Browse files Browse the repository at this point in the history
Do not use a collection as the default object. Fixes #142
  • Loading branch information
nesquena committed Jun 19, 2013
2 parents 67fcbe9 + c7be10c commit e61ae73
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 e61ae73

Please sign in to comment.