aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-07-10 19:54:21 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-07-10 19:54:21 +0000
commitac681152051884c173486006089fc459cbf7128e (patch)
tree0e1af0d77512d3279a64b7facd19a9672f69196e /activerecord/test
parentf0c22d4ad5c61e7e683291fd42e143d1a339c3a2 (diff)
downloadrails-ac681152051884c173486006089fc459cbf7128e.tar.gz
rails-ac681152051884c173486006089fc459cbf7128e.tar.bz2
rails-ac681152051884c173486006089fc459cbf7128e.zip
PostgreSQL: return array fields as strings. Closes #4664.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4605 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/datatype_test_postgresql.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/activerecord/test/datatype_test_postgresql.rb b/activerecord/test/datatype_test_postgresql.rb
new file mode 100644
index 0000000000..c4c3318de4
--- /dev/null
+++ b/activerecord/test/datatype_test_postgresql.rb
@@ -0,0 +1,52 @@
+require 'abstract_unit'
+
+class PostgresqlDatatype < ActiveRecord::Base
+end
+
+class PGDataTypeTest < Test::Unit::TestCase
+ self.use_transactional_fixtures = false
+
+ TABLE_NAME = 'postgresql_datatypes'
+ COLUMNS = [
+ 'id SERIAL PRIMARY KEY',
+ 'commission_by_quarter INTEGER[]',
+ 'nicknames TEXT[]'
+ ]
+
+ def setup
+ @connection = ActiveRecord::Base.connection
+ @connection.execute "CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})"
+ @connection.execute "INSERT INTO #{TABLE_NAME} (commission_by_quarter, nicknames) VALUES ( '{35000,21000,18000,17000}', '{foo,bar,baz}' )"
+ @first = PostgresqlDatatype.find( 1 )
+ end
+
+ def teardown
+ @connection.execute "DROP TABLE #{TABLE_NAME}"
+ end
+
+ def test_data_type_of_array_types
+ assert_equal :string, @first.column_for_attribute("commission_by_quarter").type
+ assert_equal :string, @first.column_for_attribute("nicknames").type
+ end
+
+ def test_array_values
+ assert_equal '{35000,21000,18000,17000}', @first.commission_by_quarter
+ assert_equal '{foo,bar,baz}', @first.nicknames
+ end
+
+ def test_update_integer_array
+ new_value = '{32800,95000,29350,17000}'
+ assert @first.commission_by_quarter = new_value
+ assert @first.save
+ assert @first.reload
+ assert_equal @first.commission_by_quarter, new_value
+ end
+
+ def test_update_text_array
+ new_value = '{robby,robert,rob,robbie}'
+ assert @first.nicknames = new_value
+ assert @first.save
+ assert @first.reload
+ assert_equal @first.nicknames, new_value
+ end
+end