diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-08 12:12:15 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-08 12:12:15 -0700 |
commit | bbc08c759c13d654621c1eb0659f3bdd6a66dfd5 (patch) | |
tree | 52bec1a2902110134cb1819fd8c46ef194bd9962 /railties | |
parent | 22bc12ec374b8bdeb3818ca0a3eb787dd3ce39d8 (diff) | |
parent | 07ebc53d339a3f59f038c0b2663416c64a417885 (diff) | |
download | rails-bbc08c759c13d654621c1eb0659f3bdd6a66dfd5.tar.gz rails-bbc08c759c13d654621c1eb0659f3bdd6a66dfd5.tar.bz2 rails-bbc08c759c13d654621c1eb0659f3bdd6a66dfd5.zip |
Merge pull request #6956 from lexmag/ref_migration_generator
Add references statements to migration generator
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 11 | ||||
-rw-r--r-- | railties/test/generators/migration_generator_test.rb | 29 |
2 files changed, 40 insertions, 0 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 7223270210..5165d9401f 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,16 @@ ## Rails 4.0.0 (unreleased) ## +* The migration generator will now produce AddXXXToYYY/RemoveXXXFromYYY migrations 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 + + *Aleksey Magusev* + * Allow scaffold/model/migration generators to accept a `polymorphic` modifier for `references`/`belongs_to`, for instance 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"] |