Skip to content

Commit

Permalink
Handle case of existing gitignore no newline end
Browse files Browse the repository at this point in the history
keep blank line at top in case existing .gitignore does not end in a
newline
  • Loading branch information
justin808 committed Aug 17, 2017
1 parent fe57b3e commit ec5da26
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/generators/react_on_rails/base_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions spec/react_on_rails/generators/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ec5da26

Please sign in to comment.