blob: aa3bde09d8294a69bcf176350e7ad7350563bf3f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
require "cases/helper"
class PostgresqlHstoreTest < ActiveRecord::TestCase
class Hstore < ActiveRecord::Base
self.table_name = 'hstores'
end
def setup
@connection = ActiveRecord::Base.connection
@connection.create_table('hstores') do |t|
t.hstore 'tags'
end
end
def teardown
@connection.execute 'drop table if exists hstores'
end
def test_column
column = Hstore.columns.find { |c| c.name == 'tags' }
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
|