From b61fdec32680a2d4b32ef28b8d309d212bdd8590 Mon Sep 17 00:00:00 2001 From: ccocchi Date: Fri, 20 Jul 2012 15:14:46 +0200 Subject: [PATCH] Allow to set root_name to false in template --- lib/rabl-rails/compiler.rb | 4 ++-- test/compiler_test.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/rabl-rails/compiler.rb b/lib/rabl-rails/compiler.rb index ea291bb..7e78ea2 100644 --- a/lib/rabl-rails/compiler.rb +++ b/lib/rabl-rails/compiler.rb @@ -26,7 +26,7 @@ module RablRails # def object(data, options = {}) @template.data, @template.root_name = extract_data_and_name(data) - @template.root_name = options[:root] if options[:root] + @template.root_name = options[:root] if options.has_key? :root end alias_method :collection, :object @@ -60,7 +60,7 @@ module RablRails # def child(name_or_data, options = {}) data, name = extract_data_and_name(name_or_data) - name = options[:root] if options[:root] + name = options[:root] if options.has_key? :root if options[:partial] template = Library.instance.compile_template_from_path(options[:partial]) @template[name] = template.merge!(:_data => data) diff --git a/test/compiler_test.rb b/test/compiler_test.rb index 493e4e6..b9f8fcc 100644 --- a/test/compiler_test.rb +++ b/test/compiler_test.rb @@ -42,6 +42,11 @@ class CompilerTest < ActiveSupport::TestCase assert_equal :@user, t.data assert_equal :users, t.root_name end + + test "root can be set to false via options" do + t = @compiler.compile_source(%( object :@user, root: false)) + assert_equal false, t.root_name + end # Compilation