2008-07-16 13:26:23 +00:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'controller/fake_models'
|
|
|
|
|
2009-02-04 02:25:37 +00:00
|
|
|
class CompiledTemplatesTest < Test::Unit::TestCase
|
|
|
|
def setup
|
2009-07-19 13:12:15 +00:00
|
|
|
@compiled_templates = ActionView::CompiledTemplates
|
2009-02-04 02:25:37 +00:00
|
|
|
@compiled_templates.instance_methods.each do |m|
|
2009-04-23 22:58:38 +00:00
|
|
|
@compiled_templates.send(:remove_method, m) if m =~ /^_render_template_/
|
2008-07-16 13:26:23 +00:00
|
|
|
end
|
2009-02-04 02:25:37 +00:00
|
|
|
end
|
2010-08-14 05:13:00 +00:00
|
|
|
|
2009-02-04 02:25:37 +00:00
|
|
|
def test_template_gets_recompiled_when_using_different_keys_in_local_assigns
|
2009-04-23 22:58:38 +00:00
|
|
|
assert_equal "one", render(:file => "test/render_file_with_locals_and_default.erb")
|
|
|
|
assert_equal "two", render(:file => "test/render_file_with_locals_and_default.erb", :locals => { :secret => "two" })
|
2009-02-20 02:55:56 +00:00
|
|
|
end
|
2008-11-28 20:31:54 +00:00
|
|
|
|
2009-04-13 22:18:45 +00:00
|
|
|
def test_template_changes_are_not_reflected_with_cached_templates
|
|
|
|
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
|
|
|
modify_template "test/hello_world.erb", "Goodbye world!" do
|
2008-11-28 20:31:54 +00:00
|
|
|
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
|
|
|
end
|
2009-04-13 22:18:45 +00:00
|
|
|
assert_equal "Hello world!", render(:file => "test/hello_world.erb")
|
2009-02-20 02:55:56 +00:00
|
|
|
end
|
2008-11-28 20:31:54 +00:00
|
|
|
|
2009-04-13 22:18:45 +00:00
|
|
|
def test_template_changes_are_reflected_with_uncached_templates
|
|
|
|
assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb")
|
|
|
|
modify_template "test/hello_world.erb", "Goodbye world!" do
|
|
|
|
assert_equal "Goodbye world!", render_without_cache(:file => "test/hello_world.erb")
|
2008-11-28 20:31:54 +00:00
|
|
|
end
|
2009-04-13 22:18:45 +00:00
|
|
|
assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb")
|
2009-02-20 02:55:56 +00:00
|
|
|
end
|
2008-11-28 20:31:54 +00:00
|
|
|
|
2009-02-04 02:25:37 +00:00
|
|
|
private
|
|
|
|
def render(*args)
|
2009-04-13 22:18:45 +00:00
|
|
|
render_with_cache(*args)
|
2009-02-04 02:25:37 +00:00
|
|
|
end
|
2008-11-28 20:31:54 +00:00
|
|
|
|
2009-04-13 22:18:45 +00:00
|
|
|
def render_with_cache(*args)
|
|
|
|
view_paths = ActionController::Base.view_paths
|
|
|
|
ActionView::Base.new(view_paths, {}).render(*args)
|
2009-02-12 18:35:14 +00:00
|
|
|
end
|
2008-11-28 20:31:54 +00:00
|
|
|
|
2009-04-13 22:18:45 +00:00
|
|
|
def render_without_cache(*args)
|
2010-03-08 15:32:40 +00:00
|
|
|
path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH)
|
2011-08-09 19:10:25 +00:00
|
|
|
view_paths = ActionView::PathSet.new([path])
|
2009-04-13 22:18:45 +00:00
|
|
|
ActionView::Base.new(view_paths, {}).render(*args)
|
2009-02-20 02:55:56 +00:00
|
|
|
end
|
2008-11-28 20:31:54 +00:00
|
|
|
|
2009-04-13 22:18:45 +00:00
|
|
|
def modify_template(template, content)
|
|
|
|
filename = "#{FIXTURE_LOAD_PATH}/#{template}"
|
2009-02-04 02:25:37 +00:00
|
|
|
old_content = File.read(filename)
|
|
|
|
begin
|
|
|
|
File.open(filename, "wb+") { |f| f.write(content) }
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
File.open(filename, "wb+") { |f| f.write(old_content) }
|
2008-07-22 15:27:32 +00:00
|
|
|
end
|
2009-02-04 02:25:37 +00:00
|
|
|
end
|
2008-07-16 13:26:23 +00:00
|
|
|
end
|