3
class SchemaThing < ActiveRecord::Base
6
class SchemaAuthorizationTest < ActiveRecord::TestCase
7
self.use_transactional_fixtures = false
9
TABLE_NAME = 'schema_things'
11
'id serial primary key',
12
'name character varying(50)'
14
USERS = ['rails_pg_schema_user1', 'rails_pg_schema_user2']
17
@connection = ActiveRecord::Base.connection
18
@connection.execute "SET search_path TO '$user',public"
21
@connection.execute "CREATE USER #{u}" rescue nil
22
@connection.execute "CREATE SCHEMA AUTHORIZATION #{u}" rescue nil
24
@connection.execute "CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})"
25
@connection.execute "INSERT INTO #{TABLE_NAME} (name) VALUES ('#{u}')"
32
@connection.execute "RESET search_path"
34
@connection.execute "DROP SCHEMA #{u} CASCADE"
35
@connection.execute "DROP USER #{u}"
39
def test_schema_invisible
40
assert_raise(ActiveRecord::StatementInvalid) do
42
@connection.execute "SELECT * FROM #{TABLE_NAME}"
46
def test_schema_uniqueness
47
assert_nothing_raised do
51
assert_equal u, @connection.select_value("SELECT name FROM #{TABLE_NAME} WHERE id = 1")
57
def test_sequence_schema_caching
58
assert_nothing_raised do
61
st = SchemaThing.new :name => 'TEST1'
63
st = SchemaThing.new :id => 5, :name => 'TEST2'
71
def set_session_auth auth = nil
72
@connection.execute "SET SESSION AUTHORIZATION #{auth || 'default'}"