Skip to content

Commit 91dedc0

Browse files
committed
Fix Railties tests
These tests have never run in CI due to CI using a root user. This commit keeps that behavior without using the skip so that we can enable raise on skips.
1 parent e67b8d0 commit 91dedc0

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

railties/test/application/rake/dbs_test.rb

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,32 @@ def with_database_existing
232232

233233
def with_bad_permissions
234234
Dir.chdir(app_path) do
235-
skip "Can't avoid permissions as root" if Process.uid.zero?
236-
237235
set_database_url
238236
FileUtils.chmod("-w", "db")
239237
yield
240238
FileUtils.chmod("+w", "db")
241239
end
242240
end
243241

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
249249
end
250-
end
251250

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
252261
test "db:create works when schema cache exists and database does not exist" do
253262
use_postgresql
254263

@@ -268,16 +277,6 @@ def with_bad_permissions
268277
assert_match(/does not exist/, output)
269278
end
270279

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-
281280
test "db:truncate_all truncates all non-internal tables" do
282281
Dir.chdir(app_path) do
283282
rails "generate", "model", "book", "title:string"

0 commit comments

Comments
 (0)