From fbcbbd2328eec224758d9ce2c82122ad410280d5 Mon Sep 17 00:00:00 2001 From: ccocchi Date: Fri, 2 Mar 2012 14:59:01 +0100 Subject: [PATCH] Add root option for collection --- lib/rabl-fast-json/compiler.rb | 2 +- test/compiler_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rabl-fast-json/compiler.rb b/lib/rabl-fast-json/compiler.rb index dd0be68..ea15181 100644 --- a/lib/rabl-fast-json/compiler.rb +++ b/lib/rabl-fast-json/compiler.rb @@ -52,8 +52,8 @@ module RablFastJson alias_method :code, :node def collection(data, options = {}) - @template.root_name = options[:root] if root_given?(options) object(data) + @template.root_name = options[:root] if root_given?(options) end def extends(path) diff --git a/test/compiler_test.rb b/test/compiler_test.rb index 0265775..41750c9 100644 --- a/test/compiler_test.rb +++ b/test/compiler_test.rb @@ -103,6 +103,12 @@ class CompilerTest < ActiveSupport::TestCase assert_equal :users, t.root_name end + test "collection property can define root name via options" do + t = @compiler.compile_source(%{ collection :@user, :root => :users }) + assert_equal :@user, t.data + assert_equal :users, t.root_name + end + test "extends use other template source as itself" do template = mock('template', :source => { :id => :id }) RablFastJson::Library.reset_instance