ensure that child usage does not manipulate cached template

This commit is contained in:
John Bintz 2013-01-22 14:16:44 -05:00
parent 297f8a9145
commit cb53352607
5 changed files with 8 additions and 7 deletions

View File

@ -67,7 +67,7 @@ module RablRails
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)
@template[name] = template.merge(:_data => data)
elsif block_given?
@template[name] = sub_compile(data) { yield }
end
@ -161,4 +161,4 @@ module RablRails
@template = old_template
end
end
end
end

View File

@ -33,4 +33,4 @@ module RablRails
compile_template_from_source(t.source, path)
end
end
end
end

View File

@ -129,4 +129,4 @@ module RablRails
end
end
end
end
end

View File

@ -2,10 +2,10 @@ module RablRails
class CompiledTemplate
attr_accessor :source, :data, :root_name
delegate :[], :[]=, :merge!, :to => :source
delegate :[], :[]=, :merge!, :merge, :to => :source
def initialize
@source = {}
end
end
end
end

View File

@ -113,6 +113,7 @@ class CompilerTest < ActiveSupport::TestCase
t = @compiler.compile_source(%{child(:user, :partial => 'users/base') })
assert_equal( {:user => { :_data => :user, :id => :id } }, t.source)
assert_equal( {:id => :id}, mock_template.source)
end
test "glue is compiled as a child but with anonymous name" do
@ -188,4 +189,4 @@ class CompilerTest < ActiveSupport::TestCase
assert_equal [:users, :users], @compiler.send(:extract_data_and_name, :users)
assert_equal [:@users, :authors], @compiler.send(:extract_data_and_name, :@users => :authors)
end
end
end