diff options
author | Ken Mazaika <kenmazaika@gmail.com> | 2013-03-27 00:30:11 -0400 |
---|---|---|
committer | Ken Mazaika <kenmazaika@gmail.com> | 2013-03-27 23:35:54 -0400 |
commit | 9600e0b02973ce5dd36642511d542a6b62983a5e (patch) | |
tree | 9f8317610a85ef1e74b49ac08cbc329a03be6908 /activerecord/test/cases/adapters | |
parent | 0739d146bcd31247391d64b852885634d78e576d (diff) | |
download | rails-9600e0b02973ce5dd36642511d542a6b62983a5e.tar.gz rails-9600e0b02973ce5dd36642511d542a6b62983a5e.tar.bz2 rails-9600e0b02973ce5dd36642511d542a6b62983a5e.zip |
Add support for FULLTEXT and SPATIAL indexes using the :type flag for MySQL.
Diffstat (limited to 'activerecord/test/cases/adapters')
4 files changed, 46 insertions, 30 deletions
diff --git a/activerecord/test/cases/adapters/mysql/active_schema_test.rb b/activerecord/test/cases/adapters/mysql/active_schema_test.rb index 9050ae3fe3..e6d0183b11 100644 --- a/activerecord/test/cases/adapters/mysql/active_schema_test.rb +++ b/activerecord/test/cases/adapters/mysql/active_schema_test.rb @@ -36,9 +36,14 @@ class ActiveSchemaTest < ActiveRecord::TestCase expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(10)) " assert_equal expected, add_index(:people, [:last_name, :first_name], :length => {:last_name => 15, :first_name => 10}) - %w(btree hash).each do |type| - expected = "CREATE INDEX `index_people_on_last_name` USING #{type} ON `people` (`last_name`) " - assert_equal expected, add_index(:people, :last_name, :using => type) + %w(SPATIAL FULLTEXT UNIQUE).each do |type| + expected = "CREATE #{type} INDEX `index_people_on_last_name` ON `people` (`last_name`) " + assert_equal expected, add_index(:people, :last_name, :type => type) + end + + %w(btree hash).each do |using| + expected = "CREATE INDEX `index_people_on_last_name` USING #{using} ON `people` (`last_name`) " + assert_equal expected, add_index(:people, :last_name, :using => using) end expected = "CREATE INDEX `index_people_on_last_name` USING btree ON `people` (`last_name`(10)) " diff --git a/activerecord/test/cases/adapters/mysql/schema_test.rb b/activerecord/test/cases/adapters/mysql/schema_test.rb index e6e54bf20a..807a7a155e 100644 --- a/activerecord/test/cases/adapters/mysql/schema_test.rb +++ b/activerecord/test/cases/adapters/mysql/schema_test.rb @@ -37,22 +37,25 @@ module ActiveRecord end def test_dump_indexes - index_a_name = 'index_post_title' - index_b_name = 'index_post_body' + index_a_name = 'index_key_tests_on_snack' + index_b_name = 'index_key_tests_on_pizza' + index_c_name = 'index_key_tests_on_awesome' - table = Post.table_name - - @connection.execute "CREATE INDEX `#{index_a_name}` ON `#{table}` (`title`);" - @connection.execute "CREATE INDEX `#{index_b_name}` USING btree ON `#{table}` (`body`(10));" + table = 'key_tests' indexes = @connection.indexes(table).sort_by {|i| i.name} - assert_equal 2,indexes.size - - assert_equal :btree, indexes.select{|i| i.name == index_a_name}[0].using - assert_equal :btree, indexes.select{|i| i.name == index_b_name}[0].using - - @connection.execute "DROP INDEX `#{index_a_name}` ON `#{table}`;" - @connection.execute "DROP INDEX `#{index_b_name}` ON `#{table}`;" + assert_equal 3,indexes.size + + index_a = indexes.select{|i| i.name == index_a_name}[0] + index_b = indexes.select{|i| i.name == index_b_name}[0] + index_c = indexes.select{|i| i.name == index_c_name}[0] + assert_equal :btree, index_a.using + assert_nil index_a.type + assert_equal :btree, index_b.using + assert_nil index_b.type + + assert_nil index_c.using + assert_equal :fulltext, index_c.type end end end diff --git a/activerecord/test/cases/adapters/mysql2/active_schema_test.rb b/activerecord/test/cases/adapters/mysql2/active_schema_test.rb index 48d63aeef5..8a2a7ef269 100644 --- a/activerecord/test/cases/adapters/mysql2/active_schema_test.rb +++ b/activerecord/test/cases/adapters/mysql2/active_schema_test.rb @@ -36,9 +36,14 @@ class ActiveSchemaTest < ActiveRecord::TestCase expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(10)) " assert_equal expected, add_index(:people, [:last_name, :first_name], :length => {:last_name => 15, :first_name => 10}) - %w(btree hash).each do |type| - expected = "CREATE INDEX `index_people_on_last_name` USING #{type} ON `people` (`last_name`) " - assert_equal expected, add_index(:people, :last_name, :using => type) + %w(SPATIAL FULLTEXT UNIQUE).each do |type| + expected = "CREATE #{type} INDEX `index_people_on_last_name` ON `people` (`last_name`) " + assert_equal expected, add_index(:people, :last_name, :type => type) + end + + %w(btree hash).each do |using| + expected = "CREATE INDEX `index_people_on_last_name` USING #{using} ON `people` (`last_name`) " + assert_equal expected, add_index(:people, :last_name, :using => using) end expected = "CREATE INDEX `index_people_on_last_name` USING btree ON `people` (`last_name`(10)) " diff --git a/activerecord/test/cases/adapters/mysql2/schema_test.rb b/activerecord/test/cases/adapters/mysql2/schema_test.rb index 78f754d2ce..5db60ff8a0 100644 --- a/activerecord/test/cases/adapters/mysql2/schema_test.rb +++ b/activerecord/test/cases/adapters/mysql2/schema_test.rb @@ -45,22 +45,25 @@ module ActiveRecord end def test_dump_indexes - index_a_name = 'index_post_title' - index_b_name = 'index_post_body' + index_a_name = 'index_key_tests_on_snack' + index_b_name = 'index_key_tests_on_pizza' + index_c_name = 'index_key_tests_on_awesome' - table = Post.table_name - - @connection.execute "CREATE INDEX `#{index_a_name}` ON `#{table}` (`title`);" - @connection.execute "CREATE INDEX `#{index_b_name}` USING btree ON `#{table}` (`body`(10));" + table = 'key_tests' indexes = @connection.indexes(table).sort_by {|i| i.name} - assert_equal 2,indexes.size + assert_equal 3,indexes.size - assert_equal :btree, indexes.select{|i| i.name == index_a_name}[0].using - assert_equal :btree, indexes.select{|i| i.name == index_b_name}[0].using + index_a = indexes.select{|i| i.name == index_a_name}[0] + index_b = indexes.select{|i| i.name == index_b_name}[0] + index_c = indexes.select{|i| i.name == index_c_name}[0] + assert_equal :btree, index_a.using + assert_nil index_a.type + assert_equal :btree, index_b.using + assert_nil index_b.type - @connection.execute "DROP INDEX `#{index_a_name}` ON `#{table}`;" - @connection.execute "DROP INDEX `#{index_b_name}` ON `#{table}`;" + assert_nil index_c.using + assert_equal :fulltext, index_c.type end end end |