aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-06-12 22:05:30 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-06-12 22:05:30 +0000
commit1fde44bfee41a35469084e1c73e2bccbd4e5fbe8 (patch)
tree8b5e55bdb129f68cc1b9205e39a28e7dc28e8e20 /activerecord/test
parentc4a3634929b2739782da63dc4f00493add949b45 (diff)
downloadrails-1fde44bfee41a35469084e1c73e2bccbd4e5fbe8.tar.gz
rails-1fde44bfee41a35469084e1c73e2bccbd4e5fbe8.tar.bz2
rails-1fde44bfee41a35469084e1c73e2bccbd4e5fbe8.zip
r1278@iwill: jeremy | 2005-06-12 05:11:48 -0700
Branch for PostgreSQL schema. Ticket #827. r1281@iwill: jeremy | 2005-06-12 19:06:43 -0700 remove search_path from PostgreSQL db definition r1282@iwill: jeremy | 2005-06-12 19:07:50 -0700 Rakefile support for database-specific tests. r1283@iwill: jeremy | 2005-06-12 19:10:18 -0700 Add schema_search_path attribute to PostgreSQL adapter. Replace table_structure with column_definitions which finds the given table_name in the schema search path. r1284@iwill: jeremy | 2005-06-12 19:12:10 -0700 Unit test PostgreSQL schema search path. r1285@iwill: jeremy | 2005-06-12 19:12:20 -0700 Changelog entry. r1286@iwill: jeremy | 2005-06-12 20:08:20 -0700 Don't try to quote schema names. Include a reference to the PostgreSQL schema docs. r1287@iwill: jeremy | 2005-06-12 20:16:07 -0700 SchemasTest -> SchemaTest git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1407 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/fixtures/db_definitions/postgresql.sql2
-rw-r--r--activerecord/test/schema_test_postgresql.rb63
2 files changed, 63 insertions, 2 deletions
diff --git a/activerecord/test/fixtures/db_definitions/postgresql.sql b/activerecord/test/fixtures/db_definitions/postgresql.sql
index 6eb2304957..134f030f13 100644
--- a/activerecord/test/fixtures/db_definitions/postgresql.sql
+++ b/activerecord/test/fixtures/db_definitions/postgresql.sql
@@ -1,5 +1,3 @@
-SET search_path = public, pg_catalog;
-
CREATE TABLE accounts (
id serial,
firm_id integer,
diff --git a/activerecord/test/schema_test_postgresql.rb b/activerecord/test/schema_test_postgresql.rb
new file mode 100644
index 0000000000..7f7d85ae43
--- /dev/null
+++ b/activerecord/test/schema_test_postgresql.rb
@@ -0,0 +1,63 @@
+require 'abstract_unit'
+
+class SchemaTest < Test::Unit::TestCase
+ SCHEMA_NAME = 'test_schema'
+ TABLE_NAME = 'things'
+ COLUMNS = [
+ 'id integer',
+ 'name character varying(50)',
+ 'moment timestamp without time zone default now()'
+ ]
+
+ def setup
+ @connection = ActiveRecord::Base.connection
+ @connection.execute "CREATE SCHEMA #{SCHEMA_NAME} CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})"
+ end
+
+ def teardown
+ @connection.execute "DROP TABLE #{SCHEMA_NAME}.#{TABLE_NAME}"
+ @connection.execute "DROP SCHEMA #{SCHEMA_NAME}"
+ end
+
+ def test_with_schema_prefixed_table_name
+ assert_nothing_raised do
+ assert_equal COLUMNS, columns("#{SCHEMA_NAME}.#{TABLE_NAME}")
+ end
+ end
+
+ def test_with_schema_search_path
+ assert_nothing_raised do
+ with_schema_search_path(SCHEMA_NAME) do
+ assert_equal COLUMNS, columns(TABLE_NAME)
+ end
+ end
+ end
+
+ def test_raise_on_unquoted_schema_name
+ assert_raise(ActiveRecord::StatementInvalid) do
+ with_schema_search_path '$user,public'
+ end
+ end
+
+ def test_without_schema_search_path
+ assert_raise(ActiveRecord::StatementInvalid) { columns(TABLE_NAME) }
+ end
+
+ def test_ignore_nil_schema_search_path
+ assert_nothing_raised { with_schema_search_path nil }
+ end
+
+ private
+ def columns(table_name)
+ @connection.send(:column_definitions, table_name).map do |name, type, default|
+ "#{name} #{type}" + (default ? " default #{default}" : '')
+ end
+ end
+
+ def with_schema_search_path(schema_search_path)
+ @connection.schema_search_path = schema_search_path
+ yield if block_given?
+ ensure
+ @connection.schema_search_path = "'$user', public"
+ end
+end