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:
parent
1741bbe2d5
commit
9d9aed433b
2 changed files with 13 additions and 1 deletions
|
@ -389,6 +389,11 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set the authorized user for this session
|
||||||
|
def session_auth=(user)
|
||||||
|
exec "SET SESSION AUTHORIZATION #{user}"
|
||||||
|
end
|
||||||
|
|
||||||
# REFERENTIAL INTEGRITY ====================================
|
# REFERENTIAL INTEGRITY ====================================
|
||||||
|
|
||||||
def supports_disable_referential_integrity?() #:nodoc:
|
def supports_disable_referential_integrity?() #:nodoc:
|
||||||
|
|
|
@ -43,6 +43,13 @@ class SchemaAuthorizationTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
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
|
def test_auth_with_bind
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
set_session_auth
|
set_session_auth
|
||||||
|
@ -90,7 +97,7 @@ class SchemaAuthorizationTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
private
|
private
|
||||||
def set_session_auth auth = nil
|
def set_session_auth auth = nil
|
||||||
@connection.execute "SET SESSION AUTHORIZATION #{auth || 'default'}"
|
@connection.session_auth = auth || 'default'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue