@@ -232,23 +232,32 @@ def with_database_existing
232
232
233
233
def with_bad_permissions
234
234
Dir . chdir ( app_path ) do
235
- skip "Can't avoid permissions as root" if Process . uid . zero?
236
-
237
235
set_database_url
238
236
FileUtils . chmod ( "-w" , "db" )
239
237
yield
240
238
FileUtils . chmod ( "+w" , "db" )
241
239
end
242
240
end
243
241
244
- test "db:create failure because bad permissions" do
245
- with_bad_permissions do
246
- output = rails ( "db:create" , allow_failure : true )
247
- assert_match ( "Couldn't create '#{ database_url_db_name } ' database. Please check your configuration." , output )
248
- assert_equal 1 , $?. exitstatus
242
+ unless Process . uid . zero?
243
+ test "db:create failure because bad permissions" do
244
+ with_bad_permissions do
245
+ output = rails ( "db:create" , allow_failure : true )
246
+ assert_match ( "Couldn't create '#{ database_url_db_name } ' database. Please check your configuration." , output )
247
+ assert_equal 1 , $?. exitstatus
248
+ end
249
249
end
250
- end
251
250
251
+ test "db:drop failure because bad permissions" do
252
+ with_database_existing do
253
+ with_bad_permissions do
254
+ output = rails ( "db:drop" , allow_failure : true )
255
+ assert_match ( /Couldn't drop/ , output )
256
+ assert_equal 1 , $?. exitstatus
257
+ end
258
+ end
259
+ end
260
+ end
252
261
test "db:create works when schema cache exists and database does not exist" do
253
262
use_postgresql
254
263
@@ -268,16 +277,6 @@ def with_bad_permissions
268
277
assert_match ( /does not exist/ , output )
269
278
end
270
279
271
- test "db:drop failure because bad permissions" do
272
- with_database_existing do
273
- with_bad_permissions do
274
- output = rails ( "db:drop" , allow_failure : true )
275
- assert_match ( /Couldn't drop/ , output )
276
- assert_equal 1 , $?. exitstatus
277
- end
278
- end
279
- end
280
-
281
280
test "db:truncate_all truncates all non-internal tables" do
282
281
Dir . chdir ( app_path ) do
283
282
rails "generate" , "model" , "book" , "title:string"
0 commit comments