From f036239447c79843983ee1c0d3dfe68484d63203 Mon Sep 17 00:00:00 2001 From: schneems Date: Mon, 5 Aug 2013 11:12:12 -0400 Subject: 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 --- .../adapters/sqlite3/sqlite3_create_folder_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 activerecord/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb (limited to 'activerecord/test/cases/adapters/sqlite3') 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 -- cgit v1.2.3