diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/guides/source/getting_started.textile | 4 | ||||
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 902b7353c0..e371632d87 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -811,6 +811,8 @@ class CreateComments < ActiveRecord::Migration t.timestamps end + + add_index :comments, :post_id end def self.down @@ -819,7 +821,7 @@ class CreateComments < ActiveRecord::Migration end </ruby> -The +t.references+ line sets up a foreign key column for the association between the two models. Go ahead and run the migration: +The +t.references+ line sets up a foreign key column for the association between the two models. And the +add_index+ line sets up an index for this association column. Go ahead and run the migration: <shell> $ rake db:migrate diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index f366600b16..df787f61ba 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -3,7 +3,7 @@ require 'rails/generators/rails/scaffold/scaffold_generator' class ScaffoldGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper - arguments %w(product_line title:string price:integer) + arguments %w(product_line title:string product:belongs_to user:references) setup :copy_routes @@ -14,7 +14,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "app/models/product_line.rb", /class ProductLine < ActiveRecord::Base/ assert_file "test/unit/product_line_test.rb", /class ProductLineTest < ActiveSupport::TestCase/ assert_file "test/fixtures/product_lines.yml" - assert_migration "db/migrate/create_product_lines.rb" + assert_migration "db/migrate/create_product_lines.rb", /belongs_to :product/ + assert_migration "db/migrate/create_product_lines.rb", /add_index :product_lines, :product_id/ + assert_migration "db/migrate/create_product_lines.rb", /references :user/ + assert_migration "db/migrate/create_product_lines.rb", /add_index :product_lines, :user_id/ # Route assert_file "config/routes.rb" do |route| |