require "cases/helper"
require 'models/owner'

module ActiveRecord
  module ConnectionAdapters
    class SQLite3CreateFolder < ActiveRecord::SQLite3TestCase
      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.exist? dir.join('db')
          assert File.exist? dir.join('db/foo.sqlite3')
        end
      end
    end
  end
end

require "cases/helper"
require 'models/owner'

module ActiveRecord
  module ConnectionAdapters
    class SQLite3CreateFolder < ActiveRecord::SQLite3TestCase
      def test_sqlite_creates_directory
        Dir.mktmpdir do |dir|
          begin
            dir = Pathname.new(dir)
            @conn = Base.sqlite3_connection :database => dir.join("db/foo.sqlite3"),
                                 :adapter => 'sqlite3',
                                 :timeout => 100

            assert Dir.exist? dir.join('db')
            assert File.exist? dir.join('db/foo.sqlite3')
          ensure
            @conn.disconnect! if @conn
          end
        end
      end
    end
  end
end

Fix test failure on Windows
Fix test failure on Windows

When this test was run on Windows, the database file would still be in
use, and `File.unlink` would fail. This would cause the temp directory to
be unable to be removed, and error out. By disconnecting the connection
when finished, we can avoid this error.
