Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Propshaft assets to use fallbacks #140

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/inline_svg/propshaft_asset_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def initialize(filename)
end

def pathname
::Rails.application.assets.load_path.find(@filename).path
asset_path = ::Rails.application.assets.load_path.find(@filename)
asset_path.path unless asset_path.nil?
end
end
end
23 changes: 23 additions & 0 deletions spec/propshaft_asset_finder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require_relative '../lib/inline_svg'

describe InlineSvg::PropshaftAssetFinder do
context "when the file is not found" do
it "returns nil" do
stub_const('Rails', double('Rails').as_null_object)
expect(::Rails.application.assets.load_path).to receive(:find).with('some-file').and_return(nil)

expect(InlineSvg::PropshaftAssetFinder.find_asset('some-file').pathname).to be_nil
end
end

context "when the file is found" do
it "returns fully qualified file paths from Propshaft" do
stub_const('Rails', double('Rails').as_null_object)
asset = double('Asset')
expect(asset).to receive(:path).and_return(Pathname.new('/full/path/to/some-file'))
expect(::Rails.application.assets.load_path).to receive(:find).with('some-file').and_return(asset)

expect(InlineSvg::PropshaftAssetFinder.find_asset('some-file').pathname).to eq Pathname('/full/path/to/some-file')
end
end
end