Skip to content

Commit

Permalink
Make compilers option required to avoid nil testing just for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed May 17, 2024
1 parent f894726 commit 673deec
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/propshaft/load_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Propshaft::LoadPath
attr_reader :paths, :compilers, :version

def initialize(paths = [], compilers: nil, version: nil)
def initialize(paths = [], compilers:, version: nil)
@paths, @compilers, @version = dedup(paths), compilers, version
end

Expand All @@ -12,7 +12,7 @@ def find(asset_name)
end

def find_references_by(asset)
compilers&.referenced_by(asset) || Set.new
compilers.referenced_by(asset) || Set.new
end

def assets(content_types: nil)
Expand Down
3 changes: 2 additions & 1 deletion test/propshaft/compilers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Propshaft::CompilersTest < ActiveSupport::TestCase
private
def find_asset(logical_path)
root_path = Pathname.new("#{__dir__}/../fixtures/assets/first_path")
Propshaft::Asset.new(root_path.join(logical_path), logical_path: logical_path, load_path: Propshaft::LoadPath.new([ root_path ]))
load_path = Propshaft::LoadPath.new([ root_path ], compilers: Propshaft::Compilers.new(nil))
Propshaft::Asset.new(root_path.join(logical_path), logical_path: logical_path, load_path: load_path)
end
end
11 changes: 6 additions & 5 deletions test/propshaft/load_path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Propshaft::LoadPathTest < ActiveSupport::TestCase
@load_path = Propshaft::LoadPath.new [
Pathname.new("#{__dir__}/../fixtures/assets/first_path"),
Pathname.new("#{__dir__}/../fixtures/assets/second_path").to_s
]
], compilers: Propshaft::Compilers.new(nil)
end

test "find asset that only appears once in the paths" do
Expand Down Expand Up @@ -44,15 +44,15 @@ class Propshaft::LoadPathTest < ActiveSupport::TestCase
end

test "manifest with version" do
@load_path = Propshaft::LoadPath.new(@load_path.paths, version: "1")
@load_path = Propshaft::LoadPath.new(@load_path.paths, version: "1", compilers: Propshaft::Compilers.new(nil))
@load_path.manifest.tap do |manifest|
assert_equal "one-c9373b68.txt", manifest["one.txt"]
assert_equal "nested/three-a41a5d38.txt", manifest["nested/three.txt"]
end
end

test "missing load path directory" do
assert_nil Propshaft::LoadPath.new(Pathname.new("#{__dir__}/../fixtures/assets/nowhere")).find("missing")
assert_nil Propshaft::LoadPath.new(Pathname.new("#{__dir__}/../fixtures/assets/nowhere"), compilers: Propshaft::Compilers.new(nil)).find("missing")
end

test "deduplicate paths" do
Expand All @@ -62,7 +62,7 @@ class Propshaft::LoadPathTest < ActiveSupport::TestCase
"app/assets/stylesheets",
"app/assets/images",
"app/assets"
]
], compilers: Propshaft::Compilers.new(nil)

paths = load_path.paths
assert_equal 2, paths.count
Expand All @@ -73,6 +73,7 @@ class Propshaft::LoadPathTest < ActiveSupport::TestCase
private
def find_asset(logical_path)
root_path = Pathname.new("#{__dir__}/../fixtures/assets/first_path")
Propshaft::Asset.new(root_path.join(logical_path), logical_path: logical_path, load_path: Propshaft::LoadPath.new([ root_path ]))
load_path = Propshaft::LoadPath.new([ root_path ], compilers: Propshaft::Compilers.new(nil))
Propshaft::Asset.new(root_path.join(logical_path), logical_path: logical_path, load_path: load_path)
end
end
3 changes: 2 additions & 1 deletion test/propshaft/output_path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class Propshaft::OutputPathTest < ActiveSupport::TestCase

private
def output_asset(filename, content, created_at: Time.now)
asset = Propshaft::Asset.new(nil, logical_path: filename, load_path: Propshaft::LoadPath.new)
load_path = Propshaft::LoadPath.new([], compilers: Propshaft::Compilers.new(nil))
asset = Propshaft::Asset.new(nil, logical_path: filename, load_path: load_path)
asset.stub :content, content do
output_path = @output_path.path.join(asset.digested_path)
`touch -mt #{created_at.strftime('%y%m%d%H%M')} #{output_path}`
Expand Down
2 changes: 1 addition & 1 deletion test/propshaft/resolver/dynamic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Propshaft::Resolver::DynamicTest < ActiveSupport::TestCase
setup do
@load_path = Propshaft::LoadPath.new Pathname.new("#{__dir__}/../../fixtures/assets/first_path")
@load_path = Propshaft::LoadPath.new Pathname.new("#{__dir__}/../../fixtures/assets/first_path"), compilers: Propshaft::Compilers.new(nil)
@resolver = Propshaft::Resolver::Dynamic.new(load_path: @load_path, prefix: "/assets")
end

Expand Down
4 changes: 3 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ActiveSupport::TestCase
def find_asset(logical_path, fixture_path:)
root_path = Pathname.new("#{__dir__}/fixtures/assets/#{fixture_path}")
path = root_path.join(logical_path)
Propshaft::Asset.new(path, logical_path: logical_path, load_path: Propshaft::LoadPath.new([ root_path ]))
load_path = Propshaft::LoadPath.new([ root_path ], compilers: Propshaft::Compilers.new(nil))

Propshaft::Asset.new(path, logical_path: logical_path, load_path: load_path)
end
end

0 comments on commit 673deec

Please sign in to comment.