Dup the template to avoid in place modification across users
This commit is contained in:
parent
e30e5dd66a
commit
3c7448ebfd
|
@ -23,6 +23,7 @@ module RablFastJson
|
||||||
def get_compiled_template(path, source)
|
def get_compiled_template(path, source)
|
||||||
if path && RablFastJson.cache_templates?
|
if path && RablFastJson.cache_templates?
|
||||||
@cached_templates[path] ||= Compiler.new.compile_source(source)
|
@cached_templates[path] ||= Compiler.new.compile_source(source)
|
||||||
|
@cached_templates[path].dup
|
||||||
else
|
else
|
||||||
Compiler.new.compile_source(source)
|
Compiler.new.compile_source(source)
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,8 +10,19 @@ class CacheTemplatesTest < ActiveSupport::TestCase
|
||||||
test "cache templates if perform_caching is active and cache_templates is enabled" do
|
test "cache templates if perform_caching is active and cache_templates is enabled" do
|
||||||
RablFastJson.cache_templates = true
|
RablFastJson.cache_templates = true
|
||||||
ActionController::Base.stub(:perform_caching).and_return(true)
|
ActionController::Base.stub(:perform_caching).and_return(true)
|
||||||
|
@library.get_compiled_template('some/path', "")
|
||||||
|
t = @library.get_compiled_template('some/path', "attribute :id")
|
||||||
|
|
||||||
assert_equal @library.get_compiled_template('some/path', ""), @library.get_compiled_template('some/path', "")
|
assert_equal({}, t.source)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "cached templates should not be modifiable in place" do
|
||||||
|
RablFastJson.cache_templates = true
|
||||||
|
ActionController::Base.stub(:perform_caching).and_return(true)
|
||||||
|
t = @library.get_compiled_template('some/path', "")
|
||||||
|
assert_nil t.context
|
||||||
|
t.context = "foobar"
|
||||||
|
assert_nil @library.get_compiled_template('some/path', "").context
|
||||||
end
|
end
|
||||||
|
|
||||||
test "don't cache templates cache_templates is enabled but perform_caching is not active" do
|
test "don't cache templates cache_templates is enabled but perform_caching is not active" do
|
||||||
|
|
Loading…
Reference in New Issue