diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2012-07-18 00:16:39 -0700 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2012-07-18 00:16:39 -0700 |
commit | 58ccc9f6c5d261f7c1305d822b16447ac3d286b3 (patch) | |
tree | f47e5097d83b04464904fa56d0f65bc91b521fc8 /railties | |
parent | 17b6fa877752c217a9171b7f420bc86d55fddcbc (diff) | |
parent | 211d88b71b3df2ae161b23579a79f8e937132388 (diff) | |
download | rails-58ccc9f6c5d261f7c1305d822b16447ac3d286b3.tar.gz rails-58ccc9f6c5d261f7c1305d822b16447ac3d286b3.tar.bz2 rails-58ccc9f6c5d261f7c1305d822b16447ac3d286b3.zip |
Merge pull request #7028 from lexmag/join_table_indexes
Add indexes to create_join_table method
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators/generated_attribute.rb | 3 | ||||
-rw-r--r-- | railties/test/generators/migration_generator_test.rb | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index d480fc12b5..35cd40d25e 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -8,6 +8,7 @@ module Rails attr_accessor :name, :type attr_reader :attr_options + attr_writer :index_name class << self def parse(column_definition) @@ -94,7 +95,7 @@ module Rails end def index_name - if reference? + @index_name ||= if reference? polymorphic? ? %w(id type).map { |t| "#{name}_#{t}" } : "#{name}_id" else name diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 86e3793289..9f9cd9c9fc 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -167,6 +167,19 @@ class MigrationGeneratorTest < Rails::Generators::TestCase end end + def test_create_join_table_migration + migration = "add_media_join_table" + run_generator [migration, "artists", "musics:uniq"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :change, content do |up| + assert_match(/create_join_table :artists, :musics/, up) + assert_match(/# t.index \[:artist_id, :music_id\]/, up) + assert_match(/ t.index \[:music_id, :artist_id\], unique: 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"] |