Skip to content

Commit 88d1915

Browse files
Use File::NULL instead of /dev/null
Some platforms (namely, Windows) use a path other than `/dev/null` to point to the null device. Ruby provides the `File::NULL` constant to specify that path in a cross-platform way.
1 parent d04dbcf commit 88d1915

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

activerecord/lib/active_record/tasks/postgresql_database_tasks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def structure_dump(filename, extra_flags)
8181
end
8282

8383
def structure_load(filename, extra_flags)
84-
args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename]
84+
args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename]
8585
args.concat(Array(extra_flags)) if extra_flags
8686
args << db_config.database
8787
run_cmd("psql", args, "loading")

activerecord/test/cases/tasks/postgresql_rake_test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def test_structure_load
531531
assert_called_with(
532532
Kernel,
533533
:system,
534-
[{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, @configuration["database"]],
534+
[{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, @configuration["database"]],
535535
returns: true
536536
) do
537537
ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename)
@@ -540,7 +540,7 @@ def test_structure_load
540540

541541
def test_structure_load_with_extra_flags
542542
filename = "awesome-file.sql"
543-
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]]
543+
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]
544544

545545
assert_called_with(Kernel, :system, expected_command, returns: true) do
546546
with_structure_load_flags(["--noop"]) do
@@ -552,7 +552,7 @@ def test_structure_load_with_extra_flags
552552
def test_structure_load_with_env
553553
filename = "awesome-file.sql"
554554
expected_env = { "PGHOST" => "my.server.tld", "PGPORT" => "2345", "PGUSER" => "jane", "PGPASSWORD" => "s3cr3t" }
555-
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]]
555+
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]
556556

557557
assert_called_with(Kernel, :system, expected_command, returns: true) do
558558
with_structure_load_flags(["--noop"]) do
@@ -567,7 +567,7 @@ def test_structure_load_with_env
567567
def test_structure_load_with_ssl_env
568568
filename = "awesome-file.sql"
569569
expected_env = { "PGSSLMODE" => "verify-full", "PGSSLCERT" => "client.crt", "PGSSLKEY" => "client.key", "PGSSLROOTCERT" => "root.crt" }
570-
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]]
570+
expected_command = [expected_env, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]
571571

572572
assert_called_with(Kernel, :system, expected_command, returns: true) do
573573
with_structure_load_flags(["--noop"]) do
@@ -581,7 +581,7 @@ def test_structure_load_with_ssl_env
581581

582582
def test_structure_load_with_hash_extra_flags_for_a_different_driver
583583
filename = "awesome-file.sql"
584-
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, @configuration["database"]]
584+
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, @configuration["database"]]
585585

586586
assert_called_with(Kernel, :system, expected_command, returns: true) do
587587
with_structure_load_flags({ mysql2: ["--noop"] }) do
@@ -592,7 +592,7 @@ def test_structure_load_with_hash_extra_flags_for_a_different_driver
592592

593593
def test_structure_load_with_hash_extra_flags_for_the_correct_driver
594594
filename = "awesome-file.sql"
595-
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, "--noop", @configuration["database"]]
595+
expected_command = [{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, "--noop", @configuration["database"]]
596596

597597
assert_called_with(Kernel, :system, expected_command, returns: true) do
598598
with_structure_load_flags({ postgresql: ["--noop"] }) do
@@ -606,7 +606,7 @@ def test_structure_load_accepts_path_with_spaces
606606
assert_called_with(
607607
Kernel,
608608
:system,
609-
[{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", "/dev/null", "--file", filename, @configuration["database"]],
609+
[{}, "psql", "--set", "ON_ERROR_STOP=1", "--quiet", "--no-psqlrc", "--output", File::NULL, "--file", filename, @configuration["database"]],
610610
returns: true
611611
) do
612612
ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename)

0 commit comments

Comments
 (0)