Skip to content

Commit

Permalink
Merge pull request #8 from RoleModel/unique-buildpack
Browse files Browse the repository at this point in the history
Account for duplicate buildpacks
  • Loading branch information
mikehale authored Aug 15, 2024
2 parents 8bb1191 + 87d0449 commit d8cebb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/generators/chromium/pdf/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def include_chrome_buildpack_in_app_json
def add_buildpack_to_app_json
in_root do
update_json_file('app.json') do |data|
data['buildpacks'] << { 'url' => 'heroku-community/chrome-for-testing' }
if data['buildpacks'].none? { |entry| entry['url'] == 'heroku-community/chrome-for-testing' }
data['buildpacks'] << { 'url' => 'heroku-community/chrome-for-testing' }
end
end
end
end
Expand Down
16 changes: 13 additions & 3 deletions test/generators/install_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
destination File.expand_path('../../tmp', __dir__)
setup do
prepare_destination
@app_json_path = "#{destination_root}/app.json"
end

test 'pdf job template is created' do
Expand All @@ -21,9 +22,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
assert_file 'config/initializers/good_job.rb'
end

test 'app.json is created' do
@app_json_path = "#{destination_root}/app.json"

test 'app.json is correct' do
File.write(@app_json_path, ActiveSupport::JSON.encode({}))
run_generator
assert_includes(File.read(@app_json_path), 'heroku-community/chrome-for-testing')
Expand All @@ -32,4 +31,15 @@ class InstallGeneratorTest < Rails::Generators::TestCase
run_generator
assert_includes(File.read(@app_json_path), 'heroku-community/chrome-for-testing')
end

test 'does not duplicate the buildpack in app.json' do
File.write(@app_json_path,
ActiveSupport::JSON.encode({ buildpacks: [{ 'url' => 'heroku-community/chrome-for-testing' }] }))

run_generator
found = ActiveSupport::JSON.decode(File.read(@app_json_path))['buildpacks'].select do |entry|
entry['url'] == 'heroku-community/chrome-for-testing'
end
assert_equal(1, found.size)
end
end

0 comments on commit d8cebb8

Please sign in to comment.