Skip to content

Commit

Permalink
Use 127.0.0.1 instead of localhost so Docker DB can be easily used (r…
Browse files Browse the repository at this point in the history
…ails#52778)

* Use 127.0.0.1 instead of localhost so Docker DB can be easily used

* Fix tests
  • Loading branch information
dhh authored Sep 3, 2024
1 parent 66a9d11 commit dd3f743
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion railties/lib/rails/generators/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def socket
end

def host
"localhost"
"127.0.0.1"
end
end

Expand Down
8 changes: 4 additions & 4 deletions railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ def test_devcontainer_mysql
assert_includes content["forwardPorts"], 3306
end
assert_file("config/database.yml") do |content|
assert_match(/host: <%= ENV.fetch\("DB_HOST"\) \{ "localhost" } %>/, content)
assert_match(/host: <%= ENV.fetch\("DB_HOST"\) \{ "127.0.0.1" } %>/, content)
end
end

Expand Down Expand Up @@ -1393,7 +1393,7 @@ def test_devcontainer_trilogy
assert_includes(content["forwardPorts"], 3306)
end
assert_file("config/database.yml") do |content|
assert_match(/host: <%= ENV.fetch\("DB_HOST"\) \{ "localhost" } %>/, content)
assert_match(/host: <%= ENV.fetch\("DB_HOST"\) \{ "127.0.0.1" } %>/, content)
end
end

Expand Down Expand Up @@ -1421,7 +1421,7 @@ def test_devcontainer_mariadb_mysql
assert_includes(content["forwardPorts"], 3306)
end
assert_file("config/database.yml") do |content|
assert_match(/host: <%= ENV.fetch\("DB_HOST"\) \{ "localhost" } %>/, content)
assert_match(/host: <%= ENV.fetch\("DB_HOST"\) \{ "127.0.0.1" } %>/, content)
end
end

Expand All @@ -1448,7 +1448,7 @@ def test_devcontainer_mariadb_trilogy
assert_includes(content["forwardPorts"], 3306)
end
assert_file("config/database.yml") do |content|
assert_match(/host: <%= ENV.fetch\("DB_HOST"\) \{ "localhost" } %>/, content)
assert_match(/host: <%= ENV.fetch\("DB_HOST"\) \{ "127.0.0.1" } %>/, content)
end
end

Expand Down

0 comments on commit dd3f743

Please sign in to comment.