Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17574 from kamipo/charset_collation_options
Add charset and collation options support for MySQL string and text columns.
- Loading branch information
Showing
8 changed files
with
172 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
activerecord/test/cases/adapters/mysql/charset_collation_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "cases/helper" | ||
require 'support/schema_dumping_helper' | ||
|
||
class CharsetCollationTest < ActiveRecord::TestCase | ||
include SchemaDumpingHelper | ||
self.use_transactional_fixtures = false | ||
|
||
setup do | ||
@connection = ActiveRecord::Base.connection | ||
@connection.create_table :charset_collations, force: true do |t| | ||
t.string :string_ascii_bin, charset: 'ascii', collation: 'ascii_bin' | ||
t.text :text_ucs2_unicode_ci, charset: 'ucs2', collation: 'ucs2_unicode_ci' | ||
end | ||
end | ||
|
||
teardown do | ||
@connection.drop_table :charset_collations, if_exists: true | ||
end | ||
|
||
test "string column with charset and collation" do | ||
column = @connection.columns(:charset_collations).find { |c| c.name == 'string_ascii_bin' } | ||
assert_equal :string, column.type | ||
assert_equal 'ascii_bin', column.collation | ||
end | ||
|
||
test "text column with charset and collation" do | ||
column = @connection.columns(:charset_collations).find { |c| c.name == 'text_ucs2_unicode_ci' } | ||
assert_equal :text, column.type | ||
assert_equal 'ucs2_unicode_ci', column.collation | ||
end | ||
|
||
test "add column with charset and collation" do | ||
@connection.add_column :charset_collations, :title, :string, charset: 'utf8', collation: 'utf8_bin' | ||
|
||
column = @connection.columns(:charset_collations).find { |c| c.name == 'title' } | ||
assert_equal :string, column.type | ||
assert_equal 'utf8_bin', column.collation | ||
end | ||
|
||
test "change column with charset and collation" do | ||
@connection.add_column :charset_collations, :description, :string, charset: 'utf8', collation: 'utf8_unicode_ci' | ||
@connection.change_column :charset_collations, :description, :text, charset: 'utf8', collation: 'utf8_general_ci' | ||
|
||
column = @connection.columns(:charset_collations).find { |c| c.name == 'description' } | ||
assert_equal :text, column.type | ||
assert_equal 'utf8_general_ci', column.collation | ||
end | ||
|
||
test "schema dump includes collation" do | ||
output = dump_table_schema("charset_collations") | ||
assert_match %r{t.string\s+"string_ascii_bin",\s+limit: 255,\s+collation: "ascii_bin"$}, output | ||
assert_match %r{t.text\s+"text_ucs2_unicode_ci",\s+limit: 65535,\s+collation: "ucs2_unicode_ci"$}, output | ||
end | ||
end |
54 changes: 54 additions & 0 deletions
54
activerecord/test/cases/adapters/mysql2/charset_collation_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "cases/helper" | ||
require 'support/schema_dumping_helper' | ||
|
||
class CharsetCollationTest < ActiveRecord::TestCase | ||
include SchemaDumpingHelper | ||
self.use_transactional_fixtures = false | ||
|
||
setup do | ||
@connection = ActiveRecord::Base.connection | ||
@connection.create_table :charset_collations, force: true do |t| | ||
t.string :string_ascii_bin, charset: 'ascii', collation: 'ascii_bin' | ||
t.text :text_ucs2_unicode_ci, charset: 'ucs2', collation: 'ucs2_unicode_ci' | ||
end | ||
end | ||
|
||
teardown do | ||
@connection.drop_table :charset_collations, if_exists: true | ||
end | ||
|
||
test "string column with charset and collation" do | ||
column = @connection.columns(:charset_collations).find { |c| c.name == 'string_ascii_bin' } | ||
assert_equal :string, column.type | ||
assert_equal 'ascii_bin', column.collation | ||
end | ||
|
||
test "text column with charset and collation" do | ||
column = @connection.columns(:charset_collations).find { |c| c.name == 'text_ucs2_unicode_ci' } | ||
assert_equal :text, column.type | ||
assert_equal 'ucs2_unicode_ci', column.collation | ||
end | ||
|
||
test "add column with charset and collation" do | ||
@connection.add_column :charset_collations, :title, :string, charset: 'utf8', collation: 'utf8_bin' | ||
|
||
column = @connection.columns(:charset_collations).find { |c| c.name == 'title' } | ||
assert_equal :string, column.type | ||
assert_equal 'utf8_bin', column.collation | ||
end | ||
|
||
test "change column with charset and collation" do | ||
@connection.add_column :charset_collations, :description, :string, charset: 'utf8', collation: 'utf8_unicode_ci' | ||
@connection.change_column :charset_collations, :description, :text, charset: 'utf8', collation: 'utf8_general_ci' | ||
|
||
column = @connection.columns(:charset_collations).find { |c| c.name == 'description' } | ||
assert_equal :text, column.type | ||
assert_equal 'utf8_general_ci', column.collation | ||
end | ||
|
||
test "schema dump includes collation" do | ||
output = dump_table_schema("charset_collations") | ||
assert_match %r{t.string\s+"string_ascii_bin",\s+limit: 255,\s+collation: "ascii_bin"$}, output | ||
assert_match %r{t.text\s+"text_ucs2_unicode_ci",\s+limit: 65535,\s+collation: "ucs2_unicode_ci"$}, output | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters