multiple key / values work

This commit is contained in:
Aaron Patterson 2011-12-19 21:19:09 -08:00
parent 776af48acb
commit 135b3a0dde
2 changed files with 10 additions and 1 deletions

@ -51,7 +51,10 @@ def string_to_time(string)
end
def cast_hstore(string)
Hash[[string.split('=>').map { |k| k[1...-1] }]]
kvs = string.split(', ').map { |kv|
kv.split('=>').map { |k| k[1...-1] }
}
Hash[kvs]
end
end
# :startdoc:

@ -37,4 +37,10 @@ def test_select
x = Hstore.find :first
assert_equal({'1' => '2'}, x.tags)
end
def test_select_multikey
@connection.execute "insert into hstores (tags) VALUES ('1=>2,2=>3')"
x = Hstore.find :first
assert_equal({'1' => '2', '2' => '3'}, x.tags)
end
end