aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/lookup_context_test.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-11-24 12:38:52 +0100
committerJosé Valim <jose.valim@gmail.com>2010-11-24 12:38:52 +0100
commit8624065bffd203e1f590ca431d468f9b38e9fb7f (patch)
tree5ecce040453a8762fae2e3b0467232577473d929 /actionpack/test/template/lookup_context_test.rb
parente39138478b38d7a5e0a13756b1bdfa8b43226846 (diff)
downloadrails-8624065bffd203e1f590ca431d468f9b38e9fb7f.tar.gz
rails-8624065bffd203e1f590ca431d468f9b38e9fb7f.tar.bz2
rails-8624065bffd203e1f590ca431d468f9b38e9fb7f.zip
Allow template handlers to store temp data.
Diffstat (limited to 'actionpack/test/template/lookup_context_test.rb')
-rw-r--r--actionpack/test/template/lookup_context_test.rb29
1 files changed, 27 insertions, 2 deletions
diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb
index 6d3b26e131..c9dd27cf2a 100644
--- a/actionpack/test/template/lookup_context_test.rb
+++ b/actionpack/test/template/lookup_context_test.rb
@@ -180,6 +180,16 @@ class LookupContextTest < ActiveSupport::TestCase
assert_not_equal template, old_template
end
+
+ test "data can be stored in cached templates" do
+ template = @lookup_context.find("hello_world", "test")
+ template.data["cached"] = "data"
+ assert_equal "Hello world!", template.source
+
+ template = @lookup_context.find("hello_world", "test")
+ assert_equal "data", template.data["cached"]
+ assert_equal "Hello world!", template.source
+ end
end
class LookupContextWithFalseCaching < ActiveSupport::TestCase
@@ -205,7 +215,7 @@ class LookupContextWithFalseCaching < ActiveSupport::TestCase
assert_equal "Bar", template.source
end
- test "if no template was found in the second lookup, give it higher preference" do
+ test "if no template was found in the second lookup, with no cache, raise error" do
template = @lookup_context.find("foo", "test", true)
assert_equal "Foo", template.source
@@ -215,7 +225,7 @@ class LookupContextWithFalseCaching < ActiveSupport::TestCase
end
end
- test "if no template was cached in the first lookup, do not use the cache in the second" do
+ test "if no template was cached in the first lookup, retrieval should work in the second call" do
@resolver.hash.clear
assert_raise ActionView::MissingTemplate do
@lookup_context.find("foo", "test", true)
@@ -225,4 +235,19 @@ class LookupContextWithFalseCaching < ActiveSupport::TestCase
template = @lookup_context.find("foo", "test", true)
assert_equal "Foo", template.source
end
+
+ test "data can be stored as long as template was not updated" do
+ template = @lookup_context.find("foo", "test", true)
+ template.data["cached"] = "data"
+ assert_equal "Foo", template.source
+
+ template = @lookup_context.find("foo", "test", true)
+ assert_equal "data", template.data["cached"]
+ assert_equal "Foo", template.source
+
+ @resolver.hash["test/_foo.erb"][1] = Time.now.utc
+ template = @lookup_context.find("foo", "test", true)
+ assert_nil template.data["cached"]
+ assert_equal "Foo", template.source
+ end
end \ No newline at end of file