aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2013-08-05 11:12:12 -0400
committerschneems <richard.schneeman@gmail.com>2013-08-05 12:10:52 -0400
commitf036239447c79843983ee1c0d3dfe68484d63203 (patch)
treefcb37f07ccb111253bb2385d8955d1dbbc1655fd /activerecord/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb
parent3baee0982d25e64cab2eeb046369f0fcf9ee2436 (diff)
downloadrails-f036239447c79843983ee1c0d3dfe68484d63203.tar.gz
rails-f036239447c79843983ee1c0d3dfe68484d63203.tar.bz2
rails-f036239447c79843983ee1c0d3dfe68484d63203.zip
Create sqlite3 directory if not present
If the `db/` directory is not present on a remote machine it will blow up in unexpected ways with error messages that do not indicate there is a missing directory: ``` SQLite3::CantOpenException: unable to open database file ``` This PR checks to see if a directory exists for the sqlite3 file and if not creates it for you. This PR is an alternative to #11692 as suggested by @josevalim
Diffstat (limited to 'activerecord/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb')
-rw-r--r--activerecord/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb
new file mode 100644
index 0000000000..5a4fe63580
--- /dev/null
+++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb
@@ -0,0 +1,21 @@
+# encoding: utf-8
+require "cases/helper"
+require 'models/owner'
+
+module ActiveRecord
+ module ConnectionAdapters
+ class SQLite3CreateFolder < ActiveRecord::TestCase
+ def test_sqlite_creates_directory
+ Dir.mktmpdir do |dir|
+ dir = Pathname.new(dir)
+ @conn = Base.sqlite3_connection :database => dir.join("db/foo.sqlite3"),
+ :adapter => 'sqlite3',
+ :timeout => 100
+
+ assert Dir.exists? dir.join('db')
+ assert File.exist? dir.join('db/foo.sqlite3')
+ end
+ end
+ end
+ end
+end