aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/migration_generator_test.rb
diff options
context:
space:
mode:
authorDerek Prior <derekprior@gmail.com>2014-11-24 21:25:15 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-25 20:22:58 -0200
commit323334a775bb35d901742e4cc39f6fe7b5e53c8f (patch)
treebe2b9444543f5b269b8515a6557e457742f99b73 /railties/test/generators/migration_generator_test.rb
parentac0432cf351d11f9cfaf2eb879388eb8bcf09cd7 (diff)
downloadrails-323334a775bb35d901742e4cc39f6fe7b5e53c8f.tar.gz
rails-323334a775bb35d901742e4cc39f6fe7b5e53c8f.tar.bz2
rails-323334a775bb35d901742e4cc39f6fe7b5e53c8f.zip
Generators add foreign keys on references
If you run a generator such as: ``` rails generate model accounts supplier:references ``` The resulting migration will now add the corresponding foreign key constraint unless the reference was specified to be polymorphic.
Diffstat (limited to 'railties/test/generators/migration_generator_test.rb')
-rw-r--r--railties/test/generators/migration_generator_test.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb
index 72f5fe29ca..c2c8e2abad 100644
--- a/railties/test/generators/migration_generator_test.rb
+++ b/railties/test/generators/migration_generator_test.rb
@@ -85,6 +85,18 @@ class MigrationGeneratorTest < Rails::Generators::TestCase
end
end
+ def test_remove_migration_with_references_removes_foreign_keys
+ migration = "remove_references_from_books"
+ run_generator [migration, "author:belongs_to", "distributor:references{polymorphic}"]
+
+ assert_migration "db/migrate/#{migration}.rb" do |content|
+ assert_method :change, content do |change|
+ assert_match(/remove_foreign_key :books, :authors/, change)
+ assert_no_match(/remove_foreign_key :books, :distributors/, change)
+ 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"]
@@ -171,6 +183,18 @@ class MigrationGeneratorTest < Rails::Generators::TestCase
end
end
+ def test_add_migration_with_references_adds_foreign_keys
+ 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 |change|
+ assert_match(/add_foreign_key :books, :authors/, change)
+ assert_no_match(/add_foreign_key :books, :distributors/, change)
+ end
+ end
+ end
+
def test_create_join_table_migration
migration = "add_media_join_table"
run_generator [migration, "artist_id", "musics:uniq"]
@@ -205,7 +229,7 @@ class MigrationGeneratorTest < Rails::Generators::TestCase
end
end
end
-
+
def test_properly_identifies_usage_file
assert generator_class.send(:usage_path)
end