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

Avoid using the shell to locate wkhtmltopdf in a Bundler environment #728

Merged
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
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