Skip to content

Commit d5e09e3

Browse files
authored
Merge pull request #804 from casperisfine/3.x-fix-erb-version-checking
Various compatibility fixes for the 3.x branch
2 parents f4d3dae + 45886ab commit d5e09e3

37 files changed

+115
-80
lines changed

.github/workflows/ci.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI
2+
on: [push, pull_request]
3+
jobs:
4+
tests:
5+
runs-on: ubuntu-latest
6+
continue-on-error: ${{ matrix.experimental }}
7+
name: ${{ matrix.ruby }}
8+
strategy:
9+
matrix:
10+
experimental: [false]
11+
ruby:
12+
- "2.5"
13+
- "2.6"
14+
- "2.7"
15+
- "3.0"
16+
- "3.1"
17+
- "3.2"
18+
- "3.3"
19+
rubyopt: [""]
20+
include:
21+
- { ruby: "3.3", rubyopt: "--enable-frozen-string-literal --debug-frozen-string-literal", experimental: false }
22+
- { ruby: head, experimental: true }
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Set up Ruby
27+
uses: ruby/setup-ruby@v1
28+
with:
29+
ruby-version: ${{ matrix.ruby }}
30+
bundler-cache: true
31+
32+
- name: Run tests ${{ matrix.rubyopt }}
33+
timeout-minutes: 10
34+
run: bundle exec rake RUBYOPT="${{ matrix.rubyopt }}"

.github/workflows/isolated.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: CI isolated tests
2+
on: [push, pull_request]
3+
jobs:
4+
tests:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
ruby: [2.7]
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Set up Ruby
14+
uses: ruby/setup-ruby@v1
15+
with:
16+
ruby-version: ${{ matrix.ruby }}
17+
bundler-cache: true
18+
19+
- name: Run tests
20+
run: bundle exec rake test_isolated

.travis.yml

-36
This file was deleted.

lib/sprockets.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module Sprockets
105105
register_bundle_processor 'application/javascript', Bundle
106106
register_bundle_processor 'text/css', Bundle
107107

108-
register_bundle_metadata_reducer '*/*', :data, proc { "" }, :concat
108+
register_bundle_metadata_reducer '*/*', :data, proc { "" }, :+
109109
register_bundle_metadata_reducer 'application/javascript', :data, proc { "" }, Utils.method(:concat_javascript_sources)
110110
register_bundle_metadata_reducer '*/*', :links, :+
111111

lib/sprockets/directive_processor.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: false
2+
13
require 'set'
24
require 'shellwords'
35

lib/sprockets/server.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ def cache_headers(env, etag)
251251
# If the request url contains a fingerprint, set a long
252252
# expires on the response
253253
if path_fingerprint(env["PATH_INFO"])
254-
headers["Cache-Control"] << ", max-age=31536000"
254+
headers["Cache-Control"] += ", max-age=31536000"
255255

256256
# Otherwise set `must-revalidate` since the asset could be modified.
257257
else
258-
headers["Cache-Control"] << ", must-revalidate"
258+
headers["Cache-Control"] += ", must-revalidate"
259259
headers["Vary"] = "Accept-Encoding"
260260
end
261261

lib/sprockets/uri_utils.rb

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def split_file_uri(uri)
5050
# Hack for parsing Windows "file:///C:/Users/IEUser" paths
5151
path.gsub!(/^\/([a-zA-Z]:)/, '\1'.freeze)
5252

53+
host = nil if host && host.empty?
54+
query = nil if query && query.empty?
55+
5356
[scheme, host, path, query]
5457
end
5558

lib/sprockets/utils.rb

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def string_end_with_semicolon?(str)
102102
#
103103
# Returns buf String.
104104
def concat_javascript_sources(buf, source)
105+
buf = +buf
105106
if source.bytesize > 0
106107
buf << source
107108

sprockets.gemspec

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
1111
s.files = Dir["README.md", "CHANGELOG.md", "LICENSE", "lib/**/*.rb"]
1212
s.executables = ["sprockets"]
1313

14+
s.add_dependency "base64"
1415
s.add_dependency "rack", "> 1", "< 3"
1516
s.add_dependency "concurrent-ruby", "~> 1.0"
1617

@@ -23,7 +24,7 @@ Gem::Specification.new do |s|
2324
s.add_development_dependency "minitest", "~> 5.0"
2425
s.add_development_dependency "nokogiri", "~> 1.3"
2526
s.add_development_dependency "rack-test", "~> 0.6"
26-
s.add_development_dependency "rake", "~> 10.0"
27+
s.add_development_dependency "rake"
2728
s.add_development_dependency "sass", "~> 3.1"
2829
s.add_development_dependency "uglifier", "~> 2.3"
2930
s.add_development_dependency "yui-compressor", "~> 0.12"

test/sprockets_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def silence_warnings
125125
Sprockets.register_transformer 'text/css', 'application/css-sourcemap+json', SourceMapTransformer
126126

127127

128-
class Sprockets::TestCase < MiniTest::Test
128+
class Sprockets::TestCase < Minitest::Test
129129
FIXTURE_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "fixtures"))
130130

131131
def self.test(name, &block)

test/test_asset.rb

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: false
2+
13
require "sprockets_test"
24

35
module AssetTests
@@ -117,7 +119,7 @@ def self.test(name, &block)
117119

118120
sandbox filename do
119121
write(filename, "a;")
120-
asset = asset('test.js')
122+
assert asset('test.js')
121123

122124
File.unlink(filename)
123125

@@ -132,7 +134,7 @@ def self.test(name, &block)
132134
sandbox main, dep do
133135
write(main, "//= depend_on test-dep\n")
134136
write(dep, "a;")
135-
asset = asset('test-main.js')
137+
assert asset('test-main.js')
136138

137139
File.unlink(dep)
138140

@@ -215,7 +217,7 @@ def setup
215217
end
216218

217219
test "charset is nil" do
218-
assert_equal nil, @asset.charset
220+
assert_nil @asset.charset
219221
end
220222

221223
test "length" do
@@ -1312,7 +1314,7 @@ def setup
13121314
end
13131315

13141316
test "content type" do
1315-
assert_equal nil, content_type("empty")
1317+
assert_nil content_type("empty")
13161318

13171319
assert_equal "application/javascript", content_type("application.js")
13181320
assert_equal "text/css", content_type("application.css")
@@ -1324,7 +1326,7 @@ def setup
13241326

13251327
assert_equal "text/css", content_type("store.css.erb")
13261328
assert_equal "text/plain", content_type("files.erb")
1327-
assert_equal nil, content_type("store.foo")
1329+
assert_nil content_type("store.foo")
13281330

13291331
assert_equal "application/javascript", content_type("application.coffee")
13301332
assert_equal "text/css", content_type("application.scss")
@@ -1347,7 +1349,7 @@ def setup
13471349
assert_equal "application/javascript", content_type("jquery.ext/form.js")
13481350
assert_equal "application/javascript", content_type("jquery-coffee.min.coffee")
13491351
assert_equal "application/javascript", content_type("jquery-custom.min.js.erb")
1350-
assert_equal nil, content_type("jquery.js.min")
1352+
assert_nil content_type("jquery.js.min")
13511353

13521354
assert_equal "application/javascript", content_type("all.coffee/plain.js")
13531355
assert_equal "application/javascript", content_type("all.coffee/hot.coffee")
@@ -1357,7 +1359,7 @@ def setup
13571359
assert_equal "application/javascript", content_type("bar-ng.ngt.haml")
13581360
assert_equal "application/javascript", content_type("baz-ng.js.ngt")
13591361

1360-
assert_equal nil, content_type("sprite.css.embed")
1362+
assert_nil content_type("sprite.css.embed")
13611363

13621364
assert_equal "application/javascript", content_type("traceur.es6")
13631365
assert_equal "application/javascript", content_type("traceur.js.es6")

test/test_cache_store.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_delete
6262
@store.set("foo", "bar")
6363
assert_equal "bar", @store.get("foo")
6464
@store.set("foo", nil)
65-
assert_equal nil, @store.get("foo")
65+
assert_nil @store.get("foo")
6666
end
6767

6868
def test_fetch
@@ -71,7 +71,7 @@ def test_fetch
7171
end
7272
end
7373

74-
class TestNullStore < MiniTest::Test
74+
class TestNullStore < Minitest::Test
7575
def setup
7676
@_store = Sprockets::Cache::NullStore.new
7777
@store = Sprockets::Cache.new(Sprockets::Cache::NullStore.new)
@@ -85,7 +85,7 @@ def test_inspect
8585
include CacheStoreNullTests
8686
end
8787

88-
class TestMemoryStore < MiniTest::Test
88+
class TestMemoryStore < Minitest::Test
8989
def setup
9090
@_store = Sprockets::Cache::MemoryStore.new
9191
@store = Sprockets::Cache.new(@_store)
@@ -118,7 +118,7 @@ def test_set_with_lru
118118
end
119119
end
120120

121-
class TestZeroMemoryStore < MiniTest::Test
121+
class TestZeroMemoryStore < Minitest::Test
122122
def setup
123123
@_store = Sprockets::Cache::MemoryStore.new(0)
124124
@store = Sprockets::Cache.new(@_store)
@@ -131,7 +131,7 @@ def test_inspect
131131
include CacheStoreNullTests
132132
end
133133

134-
class TestFileStore < MiniTest::Test
134+
class TestFileStore < Minitest::Test
135135
def setup
136136
@root = Dir::mktmpdir "sprockets-file-store"
137137
@_store = Sprockets::Cache::FileStore.new(@root)
@@ -159,7 +159,7 @@ def test_corrupted_read
159159
include CacheStoreTests
160160
end
161161

162-
class TestZeroFileStore < MiniTest::Test
162+
class TestZeroFileStore < Minitest::Test
163163
def setup
164164
@tmpdir = Dir::mktmpdir "sprockets-file-store-zero"
165165
@_store = Sprockets::Cache::FileStore.new(@tmpdir, 0)

test/test_closure_compressor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'sprockets/cache'
33
require 'sprockets/closure_compressor'
44

5-
class TestClosureCompressor < MiniTest::Test
5+
class TestClosureCompressor < Minitest::Test
66
def test_compress_javascript
77
input = {
88
:data => "function foo() {\n return true;\n}",

test/test_coffee_script_processor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'sprockets/cache'
33
require 'sprockets/coffee_script_processor'
44

5-
class TestCoffeeScriptProcessor < MiniTest::Test
5+
class TestCoffeeScriptProcessor < Minitest::Test
66
def test_compile_coffee_script_template_to_js
77
input = {
88
content_type: 'application/javascript',

test/test_digest_utils.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'minitest/autorun'
22
require 'sprockets/digest_utils'
33

4-
class TestDigestUtils < MiniTest::Test
4+
class TestDigestUtils < Minitest::Test
55
include Sprockets::DigestUtils
66

77
def test_detect_digest_class
@@ -35,7 +35,7 @@ def test_digest
3535
assert_equal "62427aa539a0b78e90fd710dc0e15f2960771ba44214b5d41d4a93a8b2940a38", hexdigest({"foo" => "baz"})
3636
assert_equal "b6054efd9929004bdd0a1c09eb2d12961325396da749143def3e9a4050aa703e", hexdigest([[:foo, 1]])
3737
assert_equal "79a19ffe41ecebd5dc35e95363e0b4aa79b139a22bc650384df57eb09842f099", hexdigest([{:foo => 1}])
38-
assert_equal "94ee40cca7c2c6d2a134033d2f5a31c488cad5d3dcc61a3dbb5e2a858635874b", hexdigest("foo".force_encoding('UTF-8').encoding)
38+
assert_equal "94ee40cca7c2c6d2a134033d2f5a31c488cad5d3dcc61a3dbb5e2a858635874b", hexdigest(Encoding::UTF_8)
3939

4040
assert_raises(TypeError) do
4141
digest(Object.new)

test/test_eco_processor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'sprockets/cache'
33
require 'sprockets/eco_processor'
44

5-
class TestEcoProcessor < MiniTest::Test
5+
class TestEcoProcessor < Minitest::Test
66
def test_compile_eco_template_to_js
77
input = {
88
content_type: 'application/javascript',

test/test_ejs_processor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'sprockets/cache'
33
require 'sprockets/ejs_processor'
44

5-
class TestEjsProcessor < MiniTest::Test
5+
class TestEjsProcessor < Minitest::Test
66
def test_compile_ejs_template_to_js
77
input = {
88
content_type: 'application/javascript',

test/test_encoding.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: utf-8
2+
# frozen_string_literal: false
23
require "sprockets_test"
34

45
class AssetEncodingTest < Sprockets::TestCase

test/test_encoding_utils.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'minitest/autorun'
33
require 'sprockets/encoding_utils'
44

5-
class TestDigestUtils < MiniTest::Test
5+
class TestDigestUtils < Minitest::Test
66
include Sprockets::EncodingUtils
77

88
def test_deflate

test/test_environment.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def self.test(name, &block)
361361
end
362362

363363
test "missing asset returns nil" do
364-
assert_equal nil, @env["missing.js"]
364+
assert_nil @env["missing.js"]
365365
end
366366

367367
test "missing asset path returns nil" do

test/test_erb_processor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'sprockets/cache'
44
require 'sprockets/erb_processor'
55

6-
class TestERBProcessor < MiniTest::Test
6+
class TestERBProcessor < Minitest::Test
77

88
def uri_path(path)
99
path = '/' + path if path[1] == ':' # Windows path / drive letter

test/test_http_utils.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'minitest/autorun'
22
require 'sprockets/http_utils'
33

4-
class TestHTTPUtils < MiniTest::Test
4+
class TestHTTPUtils < Minitest::Test
55
include Sprockets::HTTPUtils
66

77
def test_match_mime_type

test/test_jst_processor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'sprockets/cache'
33
require 'sprockets/jst_processor'
44

5-
class TestJstProcessor < MiniTest::Test
5+
class TestJstProcessor < Minitest::Test
66
def test_export_js_template_in_JST
77
input = {
88
name: 'users/show',

0 commit comments

Comments
 (0)