Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 0cdd3dd0a5
Fetching contributors…

Cannot retrieve contributors at this time

83 lines (70 sloc) 2.608 kB
require File.dirname(__FILE__) + '/helper'
class MysqlAdapterTest < ActiveRecord::TestCase
include Foreigner::MysqlAdapter
def test_add_without_options
assert_equal(
"ALTER TABLE `employees` ADD CONSTRAINT `employees_company_id_fk` FOREIGN KEY (`company_id`) REFERENCES `companies`(id)",
add_foreign_key(:employees, :companies)
)
end
def test_add_with_name
assert_equal(
"ALTER TABLE `employees` ADD CONSTRAINT `favorite_company_fk` FOREIGN KEY (`company_id`) REFERENCES `companies`(id)",
add_foreign_key(:employees, :companies, :name => 'favorite_company_fk')
)
end
def test_add_with_column
assert_equal(
"ALTER TABLE `employees` ADD CONSTRAINT `employees_last_employer_id_fk` FOREIGN KEY (`last_employer_id`) REFERENCES `companies`(id)",
add_foreign_key(:employees, :companies, :column => 'last_employer_id')
)
end
def test_add_with_column_and_name
assert_equal(
"ALTER TABLE `employees` ADD CONSTRAINT `favorite_company_fk` FOREIGN KEY (`last_employer_id`) REFERENCES `companies`(id)",
add_foreign_key(:employees, :companies, :column => 'last_employer_id', :name => 'favorite_company_fk')
)
end
def test_add_with_delete_dependency
assert_equal(
"ALTER TABLE `employees` ADD CONSTRAINT `employees_company_id_fk` FOREIGN KEY (`company_id`) REFERENCES `companies`(id) " +
"ON DELETE CASCADE",
add_foreign_key(:employees, :companies, :dependent => :delete)
)
end
def test_add_with_nullify_dependency
assert_equal(
"ALTER TABLE `employees` ADD CONSTRAINT `employees_company_id_fk` FOREIGN KEY (`company_id`) REFERENCES `companies`(id) " +
"ON DELETE SET NULL",
add_foreign_key(:employees, :companies, :dependent => :nullify)
)
end
def test_remove_by_table
assert_equal(
"ALTER TABLE `suppliers` DROP FOREIGN KEY `suppliers_company_id_fk`",
remove_foreign_key(:suppliers, :companies)
)
end
def test_remove_by_name
assert_equal(
"ALTER TABLE `suppliers` DROP FOREIGN KEY `belongs_to_supplier`",
remove_foreign_key(:suppliers, :name => "belongs_to_supplier")
)
end
def test_remove_by_column
assert_equal(
"ALTER TABLE `suppliers` DROP FOREIGN KEY `suppliers_ship_to_id_fk`",
remove_foreign_key(:suppliers, :column => "ship_to_id")
)
end
private
def execute(sql, name = nil)
sql
end
def quote_column_name(name)
"`#{name}`"
end
def quote_table_name(name)
quote_column_name(name).gsub('.', '`.`')
end
end
Jump to Line
Something went wrong with that request. Please try again.