Skip to content
Browse files

Merge pull request #14447 from Houdini/gitignore

Skip sqlite3 files in .gitignore if no sqlite3 in app
  • Loading branch information...
2 parents 8bd2912 + f42c7ee commit 9d8354c9d3858844294a9d963e32e66591e34e25 @rafaelfranca rafaelfranca committed Mar 24, 2014
View
4 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:
View
4 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
View
2 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
View
2 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
View
26 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) }

0 comments on commit 9d8354c

Please sign in to comment.
Something went wrong with that request. Please try again.