diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-10-10 14:41:14 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-10-25 08:35:35 +0200 |
commit | 0492ea6d39e48c5bdb1d15eb4afdd54b00ece091 (patch) | |
tree | 06677dc32ad6034e837bf22f26a1ec1642290ca6 /activerecord/test | |
parent | bf43b4c33fe323448a714854327fdabdcb3c7a14 (diff) | |
download | rails-0492ea6d39e48c5bdb1d15eb4afdd54b00ece091.tar.gz rails-0492ea6d39e48c5bdb1d15eb4afdd54b00ece091.tar.bz2 rails-0492ea6d39e48c5bdb1d15eb4afdd54b00ece091.zip |
`ActiveRecord::Store` works together with PG `hstore` columns.
This is necessary because as of 5ac2341 `hstore` columns are always stored
as `Hash` with `String` keys. `ActiveRecord::Store` expected the attribute to
be an instance of `HashWithIndifferentAccess`, which led to the bug.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/hstore_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/hstore_test.rb b/activerecord/test/cases/adapters/postgresql/hstore_test.rb index f61f196c71..de724486c2 100644 --- a/activerecord/test/cases/adapters/postgresql/hstore_test.rb +++ b/activerecord/test/cases/adapters/postgresql/hstore_test.rb @@ -7,6 +7,8 @@ require 'active_record/connection_adapters/postgresql_adapter' class PostgresqlHstoreTest < ActiveRecord::TestCase class Hstore < ActiveRecord::Base self.table_name = 'hstores' + + store_accessor :settings, :language, :timezone end def setup @@ -26,6 +28,7 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase @connection.transaction do @connection.create_table('hstores') do |t| t.hstore 'tags', :default => '' + t.hstore 'settings' end end @column = Hstore.columns.find { |c| c.name == 'tags' } @@ -90,6 +93,24 @@ class PostgresqlHstoreTest < ActiveRecord::TestCase assert_equal({'c'=>'}','"a"'=>'b "a b'}, @column.type_cast(%q(c=>"}", "\"a\""=>"b \"a b"))) end + def test_with_store_accessors + x = Hstore.new(language: "fr", timezone: "GMT") + assert_equal "fr", x.language + assert_equal "GMT", x.timezone + + x.save! + x = Hstore.first + assert_equal "fr", x.language + assert_equal "GMT", x.timezone + + x.language = "de" + x.save! + + x = Hstore.first + assert_equal "de", x.language + assert_equal "GMT", x.timezone + end + def test_gen1 assert_equal(%q(" "=>""), @column.class.hstore_to_string({' '=>''})) end |