diff options
author | Aleksey Magusev <lexmag@gmail.com> | 2012-07-11 01:38:21 +0400 |
---|---|---|
committer | Aleksey Magusev <lexmag@gmail.com> | 2012-07-18 00:13:19 +0400 |
commit | 211d88b71b3df2ae161b23579a79f8e937132388 (patch) | |
tree | 531ae144bfd1e3fa8bcad17d31547d4dd4d84bb2 /railties/test | |
parent | d4811702510bf289bb07ce93263cd04d49e96bea (diff) | |
download | rails-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 'railties/test')
-rw-r--r-- | railties/test/generators/migration_generator_test.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 86e3793289..9f9cd9c9fc 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -167,6 +167,19 @@ class MigrationGeneratorTest < Rails::Generators::TestCase end end + def test_create_join_table_migration + migration = "add_media_join_table" + run_generator [migration, "artists", "musics:uniq"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :change, content do |up| + assert_match(/create_join_table :artists, :musics/, up) + assert_match(/# t.index \[:artist_id, :music_id\]/, up) + assert_match(/ t.index \[:music_id, :artist_id\], unique: true/, up) + end + end + end + def test_should_create_empty_migrations_if_name_not_start_with_add_or_remove migration = "create_books" run_generator [migration, "title:string", "content:text"] |