aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-18 23:46:33 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-11-18 23:52:39 -0200
commit53aefdec91e4e26b2fbd1a8dc39817ecabfe6125 (patch)
tree07a015ccbf1f0a6128acadea23ab9cc5e3947db1 /railties/test
parent0cc9c1255d8bc5a2f7d4abb8553e9eefabf3deac (diff)
downloadrails-53aefdec91e4e26b2fbd1a8dc39817ecabfe6125.tar.gz
rails-53aefdec91e4e26b2fbd1a8dc39817ecabfe6125.tar.bz2
rails-53aefdec91e4e26b2fbd1a8dc39817ecabfe6125.zip
Fix rails db command with sqlite3 database
When using sqlite3 it was attempting to find the database file based on Rails.root, the problem is that Rails.root is not always present because we try to first manually load "config/database.yml" instead of loading the entire app, to make "rails db" faster. This means that when we're in the root path of the app, calling "rails db" won't allow us to use Rails.root, making the command fail for sqlite3 with the error: ./rails/commands/dbconsole.rb:62:in `start': undefined method `root' for Rails:Module (NoMethodError) The fix is to simply not pass any dir string to File.expand_path, which will make it use the current directory of the process as base, or the root path of the app, which is what we want. When we are in any other subdirectory, calling "rails db" should work just fine, because "config/database.yml" won't be found, thus "rails db" will fallback to loading the app, making Rails.root available. Closes #8257.
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/commands/dbconsole_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb
index d45bdaabf5..6316584825 100644
--- a/railties/test/commands/dbconsole_test.rb
+++ b/railties/test/commands/dbconsole_test.rb
@@ -116,6 +116,14 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
assert !aborted
end
+ def test_sqlite3_db_without_defined_rails_root
+ Rails.stubs(:respond_to?)
+ Rails.expects(:respond_to?).with(:root).once.returns(false)
+ dbconsole.expects(:find_cmd_and_exec).with('sqlite3', Rails.root.join('../config/db.sqlite3').to_s)
+ start(adapter: 'sqlite3', database: 'config/db.sqlite3')
+ assert !aborted
+ end
+
def test_oracle
dbconsole.expects(:find_cmd_and_exec).with('sqlplus', 'user@db')
start(adapter: 'oracle', database: 'db', username: 'user', password: 'secret')