diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-05-03 18:32:01 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-05-03 18:32:01 -0300 |
commit | 1515c4d98da3f730ef971fa5a13cad828bd9bef4 (patch) | |
tree | 4bbaa9baa7e048f8e54bceceb144cb94157d6f5c /activerecord/test/cases/adapters/postgresql/collation_test.rb | |
parent | 03b0911cff6545c84b83c1adca0e66822c336b2e (diff) | |
parent | f8e748b4e85996cb70a3e6f258944ad45f07a802 (diff) | |
download | rails-1515c4d98da3f730ef971fa5a13cad828bd9bef4.tar.gz rails-1515c4d98da3f730ef971fa5a13cad828bd9bef4.tar.bz2 rails-1515c4d98da3f730ef971fa5a13cad828bd9bef4.zip |
Merge pull request #19978 from kamipo/collation_option_support_for_postgresql
PostgreSQL: `:collation` support for string and text columns
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql/collation_test.rb')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/collation_test.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/collation_test.rb b/activerecord/test/cases/adapters/postgresql/collation_test.rb new file mode 100644 index 0000000000..17ef5f304c --- /dev/null +++ b/activerecord/test/cases/adapters/postgresql/collation_test.rb @@ -0,0 +1,53 @@ +require "cases/helper" +require 'support/schema_dumping_helper' + +class PostgresqlCollationTest < ActiveRecord::TestCase + include SchemaDumpingHelper + + def setup + @connection = ActiveRecord::Base.connection + @connection.create_table :postgresql_collations, force: true do |t| + t.string :string_c, collation: 'C' + t.text :text_posix, collation: 'POSIX' + end + end + + def teardown + @connection.drop_table :postgresql_collations, if_exists: true + end + + test "string column with collation" do + column = @connection.columns(:postgresql_collations).find { |c| c.name == 'string_c' } + assert_equal :string, column.type + assert_equal 'C', column.collation + end + + test "text column with collation" do + column = @connection.columns(:postgresql_collations).find { |c| c.name == 'text_posix' } + assert_equal :text, column.type + assert_equal 'POSIX', column.collation + end + + test "add column with collation" do + @connection.add_column :postgresql_collations, :title, :string, collation: 'C' + + column = @connection.columns(:postgresql_collations).find { |c| c.name == 'title' } + assert_equal :string, column.type + assert_equal 'C', column.collation + end + + test "change column with collation" do + @connection.add_column :postgresql_collations, :description, :string + @connection.change_column :postgresql_collations, :description, :text, collation: 'POSIX' + + column = @connection.columns(:postgresql_collations).find { |c| c.name == 'description' } + assert_equal :text, column.type + assert_equal 'POSIX', column.collation + end + + test "schema dump includes collation" do + output = dump_table_schema("postgresql_collations") + assert_match %r{t.string\s+"string_c",\s+collation: "C"$}, output + assert_match %r{t.text\s+"text_posix",\s+collation: "POSIX"$}, output + end +end |