diff --git a/lib/generators/chromium/pdf/install/install_generator.rb b/lib/generators/chromium/pdf/install/install_generator.rb index 53f72d2..5bcd378 100644 --- a/lib/generators/chromium/pdf/install/install_generator.rb +++ b/lib/generators/chromium/pdf/install/install_generator.rb @@ -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 diff --git a/test/generators/install_generator_test.rb b/test/generators/install_generator_test.rb index ff199d9..3415c09 100644 --- a/test/generators/install_generator_test.rb +++ b/test/generators/install_generator_test.rb @@ -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 @@ -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') @@ -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