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
16 changes: 12 additions & 4 deletions lib/fx/adapters/postgres/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ class Postgres
#
# @api private
class Connection < SimpleDelegator
# https://www.postgresql.org/docs/9.6/sql-dropfunction.html
# https://www.postgresql.org/docs/10/sql-dropfunction.html
# PostgreSQL version constants for feature support
POSTGRES_VERSIONS = {
# PostgreSQL 10.0 - introduced DROP FUNCTION without args
# https://www.postgresql.org/docs/10/sql-dropfunction.html
v10: 10_00_00
}.freeze

def support_drop_function_without_args
pg_connection = undecorated_connection.raw_connection
pg_connection.server_version >= 10_00_00
server_version >= POSTGRES_VERSIONS[:v10]
end

private

def server_version
undecorated_connection.raw_connection.server_version
end

def undecorated_connection
__getobj__
end
Expand Down
42 changes: 42 additions & 0 deletions spec/fx/adapters/postgres_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,46 @@
expect(adapter.triggers.map(&:name)).to eq ["uppercase_users_name"]
end
end

describe "#support_drop_function_without_args" do
it "returns true for PostgreSQL version 10.0" do
adapter = Fx::Adapters::Postgres.new
connection = adapter.send(:connection)
allow(connection).to receive(:server_version).and_return(10_00_00)

result = connection.support_drop_function_without_args

expect(result).to be(true)
end

it "returns true for PostgreSQL version 11.0" do
adapter = Fx::Adapters::Postgres.new
connection = adapter.send(:connection)
allow(connection).to receive(:server_version).and_return(11_00_00)

result = connection.support_drop_function_without_args

expect(result).to be(true)
end

it "returns false for PostgreSQL version 9.6" do
adapter = Fx::Adapters::Postgres.new
connection = adapter.send(:connection)
allow(connection).to receive(:server_version).and_return(9_06_00)

result = connection.support_drop_function_without_args

expect(result).to be(false)
end

it "returns false for PostgreSQL version 9.5" do
adapter = Fx::Adapters::Postgres.new
connection = adapter.send(:connection)
allow(connection).to receive(:server_version).and_return(9_05_00)

result = connection.support_drop_function_without_args

expect(result).to be(false)
end
end
end