Skip to content

Commit

Permalink
Merge pull request #45090 from davegudge/fix-pg-connect-ruby-27-warning
Browse files Browse the repository at this point in the history
Fix: PG.connect keyword arguments deprecation warning on ruby 2.7
  • Loading branch information
byroot committed May 15, 2022
2 parents 1672a71 + 6f83a44 commit 8e4d04c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Fix PG.connect keyword arguments deprecation warning on ruby 2.7

Fixes #44307.

*Nikita Vasilevsky*

## Rails 6.1.6 (May 09, 2022) ##

* No changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PostgreSQLAdapter < AbstractAdapter

class << self
def new_client(conn_params)
PG.connect(conn_params)
PG.connect(**conn_params)
rescue ::PG::Error => error
if conn_params && conn_params[:dbname] && error.message.include?(conn_params[:dbname])
raise ActiveRecord::NoDatabaseError
Expand Down Expand Up @@ -247,7 +247,7 @@ def connection_active?
def initialize(connection, logger, connection_parameters, config)
super(connection, logger, config)

@connection_parameters = connection_parameters
@connection_parameters = connection_parameters || {}

# @local_tz is initialized as nil to avoid warnings when connect tries to use it
@local_tz = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def exec_params(*)
end

def reset
raise PG::ConnectionBad
raise PG::ConnectionBad, "I'll be rescued by the reconnect method"
end

def close
Expand All @@ -53,8 +53,13 @@ def close
{ host: File::NULL }
)

assert_raises ActiveRecord::ConnectionNotEstablished do
@conn.reconnect!
connect_raises_error = proc { |_conn_params| raise(PG::ConnectionBad, "actual bad connection error") }
PG.stub(:connect, connect_raises_error) do
error = assert_raises ActiveRecord::ConnectionNotEstablished do
@conn.reconnect!
end

assert_equal("actual bad connection error", error.message)
end
end

Expand Down

0 comments on commit 8e4d04c

Please sign in to comment.