1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

add a session authorization setter to the pg connection

This commit is contained in:
Aaron Patterson 2010-10-21 11:26:16 -07:00
parent 1741bbe2d5
commit 9d9aed433b
2 changed files with 13 additions and 1 deletions

View file

@ -389,6 +389,11 @@ module ActiveRecord
end
end
# Set the authorized user for this session
def session_auth=(user)
exec "SET SESSION AUTHORIZATION #{user}"
end
# REFERENTIAL INTEGRITY ====================================
def supports_disable_referential_integrity?() #:nodoc:

View file

@ -43,6 +43,13 @@ class SchemaAuthorizationTest < ActiveRecord::TestCase
end
end
def test_session_auth=
assert_raise(ActiveRecord::StatementInvalid) do
@connection.session_auth = 'DEFAULT'
@connection.execute "SELECT * FROM #{TABLE_NAME}"
end
end
def test_auth_with_bind
assert_nothing_raised do
set_session_auth
@ -90,7 +97,7 @@ class SchemaAuthorizationTest < ActiveRecord::TestCase
private
def set_session_auth auth = nil
@connection.execute "SET SESSION AUTHORIZATION #{auth || 'default'}"
@connection.session_auth = auth || 'default'
end
end