Skip to content

Commit

Permalink
Rescue TypeError from Sprockets
Browse files Browse the repository at this point in the history
  • Loading branch information
kirs committed Nov 29, 2017
1 parent 8e9eafb commit d61bc1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/premailer/rails/css_loaders/asset_pipeline_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def load(url)

file = file_name(url)
::Rails.application.assets_manifest.find_sources(file).first
rescue Errno::ENOENT => _error
rescue Errno::ENOENT, TypeError => _error
end

def file_name(url)
Expand Down
17 changes: 17 additions & 0 deletions spec/integration/css_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ def expect_file(path, content='file content')
end
end

context "when find_sources raises TypeError" do
let(:response) { 'content of base.css' }
let(:uri) { URI('http://example.com/assets/base.css') }

it "falls back to Net::HTTP" do
expect(Rails.application.assets_manifest).to \
receive(:find_sources)
.with('base.css')
.and_raise(TypeError)

allow(Net::HTTP).to \
receive(:get).with(uri).and_return(response)
expect(css_for_url('http://example.com/assets/base.css')).to \
eq(response)
end
end

context "when find_sources raises Errno::ENOENT" do
let(:response) { 'content of base.css' }
let(:uri) { URI('http://example.com/assets/base.css') }
Expand Down

0 comments on commit d61bc1d

Please sign in to comment.