Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ruby-pg-extras.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ def self.connection
end

def self.database_url=(value)
@_connection&.close
@_connection = nil
@@database_url = value
end

Expand Down
12 changes: 12 additions & 0 deletions spec/smoke_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,17 @@
RubyPgExtras.bloat(in_format: :hash)
end.not_to raise_error
end

it "resets the connection when setting database URL" do
old_connection = RubyPgExtras.connection
expect(old_connection).not_to be_finished

RubyPgExtras.database_url = ENV.fetch("DATABASE_URL")

expect(old_connection).to be_finished
new_connection = RubyPgExtras.connection
expect(new_connection).not_to eq(old_connection)
expect(new_connection).not_to be_finished
end
end
end