Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use a collection as the default object. Fixes #142 #467

Merged
merged 1 commit into from
Jun 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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