提交 323b7585 编写于 作者: J Josh Kalderimis

added the mysql schema test to mysql2 adapter, and fixed the corresponding failures

上级 d54ce712
...@@ -410,12 +410,27 @@ def collation ...@@ -410,12 +410,27 @@ def collation
show_variable 'collation_database' show_variable 'collation_database'
end end
def tables(name = nil) def tables(name = nil, database = nil) #:nodoc:
execute("SHOW TABLES", 'SCHEMA').collect do |field| sql = ["SHOW TABLES", database].compact.join(' IN ')
execute(sql, 'SCHEMA').collect do |field|
field.first field.first
end end
end end
def table_exists?(name)
return true if super
name = name.to_s
schema, table = name.split('.', 2)
unless table # A table was provided without a schema
table = schema
schema = nil
end
tables(nil, schema).include? table
end
def drop_table(table_name, options = {}) def drop_table(table_name, options = {})
super(table_name, options) super(table_name, options)
end end
......
...@@ -31,6 +31,6 @@ def test_table_exists? ...@@ -31,6 +31,6 @@ def test_table_exists?
def test_table_exists_wrong_schema def test_table_exists_wrong_schema
assert(!@connection.table_exists?("#{@db_name}.zomg"), "table should not exist") assert(!@connection.table_exists?("#{@db_name}.zomg"), "table should not exist")
end end
end if current_adapter?(:MysqlAdapter) end
end end
end end
require "cases/helper"
require 'models/post'
require 'models/comment'
module ActiveRecord
module ConnectionAdapters
class Mysql2SchemaTest < ActiveRecord::TestCase
fixtures :posts
def setup
@connection = ActiveRecord::Base.connection
db = Post.connection_pool.spec.config[:database]
table = Post.table_name
@db_name = db
@omgpost = Class.new(Post) do
set_table_name "#{db}.#{table}"
def self.name; 'Post'; end
end
end
def test_schema
assert @omgpost.find(:first)
end
def test_table_exists?
name = @omgpost.table_name
assert @connection.table_exists?(name), "#{name} table should exist"
end
def test_table_exists_wrong_schema
assert(!@connection.table_exists?("#{@db_name}.zomg"), "table should not exist")
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册