2012-04-02 14:22:43 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class CacheTemplatesTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
setup do
|
2012-04-20 14:28:34 +00:00
|
|
|
RablRails::Library.reset_instance
|
|
|
|
@library = RablRails::Library.instance
|
|
|
|
RablRails.cache_templates = true
|
2012-04-02 14:22:43 +00:00
|
|
|
end
|
2012-04-09 23:03:07 +00:00
|
|
|
|
2012-04-02 14:22:43 +00:00
|
|
|
test "cache templates if perform_caching is active and cache_templates is enabled" do
|
2012-04-09 23:03:07 +00:00
|
|
|
ActionController::Base.stub(:perform_caching).and_return(true)
|
2012-07-15 15:53:20 +00:00
|
|
|
@library.compile_template_from_source('', 'some/path')
|
|
|
|
t = @library.compile_template_from_source("attribute :id", 'some/path')
|
2012-04-09 23:03:07 +00:00
|
|
|
|
2012-04-03 16:37:11 +00:00
|
|
|
assert_equal({}, t.source)
|
|
|
|
end
|
2012-04-09 23:03:07 +00:00
|
|
|
|
2012-04-03 16:37:11 +00:00
|
|
|
test "cached templates should not be modifiable in place" do
|
|
|
|
ActionController::Base.stub(:perform_caching).and_return(true)
|
2012-07-15 15:53:20 +00:00
|
|
|
@library.compile_template_from_source('', 'some/path')
|
|
|
|
t = @library.compile_template_from_source("attribute :id", 'some/path')
|
2012-04-15 16:17:49 +00:00
|
|
|
|
|
|
|
assert_equal({}, t.source)
|
2012-04-02 14:22:43 +00:00
|
|
|
end
|
2012-04-09 23:03:07 +00:00
|
|
|
|
2012-04-02 14:22:43 +00:00
|
|
|
test "don't cache templates cache_templates is enabled but perform_caching is not active" do
|
2012-04-09 23:03:07 +00:00
|
|
|
ActionController::Base.stub(:perform_caching).and_return(false)
|
2012-07-15 15:53:20 +00:00
|
|
|
@library.compile_template_from_source('', 'some/path')
|
|
|
|
t = @library.compile_template_from_source("attribute :id", 'some/path')
|
2012-04-09 23:03:07 +00:00
|
|
|
|
|
|
|
assert_equal({ :id => :id }, t.source)
|
2012-04-02 14:22:43 +00:00
|
|
|
end
|
|
|
|
end
|