diff --git a/CHANGELOG.md b/CHANGELOG.md index b5fa01335..265489d27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ Changes since last non-beta release. *Please add entries here for your pull requests.* +### [8.0.7] +#### fixed +- Fixes generator bug by keeping blank line at top in case existing .gitignore does not end in a newline. [#916](https://github.com/shakacode/react_on_rails/pull/916) by [justin808](https://github.com/justin808). + + ### [8.0.6] #### fixed - Fixes server rendering when using a CDN. Server rendering would try to fetch a file with the "asset_host". This change updates the webpacker_lite dependency to 2.1.0 which has a new helper `pack_path`. [#901](https://github.com/shakacode/react_on_rails/pull/901) by [justin808](https://github.com/justin808). Be sure to update webpacker_lite to 2.1.0. @@ -626,7 +631,8 @@ Best done with Object destructing: ##### Fixed - Fix several generator related issues. -[Unreleased]: https://github.com/shakacode/react_on_rails/compare/8.0.6...master +[Unreleased]: https://github.com/shakacode/react_on_rails/compare/8.0.7...master +[8.0.7]: https://github.com/shakacode/react_on_rails/compare/8.0.6...8.0.7 [8.0.6]: https://github.com/shakacode/react_on_rails/compare/8.0.5...8.0.6 [8.0.5]: https://github.com/shakacode/react_on_rails/compare/8.0.3...8.0.5 [8.0.3]: https://github.com/shakacode/react_on_rails/compare/8.0.2...8.0.3 diff --git a/lib/generators/react_on_rails/base_generator.rb b/lib/generators/react_on_rails/base_generator.rb index 2ed95b8df..344a460b1 100644 --- a/lib/generators/react_on_rails/base_generator.rb +++ b/lib/generators/react_on_rails/base_generator.rb @@ -33,7 +33,8 @@ def update_git_ignore DATA if dest_file_exists?(".gitignore") - append_to_file(".gitignore", data) + # NOTE: keep blank line at top in case existing .gitignore does not end in a newline + append_to_file(".gitignore", "\n#{data}") else GeneratorMessages.add_error(setup_file_error(".gitignore", data)) end diff --git a/spec/react_on_rails/generators/install_generator_spec.rb b/spec/react_on_rails/generators/install_generator_spec.rb index 194827b52..17626075d 100644 --- a/spec/react_on_rails/generators/install_generator_spec.rb +++ b/spec/react_on_rails/generators/install_generator_spec.rb @@ -3,6 +3,7 @@ require_relative "../support/generator_spec_helper" require_relative "../support/version_test_helpers" +# rubocop:disable Metrics/BlockLength describe InstallGenerator, type: :generator do destination File.expand_path("../../dummy-for-generators/", __FILE__) @@ -73,6 +74,34 @@ end end + context "when gitignore already exists and has no EOF newline" do + before(:all) { @install_generator = InstallGenerator.new } + + specify "it adds the script section if missing" do + data = "#lib from simplecov\ncoverage" + + run_generator_test_with_args(%w[]) do + simulate_existing_file(".gitignore", data) + end + + # rubocop:disable Layout/IndentHeredoc + expected = <<-MSG +#{data} + +# React on Rails +npm-debug.log* +node_modules + +# Generated js bundles +/public/webpack/* + MSG + assert_file(".gitignore") do |contents| + expect(contents).to eq(expected) + end + # rubocop:enable Layout/IndentHeredoc + end + end + context "with helpful message" do let(:expected) do <<-MSG.strip_heredoc diff --git a/spec/react_on_rails/support/shared_examples/base_generator_examples.rb b/spec/react_on_rails/support/shared_examples/base_generator_examples.rb index 8f04e5e0f..c834a200c 100644 --- a/spec/react_on_rails/support/shared_examples/base_generator_examples.rb +++ b/spec/react_on_rails/support/shared_examples/base_generator_examples.rb @@ -13,6 +13,7 @@ it "updates the .gitignore file" do match = <<-MATCH.strip_heredoc some existing text + # React on Rails npm-debug.log* node_modules