forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 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
64 changes: 64 additions & 0 deletions
64
activerecord/test/cases/migration/create_join_table_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,64 @@ | ||
require "cases/migration/helper" | ||
|
||
module ActiveRecord | ||
class Migration | ||
class CreateJoinTableTest < ActiveRecord::TestCase | ||
include ActiveRecord::Migration::TestHelper | ||
|
||
self.use_transactional_fixtures = false | ||
|
||
def setup | ||
super | ||
end | ||
|
||
def test_create_join_table | ||
con = connection | ||
|
||
create_join_table :tie => :person, :to => :group | ||
|
||
table_name = "groups_people" | ||
assert con.table_exists?(table_name) | ||
|
||
columns = con.columns(table_name) | ||
assert !columns.find { |c| c.name == "group_id" }.null | ||
assert !columns.find { |c| c.name == "person_id" }.null | ||
|
||
assert !con.index_name_exists?(table_name, "index_groups_people_on_group_id", false) | ||
assert !con.index_name_exists?(table_name, "index_groups_people_on_person_id", false) | ||
ensure | ||
drop_join_table :tie => :person, :to => :group | ||
end | ||
|
||
def test_create_join_table_with_index | ||
con = connection | ||
|
||
create_join_table :tie => :person, :to => :group, :index => true | ||
|
||
table_name = "groups_people" | ||
assert con.index_name_exists?(table_name, "index_groups_people_on_group_id", false) | ||
assert con.index_name_exists?(table_name, "index_groups_people_on_person_id", false) | ||
ensure | ||
drop_join_table :tie => :person, :to => :group | ||
end | ||
|
||
def test_create_join_table_with_table_name_and_options | ||
table_name = "habtm" | ||
create_join_table table_name, :tie => :person, :to => :group | ||
assert connection.table_exists?(table_name) | ||
ensure | ||
drop_join_table table_name | ||
end | ||
|
||
private | ||
|
||
def create_join_table(*args) | ||
connection.create_join_table(*args) | ||
end | ||
|
||
def drop_join_table(*args) | ||
connection.drop_join_table(*args) | ||
end | ||
|
||
end | ||
end | ||
end |