Permalink
Browse files

Use identifiers for template equality.

  • Loading branch information...
1 parent f659a15 commit 682368d4ba0bb4548f896d02bc4e038ee8ba6b4d @josevalim josevalim committed Oct 10, 2010
@@ -45,7 +45,7 @@ def determine_template(options) #:nodoc:
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)
@@ -93,6 +93,7 @@ class Template
autoload :Error
autoload :Handler
autoload :Handlers
+ autoload :Inline
autoload :Text
end
@@ -184,6 +185,14 @@ def rerender(view)
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)
@@ -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
+
@@ -61,13 +61,12 @@ class TestWithResolverCache < Rack::TestCase
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
@@ -151,6 +151,14 @@ def test_rerender_raises_an_error_without_virtual_path
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

0 comments on commit 682368d

Please sign in to comment.