Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use the same logger that ActionView::Base for the Digestor

  • Loading branch information...
commit d8dee214e39e806dc1b5bc5c148a347d974984f4 1 parent a227359
@rafaelfranca rafaelfranca authored
View
7 actionpack/lib/action_view/digestor.rb
@@ -19,7 +19,6 @@ class Digestor
/x
cattr_accessor(:cache) { Hash.new }
- cattr_accessor(:logger, instance_reader: true) { ActionView::Base.logger }
def self.digest(name, format, finder, options = {})
cache["#{name}.#{format}"] ||= new(name, format, finder, options).digest
@@ -53,8 +52,12 @@ def nested_dependencies
end
end
-
private
+
+ def logger
+ ActionView::Base.logger
+ end
+
def logical_name
name.gsub(%r|/_|, "/")
end
View
31 actionpack/test/template/digestor_test.rb
@@ -3,7 +3,7 @@
class FixtureTemplate
attr_reader :source
-
+
def initialize(template_path)
@source = File.read(template_path)
rescue Errno::ENOENT
@@ -14,7 +14,7 @@ def initialize(template_path)
class FixtureFinder
FIXTURES_DIR = "#{File.dirname(__FILE__)}/../fixtures/digestor"
TMP_DIR = "#{File.dirname(__FILE__)}/../tmp"
-
+
def find(logical_name, keys, partial, options)
FixtureTemplate.new("#{TMP_DIR}/digestor/#{partial ? logical_name.gsub(%r|/([^/]+)$|, '/_\1') : logical_name}.#{options[:formats].first}.erb")
end
@@ -24,7 +24,7 @@ class TemplateDigestorTest < ActionView::TestCase
def setup
FileUtils.cp_r FixtureFinder::FIXTURES_DIR, FixtureFinder::TMP_DIR
end
-
+
def teardown
FileUtils.rm_r File.join(FixtureFinder::TMP_DIR, "digestor")
ActionView::Digestor.cache.clear
@@ -71,7 +71,7 @@ def test_nested_template_directory
change_template("messages/actions/_move")
end
end
-
+
def test_dont_generate_a_digest_for_missing_templates
assert_equal '', digest("nothing/there")
end
@@ -85,7 +85,7 @@ def test_collection_dependency
change_template("events/_event")
end
end
-
+
def test_collection_derived_from_record_dependency
assert_digest_difference("messages/show") do
change_template("events/_event")
@@ -124,15 +124,18 @@ def test_old_style_hash_in_render_invocation
private
def assert_logged(message)
+ old_logger = ActionView::Base.logger
log = StringIO.new
- ActionView::Digestor.logger = Logger.new(log)
+ ActionView::Base.logger = Logger.new(log)
- yield
-
- log.rewind
- assert_match message, log.read
-
- ActionView::Digestor.logger = nil
+ begin
+ yield
+
+ log.rewind
+ assert_match message, log.read
+ ensure
+ ActionView::Base.logger = old_logger
+ end
end
def assert_digest_difference(template_name)
@@ -144,11 +147,11 @@ def assert_digest_difference(template_name)
assert previous_digest != digest(template_name), "digest didn't change"
ActionView::Digestor.cache.clear
end
-
+
def digest(template_name)
ActionView::Digestor.digest(template_name, :html, FixtureFinder.new)
end
-
+
def change_template(template_name)
File.open("#{FixtureFinder::TMP_DIR}/digestor/#{template_name}.html.erb", "w") do |f|
f.write "\nTHIS WAS CHANGED!"
Please sign in to comment.
Something went wrong with that request. Please try again.