aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-10-21 11:26:16 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-10-26 13:44:11 -0700
commit9d9aed433bd29eefb14807c02050cb8b88f15f0e (patch)
treef437803fdac6f0e11075ee77208655e9304e3da9 /activerecord
parent1741bbe2d5cb58af76fb2ca31a25c05eadfadb71 (diff)
downloadrails-9d9aed433bd29eefb14807c02050cb8b88f15f0e.tar.gz
rails-9d9aed433bd29eefb14807c02050cb8b88f15f0e.tar.bz2
rails-9d9aed433bd29eefb14807c02050cb8b88f15f0e.zip
add a session authorization setter to the pg connection
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb5
-rw-r--r--activerecord/test/cases/adapters/postgresql/schema_authorization_test.rb9
2 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 64a07cccca..e785cc6fea 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -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:
diff --git a/activerecord/test/cases/adapters/postgresql/schema_authorization_test.rb b/activerecord/test/cases/adapters/postgresql/schema_authorization_test.rb
index 8fdda20f77..dc4f8fb955 100644
--- a/activerecord/test/cases/adapters/postgresql/schema_authorization_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/schema_authorization_test.rb
@@ -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