diff options
author | Aleksey Magusev <lexmag@gmail.com> | 2012-07-08 17:01:49 +0400 |
---|---|---|
committer | Aleksey Magusev <lexmag@gmail.com> | 2012-07-08 23:03:05 +0400 |
commit | 0cae7c60ac6e6209c3d9a7cc64ad2298b7e27fe4 (patch) | |
tree | e1c77adaa95e5f370914640cb37cfb39664bf516 /railties/test | |
parent | 7404cda9f61e41d52ce244d60abbf598684a96c4 (diff) | |
download | rails-0cae7c60ac6e6209c3d9a7cc64ad2298b7e27fe4.tar.gz rails-0cae7c60ac6e6209c3d9a7cc64ad2298b7e27fe4.tar.bz2 rails-0cae7c60ac6e6209c3d9a7cc64ad2298b7e27fe4.zip |
Add references statements to migration generator
AddXXXToYYY/RemoveXXXFromYYY migrations are produced with references
statements, for instance
rails g migration AddReferencesToProducts user:references
supplier:references{polymorphic}
will generate the migration with:
add_reference :products, :user, index: true
add_reference :products, :supplier, polymorphic: true, index: true
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/generators/migration_generator_test.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index b320e40654..86e3793289 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -76,6 +76,23 @@ class MigrationGeneratorTest < Rails::Generators::TestCase end end + def test_remove_migration_with_references_options + migration = "remove_references_from_books" + run_generator [migration, "author:belongs_to", "distributor:references{polymorphic}"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :up, content do |up| + assert_match(/remove_reference :books, :author/, up) + assert_match(/remove_reference :books, :distributor, polymorphic: true/, up) + end + + assert_method :down, content do |down| + assert_match(/add_reference :books, :author, index: true/, down) + assert_match(/add_reference :books, :distributor, polymorphic: true, index: true/, down) + end + end + end + def test_add_migration_with_attributes_and_indices migration = "add_title_with_index_and_body_to_posts" run_generator [migration, "title:string:index", "body:text", "user_id:integer:uniq"] @@ -138,6 +155,18 @@ class MigrationGeneratorTest < Rails::Generators::TestCase end end + def test_add_migration_with_references_options + migration = "add_references_to_books" + run_generator [migration, "author:belongs_to", "distributor:references{polymorphic}"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :change, content do |up| + assert_match(/add_reference :books, :author, index: true/, up) + assert_match(/add_reference :books, :distributor, polymorphic: true, index: 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"] |