aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-12-19 21:16:23 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-12-20 14:04:50 -0600
commit776af48acb1035e70a326609ec5e5b632ef0c2c5 (patch)
tree5a423c1aee660d7582c766df7b5658c78bd52aa3 /activerecord/test/cases/adapters/postgresql
parent8cb7bc8b55e8054f66cd58840392e6cc63134a90 (diff)
downloadrails-776af48acb1035e70a326609ec5e5b632ef0c2c5.tar.gz
rails-776af48acb1035e70a326609ec5e5b632ef0c2c5.tar.bz2
rails-776af48acb1035e70a326609ec5e5b632ef0c2c5.zip
PostgreSQL hstore types are automatically deserialized from the database.
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql')
-rw-r--r--activerecord/test/cases/adapters/postgresql/hstore_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/hstore_test.rb b/activerecord/test/cases/adapters/postgresql/hstore_test.rb
index 155c6f593b..aa3bde09d8 100644
--- a/activerecord/test/cases/adapters/postgresql/hstore_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/hstore_test.rb
@@ -21,4 +21,20 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase
assert column
assert_equal :hstore, column.type
end
+
+ def test_type_cast_hstore
+ column = Hstore.columns.find { |c| c.name == 'tags' }
+ assert column
+
+ data = "\"1\"=>\"2\""
+ hash = column.class.cast_hstore data
+ assert_equal({'1' => '2'}, hash)
+ assert_equal({'1' => '2'}, column.type_cast(data))
+ end
+
+ def test_select
+ @connection.execute "insert into hstores (tags) VALUES ('1=>2')"
+ x = Hstore.find :first
+ assert_equal({'1' => '2'}, x.tags)
+ end
end