aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-10-10 22:40:13 +0200
committerJosé Valim <jose.valim@gmail.com>2010-10-10 23:12:22 +0200
commit682368d4ba0bb4548f896d02bc4e038ee8ba6b4d (patch)
treeec2b03c8a1adae7fd7089aabc5466b8b3a932b11
parentf659a1576fc4a447bbfbd866c7244d8d790a3d9c (diff)
downloadrails-682368d4ba0bb4548f896d02bc4e038ee8ba6b4d.tar.gz
rails-682368d4ba0bb4548f896d02bc4e038ee8ba6b4d.tar.bz2
rails-682368d4ba0bb4548f896d02bc4e038ee8ba6b4d.zip
Use identifiers for template equality.
-rw-r--r--actionpack/lib/action_view/renderer/template_renderer.rb2
-rw-r--r--actionpack/lib/action_view/template.rb9
-rw-r--r--actionpack/lib/action_view/template/inline.rb20
-rw-r--r--actionpack/test/controller/new_base/render_once_test.rb17
-rw-r--r--actionpack/test/template/template_test.rb8
5 files changed, 46 insertions, 10 deletions
diff --git a/actionpack/lib/action_view/renderer/template_renderer.rb b/actionpack/lib/action_view/renderer/template_renderer.rb
index 9f9df15347..a9076760c5 100644
--- a/actionpack/lib/action_view/renderer/template_renderer.rb
+++ b/actionpack/lib/action_view/renderer/template_renderer.rb
@@ -45,7 +45,7 @@ module ActionView
with_fallbacks { find_template(options[:file], options[:prefix], false, keys) }
elsif options.key?(:inline)
handler = Template.handler_class_for_extension(options[:type] || "erb")
- Template.new(options[:inline], "inline template", handler, { :locals => keys })
+ Template::Inline.new(options[:inline], handler, :locals => keys)
elsif options.key?(:template)
options[:template].respond_to?(:render) ?
options[:template] : find_template(options[:template], options[:prefix], false, keys)
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index 7dd8acf37b..3ba18cbfae 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -93,6 +93,7 @@ module ActionView
autoload :Error
autoload :Handler
autoload :Handlers
+ autoload :Inline
autoload :Text
end
@@ -184,6 +185,14 @@ module ActionView
end
end
+ def hash
+ identifier.hash
+ end
+
+ def eql?(other)
+ other.is_a?(Template) && other.identifier == identifier
+ end
+
def inspect
@inspect ||=
if defined?(Rails.root)
diff --git a/actionpack/lib/action_view/template/inline.rb b/actionpack/lib/action_view/template/inline.rb
new file mode 100644
index 0000000000..be08065b6b
--- /dev/null
+++ b/actionpack/lib/action_view/template/inline.rb
@@ -0,0 +1,20 @@
+require 'digest/md5'
+
+module ActionView
+ class Template
+ class Inline < ::ActionView::Template
+ def initialize(source, handler, options={})
+ super(source, "inline template", handler, options)
+ end
+
+ def md5_source
+ @md5_source ||= Digest::MD5.hexdigest(source)
+ end
+
+ def eql?(other)
+ other.is_a?(Inline) && other.md5_source == md5_source
+ end
+ end
+ end
+end
+ \ No newline at end of file
diff --git a/actionpack/test/controller/new_base/render_once_test.rb b/actionpack/test/controller/new_base/render_once_test.rb
index 12892b7255..63de25be52 100644
--- a/actionpack/test/controller/new_base/render_once_test.rb
+++ b/actionpack/test/controller/new_base/render_once_test.rb
@@ -61,13 +61,12 @@ module RenderTemplate
include Tests
end
- # TODO This still needs to be implemented and supported.
- # class TestWithoutResolverCache < Rack::TestCase
- # testing RenderTemplate::RenderOnceController
- # include Tests
- #
- # def setup
- # RenderTemplate::RenderOnceController::RESOLVER.stubs(:caching?).returns(false)
- # end
- # end
+ class TestWithoutResolverCache < Rack::TestCase
+ testing RenderTemplate::RenderOnceController
+ include Tests
+
+ def setup
+ RenderTemplate::RenderOnceController::RESOLVER.stubs(:caching?).returns(false)
+ end
+ end
end
diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb
index 63f792d328..f2156c31de 100644
--- a/actionpack/test/template/template_test.rb
+++ b/actionpack/test/template/template_test.rb
@@ -151,6 +151,14 @@ class TestERBTemplate < ActiveSupport::TestCase
end
end
+ def test_inline_template_is_only_equal_if_source_match
+ inline1 = ActionView::Template::Inline.new("sample", ERBHandler)
+ inline2 = ActionView::Template::Inline.new("sample", ERBHandler)
+ inline3 = ActionView::Template::Inline.new("other", ERBHandler)
+ assert inline1.eql?(inline2)
+ assert !inline1.eql?(inline3)
+ end
+
if "ruby".encoding_aware?
def test_resulting_string_is_utf8
@template = new_template