From 4e390720178889c773adb12ea1f073bc035fbe67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81omnicki?= Date: Tue, 1 Feb 2011 23:27:26 +0100 Subject: Configurable generation of add_index for references columns Signed-off-by: Santiago Pastorino --- railties/test/generators/model_generator_test.rb | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'railties/test/generators') diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index b86859666e..6b2fd8b9ee 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -203,4 +203,45 @@ class ModelGeneratorTest < Rails::Generators::TestCase content = capture(:stderr){ run_generator ["object"] } assert_match /The name 'Object' is either already used in your application or reserved/, content end + + def test_index_is_added_for_belongs_to_association + run_generator ["account", "supplier:belongs_to"] + + assert_migration "db/migrate/create_accounts.rb" do |m| + assert_method :change, m do |up| + assert_match /add_index/, up + end + end + end + + def test_index_is_added_for_references_association + run_generator ["account", "supplier:references"] + + assert_migration "db/migrate/create_accounts.rb" do |m| + assert_method :change, m do |up| + assert_match /add_index/, up + end + end + end + + def test_index_is_skipped_for_belongs_to_association + run_generator ["account", "supplier:belongs_to", "--no-indexes"] + + assert_migration "db/migrate/create_accounts.rb" do |m| + assert_method :change, m do |up| + assert_no_match /add_index/, up + end + end + end + + def test_index_is_skipped_for_references_association + run_generator ["account", "supplier:references", "--no-indexes"] + + assert_migration "db/migrate/create_accounts.rb" do |m| + assert_method :change, m do |up| + assert_no_match /add_index/, up + end + end + end + end -- cgit v1.2.3