Skip to content

Commit

Permalink
Add PG::DEF_PGPORT constant and use it in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
larskanis committed Nov 17, 2022
1 parent dbff785 commit e0a0796
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ext/pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,9 @@ Init_pg_ext(void)
rb_define_const(rb_mPGconstants, "INVALID_OID", INT2FIX(InvalidOid));
rb_define_const(rb_mPGconstants, "InvalidOid", INT2FIX(InvalidOid));

/* PostgreSQL compiled in default port */
rb_define_const(rb_mPGconstants, "DEF_PGPORT", INT2FIX(DEF_PGPORT));

/* Add the constants to the toplevel namespace */
rb_include_module( rb_mPG, rb_mPGconstants );

Expand Down
6 changes: 3 additions & 3 deletions spec/pg/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -736,19 +736,19 @@
external_host: 'localhost',
external_port: ENV['PGPORT'].to_i,
internal_host: "127.0.0.1",
internal_port: 5432,
internal_port: PG::DEF_PGPORT,
debug: ENV['PG_DEBUG']=='1')

PG.connect(host: "localhost",
port: "",
dbname: "test") do |conn|
expect( conn.port ).to eq( 5432 )
expect( conn.port ).to eq( PG::DEF_PGPORT )
end

PG.connect(hostaddr: "127.0.0.1",
port: nil,
dbname: "test") do |conn|
expect( conn.port ).to eq( 5432 )
expect( conn.port ).to eq( PG::DEF_PGPORT )
end

gate.finish
Expand Down

0 comments on commit e0a0796

Please sign in to comment.