File tree Expand file tree Collapse file tree 2 files changed +9
-11
lines changed
lib/active_record/connection_adapters
test/cases/adapters/sqlite3 Expand file tree Collapse file tree 2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -112,13 +112,9 @@ def initialize(...)
112
112
dirname = File . dirname ( @config [ :database ] )
113
113
unless File . directory? ( dirname )
114
114
begin
115
- Dir . mkdir ( dirname )
116
- rescue Errno ::ENOENT => error
117
- if error . message . include? ( "No such file or directory" )
118
- raise ActiveRecord ::NoDatabaseError . new ( connection_pool : @pool )
119
- else
120
- raise
121
- end
115
+ FileUtils . mkdir_p ( dirname )
116
+ rescue SystemCallError
117
+ raise ActiveRecord ::NoDatabaseError . new ( connection_pool : @pool )
122
118
end
123
119
end
124
120
end
Original file line number Diff line number Diff line change @@ -23,12 +23,14 @@ def setup
23
23
)
24
24
end
25
25
26
- def test_bad_connection
27
- error = assert_raise ActiveRecord ::NoDatabaseError do
28
- connection = SQLite3Adapter . new ( adapter : "sqlite3" , database : "/tmp/should/_not/_exist/-cinco-dog.db" )
26
+ def test_database_should_get_created_when_missing_parent_directories_for_database_path
27
+ dir = Dir . mktmpdir
28
+ db_path = File . join ( dir , "_not_exist/-cinco-dog.sqlite3" )
29
+ assert_nothing_raised do
30
+ connection = SQLite3Adapter . new ( adapter : "sqlite3" , database : db_path )
29
31
connection . drop_table "ex" , if_exists : true
30
32
end
31
- assert_kind_of ActiveRecord :: ConnectionAdapters :: NullPool , error . connection_pool
33
+ assert SQLite3Adapter . database_exists? ( adapter : "sqlite3" , database : db_path )
32
34
end
33
35
34
36
def test_database_exists_returns_false_when_the_database_does_not_exist
You can’t perform that action at this time.
0 commit comments