From f42c7eee7e63d9ac4426259f6b1b424b3f759faa Mon Sep 17 00:00:00 2001 From: Dmitrii Golub Date: Sat, 22 Mar 2014 03:26:02 +0400 Subject: [PATCH] Remove sqlite3 lines from .gitignore if the application is not using sqlite3. --- railties/CHANGELOG.md | 4 +++ railties/lib/rails/generators/app_base.rb | 4 +++ .../generators/rails/app/app_generator.rb | 2 +- .../generators/rails/app/templates/gitignore | 2 ++ .../test/generators/app_generator_test.rb | 26 ++++++++++++++++++- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index b52b80e802..6cf8714177 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Remove sqlite3 lines from `.gitignore` if the application is not using sqlite3. + + *Dmitrii Golub* + * Add public API to register new extensions for `rake notes`. Example: diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index fbdc47ea44..dd1438800c 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -172,6 +172,10 @@ def comment_if(value) options[value] ? '# ' : '' end + def sqlite3? + !options[:skip_active_record] && options[:database] == 'sqlite3' + end + class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out) def initialize(name, version, comment, options = {}, commented_out = false) super diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 83cb1dc0d5..abf6909a7f 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -50,7 +50,7 @@ def configru end def gitignore - copy_file "gitignore", ".gitignore" + template "gitignore", ".gitignore" end def app diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index 6a502e997f..8775e5e235 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -7,10 +7,12 @@ # Ignore bundler config. /.bundle +<% if sqlite3? -%> # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal +<% end -%> # Ignore all logfiles and tempfiles. /log/*.log /tmp diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 5ebdadacbf..48b40d39e4 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -408,7 +408,31 @@ def test_skip_spring end end -protected + def test_gitignore_when_sqlite3 + run_generator + + assert_file '.gitignore' do |content| + assert_match(/sqlite3/, content) + end + end + + def test_gitignore_when_no_active_record + run_generator [destination_root, '--skip-active-record'] + + assert_file '.gitignore' do |content| + assert_no_match(/sqlite3/, content) + end + end + + def test_gitignore_when_non_sqlite3_db + run_generator([destination_root, "-d", "mysql"]) + + assert_file '.gitignore' do |content| + assert_no_match(/sqlite3/, content) + end + end + + protected def action(*args, &block) silence(:stdout) { generator.send(*args, &block) } -- GitLab