aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/compiled_templates_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-01-11 17:28:43 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2014-01-11 17:28:43 -0800
commit11e8badb16876e6bd72c874631d25aec41dad293 (patch)
tree5ec87baa3a8e7652c46d6804b174b81b8f9c7745 /actionview/test/template/compiled_templates_test.rb
parent474ebc55bd13ad58626a49dfc44c8e6407813935 (diff)
parentcaa981d88112f019ade868f75af6b5f399c244a4 (diff)
downloadrails-11e8badb16876e6bd72c874631d25aec41dad293.tar.gz
rails-11e8badb16876e6bd72c874631d25aec41dad293.tar.bz2
rails-11e8badb16876e6bd72c874631d25aec41dad293.zip
Merge branch 'master' into set_binds
* master: (2794 commits) doc, API example on how to use `Model#exists?` with multiple IDs. [ci skip] Restore DATABASE_URL even if it's nil in connection_handler test [ci skip] - error_messages_for has been deprecated since 2.3.8 - lets reduce any confusion for users Ensure Active Record connection consistency Revert "ask the fixture set for the sql statements" Check `respond_to` before delegation due to: https://github.com/ruby/ruby/commit/d781caaf313b8649948c107bba277e5ad7307314 Adding Hash#compact and Hash#compact! methods MySQL version 4.1 was EOL on December 31, 2009 We should at least recommend modern versions of MySQL to users. clear cache on body close so that cache remains during rendering add a more restricted codepath for templates fixes #13390 refactor generator tests to use block form of Tempfile Fix typo [ci skip] Move finish_template as the last public method in the generator Minor typos fix [ci skip] make `change_column_null` reversible. Closes #13576. create/drop test and development databases only if RAILS_ENV is nil Revert "Speedup String#to" typo fix in test name. [ci skip]. `core_ext/string/access.rb` test what we are documenting. Fix typo in image_tag documentation ... Conflicts: activerecord/lib/active_record/associations/join_dependency/join_association.rb activerecord/lib/active_record/relation/query_methods.rb
Diffstat (limited to 'actionview/test/template/compiled_templates_test.rb')
-rw-r--r--actionview/test/template/compiled_templates_test.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/actionview/test/template/compiled_templates_test.rb b/actionview/test/template/compiled_templates_test.rb
new file mode 100644
index 0000000000..2336321f3e
--- /dev/null
+++ b/actionview/test/template/compiled_templates_test.rb
@@ -0,0 +1,62 @@
+require 'abstract_unit'
+
+class CompiledTemplatesTest < ActiveSupport::TestCase
+ def setup
+ # Clean up any details key cached to expose failures
+ # that otherwise would appear just on isolated tests
+ ActionView::LookupContext::DetailsKey.clear
+
+ @compiled_templates = ActionView::CompiledTemplates
+ @compiled_templates.instance_methods.each do |m|
+ @compiled_templates.send(:remove_method, m) if m =~ /^_render_template_/
+ end
+ end
+
+ def test_template_gets_recompiled_when_using_different_keys_in_local_assigns
+ assert_equal "one", render(:file => "test/render_file_with_locals_and_default")
+ assert_equal "two", render(:file => "test/render_file_with_locals_and_default", :locals => { :secret => "two" })
+ end
+
+ def test_template_changes_are_not_reflected_with_cached_templates
+ assert_equal "Hello world!", render(:file => "test/hello_world")
+ modify_template "test/hello_world.erb", "Goodbye world!" do
+ assert_equal "Hello world!", render(:file => "test/hello_world")
+ end
+ assert_equal "Hello world!", render(:file => "test/hello_world")
+ end
+
+ def test_template_changes_are_reflected_with_uncached_templates
+ assert_equal "Hello world!", render_without_cache(:file => "test/hello_world")
+ modify_template "test/hello_world.erb", "Goodbye world!" do
+ assert_equal "Goodbye world!", render_without_cache(:file => "test/hello_world")
+ end
+ assert_equal "Hello world!", render_without_cache(:file => "test/hello_world")
+ end
+
+ private
+ def render(*args)
+ render_with_cache(*args)
+ end
+
+ def render_with_cache(*args)
+ view_paths = ActionController::Base.view_paths
+ ActionView::Base.new(view_paths, {}).render(*args)
+ end
+
+ def render_without_cache(*args)
+ path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH)
+ view_paths = ActionView::PathSet.new([path])
+ ActionView::Base.new(view_paths, {}).render(*args)
+ end
+
+ def modify_template(template, content)
+ filename = "#{FIXTURE_LOAD_PATH}/#{template}"
+ 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) }
+ end
+ end
+end