2018-08-21 22:34:39 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-01-16 18:23:57 +01:00
|
|
|
require 'test_helper'
|
|
|
|
require 'fileutils'
|
|
|
|
require 'find'
|
|
|
|
require 'shellwords'
|
|
|
|
|
2014-09-02 23:48:44 +02:00
|
|
|
class SprocketsRailsTest < Minitest::Test
|
2014-01-16 18:23:57 +01:00
|
|
|
|
|
|
|
def test_sprockets_digest_asset_refs
|
2018-08-21 22:34:39 +01:00
|
|
|
root = 'test/dummy_rails'
|
2014-09-02 23:48:44 +02:00
|
|
|
compiled = Dir.chdir root do
|
|
|
|
silence_stderr_if !ENV['VERBOSE'] do
|
2018-08-21 22:34:39 +01:00
|
|
|
Bundler.with_original_env do
|
|
|
|
system({ 'BUNDLE_GEMFILE' => File.join(GEM_PATH, 'Gemfile'),
|
|
|
|
'RAILS_ENV' => 'production' },
|
2018-08-21 22:49:42 +01:00
|
|
|
'bundle && bundle exec rake assets:precompile')
|
2018-08-21 22:34:39 +01:00
|
|
|
end
|
2014-09-02 23:48:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
assert compiled, 'Could not precompile assets'
|
|
|
|
Dir.glob(File.join(root, 'public', 'assets', 'app*.{css,js}')) do |path|
|
2018-08-21 22:34:39 +01:00
|
|
|
File.read(path)
|
|
|
|
.scan(/url\("?[^"]+\.(?:jpg|png|eot|woff2?|ttf|svg)[^"]*"?\)/) do |m|
|
|
|
|
assert_match(/-[0-9a-f]{12,}\./, m)
|
2014-01-16 18:23:57 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
ensure
|
2018-08-21 22:34:39 +01:00
|
|
|
FileUtils.rm_rf %W[#{root}/public/assets/ #{root}/tmp/cache/], secure: true
|
2014-01-16 18:23:57 +01:00
|
|
|
end
|
|
|
|
end
|