aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorAleksey Magusev <lexmag@gmail.com>2012-07-11 01:38:21 +0400
committerAleksey Magusev <lexmag@gmail.com>2012-07-18 00:13:19 +0400
commit211d88b71b3df2ae161b23579a79f8e937132388 (patch)
tree531ae144bfd1e3fa8bcad17d31547d4dd4d84bb2 /activerecord/test
parentd4811702510bf289bb07ce93263cd04d49e96bea (diff)
downloadrails-211d88b71b3df2ae161b23579a79f8e937132388.tar.gz
rails-211d88b71b3df2ae161b23579a79f8e937132388.tar.bz2
rails-211d88b71b3df2ae161b23579a79f8e937132388.zip
Add join table migration generator
For instance, running rails g migration CreateMediaJoinTable artists musics:uniq will create a migration with create_join_table :artists, :musics do |t| # t.index [:artist_id, :music_id] t.index [:music_id, :artist_id], unique: true end
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/migration/create_join_table_test.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/activerecord/test/cases/migration/create_join_table_test.rb b/activerecord/test/cases/migration/create_join_table_test.rb
index 8b91b3bc92..cd1b0e8b47 100644
--- a/activerecord/test/cases/migration/create_join_table_test.rb
+++ b/activerecord/test/cases/migration/create_join_table_test.rb
@@ -42,22 +42,36 @@ module ActiveRecord
end
def test_create_join_table_with_the_table_name
- connection.create_join_table :artists, :musics, :table_name => :catalog
+ connection.create_join_table :artists, :musics, table_name: :catalog
assert_equal %w(artist_id music_id), connection.columns(:catalog).map(&:name).sort
end
def test_create_join_table_with_the_table_name_as_string
- connection.create_join_table :artists, :musics, :table_name => 'catalog'
+ connection.create_join_table :artists, :musics, table_name: 'catalog'
assert_equal %w(artist_id music_id), connection.columns(:catalog).map(&:name).sort
end
def test_create_join_table_with_column_options
- connection.create_join_table :artists, :musics, :column_options => {:null => true}
+ connection.create_join_table :artists, :musics, column_options: {null: true}
assert_equal [true, true], connection.columns(:artists_musics).map(&:null)
end
+
+ def test_create_join_table_without_indexes
+ connection.create_join_table :artists, :musics
+
+ assert connection.indexes(:artists_musics).blank?
+ end
+
+ def test_create_join_table_with_index
+ connection.create_join_table :artists, :musics do |t|
+ t.index [:artist_id, :music_id]
+ end
+
+ assert_equal [%w(artist_id music_id)], connection.indexes(:artists_musics).map(&:columns)
+ end
end
end
end