diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-03-11 08:27:59 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-03-11 08:27:59 +0100 |
commit | 3f5339f48e3ce3eb40eb51fb1b686914a719a26a (patch) | |
tree | f13548cf09b52568d078e0ba776067f02757fd04 | |
parent | 0e0b41d58c0a8e5921b7eebc3a6e0e4cc012ce4d (diff) | |
download | rails-3f5339f48e3ce3eb40eb51fb1b686914a719a26a.tar.gz rails-3f5339f48e3ce3eb40eb51fb1b686914a719a26a.tar.bz2 rails-3f5339f48e3ce3eb40eb51fb1b686914a719a26a.zip |
`change_table` supports `citext`. Follow up to #12523.
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/citext_test.rb | 35 |
2 files changed, 31 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index f7b053aec6..e5f7913c70 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -355,6 +355,10 @@ module ActiveRecord def json(name, options = {}) column(name, 'json', options) end + + def citext(name, options = {}) + column(name, 'citext', options) + end end class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition diff --git a/activerecord/test/cases/adapters/postgresql/citext_test.rb b/activerecord/test/cases/adapters/postgresql/citext_test.rb index 89ef46b539..ebb9ff98b1 100644 --- a/activerecord/test/cases/adapters/postgresql/citext_test.rb +++ b/activerecord/test/cases/adapters/postgresql/citext_test.rb @@ -19,10 +19,8 @@ class PostgresqlCitextTest < ActiveRecord::TestCase @connection.reconnect! - @connection.transaction do - @connection.create_table('citexts') do |t| - t.citext 'cival' - end + @connection.create_table('citexts') do |t| + t.citext 'cival' end @column = Citext.columns_hash['cival'] end @@ -44,15 +42,36 @@ class PostgresqlCitextTest < ActiveRecord::TestCase assert_equal 'citext', @column.sql_type end + def test_change_table_supports_json + @connection.transaction do + @connection.change_table('citexts') do |t| + t.citext 'username' + end + Citext.reset_column_information + column = Citext.columns.find { |c| c.name == 'username' } + assert_equal :citext, column.type + + raise ActiveRecord::Rollback # reset the schema change + end + ensure + Citext.reset_column_information + end + def test_write x = Citext.new(cival: 'Some CI Text') - assert x.save! + x.save! + citext = Citext.first + assert_equal "Some CI Text", citext.cival + + citext.cival = "Some NEW CI Text" + citext.save! + + assert_equal "Some NEW CI Text", citext.reload.cival end def test_select_case_insensitive @connection.execute "insert into citexts (cival) values('Cased Text')" x = Citext.where(cival: 'cased text').first - assert_equal('Cased Text', x.cival) + assert_equal 'Cased Text', x.cival end - -end
\ No newline at end of file +end |