Skip to content

Commit

Permalink
Merge pull request #728 from Matt529/find-binary-using-which-interface
Browse files Browse the repository at this point in the history
Avoid using the shell to locate wkhtmltopdf in a Bundler environment
  • Loading branch information
unixmonkey authored Jul 9, 2018
2 parents 3e0e2e7 + 7768be7 commit f06f00e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/wicked_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def find_wkhtmltopdf_binary_path
possible_locations += %w[~/bin] if ENV.key?('HOME')
exe_path ||= WickedPdf.config[:exe_path] unless WickedPdf.config.empty?
exe_path ||= begin
detected_path = (defined?(Bundler) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
detected_path = (defined?(Bundler) ? Bundler.which('wkhtmltopdf') : `which wkhtmltopdf`).chomp
detected_path.present? && detected_path
rescue StandardError
nil
Expand Down
50 changes: 50 additions & 0 deletions test/unit/wkhtmltopdf_location_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@


class WkhtmltopdfLocationTest < ActiveSupport::TestCase
setup do
@saved_config = WickedPdf.config
WickedPdf.config = {}
end

teardown do
WickedPdf.config = @saved_config
end

test 'should correctly locate wkhtmltopdf without bundler' do
bundler_module = Bundler
Object.send(:remove_const, :Bundler)

assert_nothing_raised do
WickedPdf.new
end

Object.const_set(:Bundler, bundler_module)
end

test 'should correctly locate wkhtmltopdf with bundler' do
assert_nothing_raised do
WickedPdf.new
end
end

class LocationNonWritableTest < ActiveSupport::TestCase
setup do
@saved_config = WickedPdf.config
WickedPdf.config = {}

@old_home = ENV['HOME']
ENV['HOME'] = '/not/a/writable/directory'
end

teardown do
WickedPdf.config = @saved_config
ENV['HOME'] = @old_home
end

test 'should correctly locate wkhtmltopdf with bundler while HOME is set to a non-writable directory' do
assert_nothing_raised do
WickedPdf.new
end
end
end
end

0 comments on commit f06f00e

Please sign in to comment.