-
Notifications
You must be signed in to change notification settings - Fork 248
/
Copy pathtest_quiet_assets.rb
58 lines (43 loc) · 1.71 KB
/
test_quiet_assets.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'active_support'
require 'active_support/testing/isolation'
require 'active_support/log_subscriber/test_helper'
require 'minitest/autorun'
require 'sprockets/railtie'
require 'rails'
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
class TestQuietAssets < Minitest::Test
include ActiveSupport::Testing::Isolation
ROOT_PATH = Pathname.new(File.expand_path("../../tmp/app", __FILE__))
ASSET_PATH = ROOT_PATH.join("app","assets", "config")
def setup
FileUtils.mkdir_p(ROOT_PATH)
Dir.chdir(ROOT_PATH)
@app = Class.new(Rails::Application)
@app.config.eager_load = false
@app.config.logger = ActiveSupport::Logger.new("/dev/null")
@app.config.active_support.to_time_preserves_timezone = :zone
FileUtils.mkdir_p(ASSET_PATH)
File.open(ASSET_PATH.join("manifest.js"), "w") { |f| f << "" }
@app.initialize!
Rails.logger.level = Logger::DEBUG
end
def test_silences_with_default_prefix
assert_equal Logger::ERROR, middleware.call("PATH_INFO" => "/assets/stylesheets/application.css")
end
def test_silences_with_custom_prefix
Rails.application.config.assets.prefix = "path/to"
assert_equal Logger::ERROR, middleware.call("PATH_INFO" => "/path/to/thing")
end
def test_does_not_silence_without_match
assert_equal Logger::DEBUG, middleware.call("PATH_INFO" => "/path/to/thing")
end
def test_logger_does_not_respond_to_silence
::Rails.logger.stub :respond_to?, false do
assert_raises(Sprockets::Rails::LoggerSilenceError) { middleware.call("PATH_INFO" => "/assets/stylesheets/application.css") }
end
end
private
def middleware
@middleware ||= Sprockets::Rails::QuietAssets.new(->(env) { Rails.logger.level })
end
end