diff options
author | Stefan Kanev <stefan.kanev@gmail.com> | 2014-07-18 19:46:53 +0300 |
---|---|---|
committer | Stefan Kanev <stefan.kanev@gmail.com> | 2014-07-18 19:46:53 +0300 |
commit | a013b082aa4459762b55bbc6c59a4f072eef8224 (patch) | |
tree | 4161fe1a062ea26ed7d3feed70c020834f229e5b /activerecord/test | |
parent | 843b8c0b8c8cccd8d1432060dfc79a8edcc4ed2c (diff) | |
download | rails-a013b082aa4459762b55bbc6c59a4f072eef8224.tar.gz rails-a013b082aa4459762b55bbc6c59a4f072eef8224.tar.bz2 rails-a013b082aa4459762b55bbc6c59a4f072eef8224.zip |
create_join_table uses same logic as HABTM reflections
Before this change, create_join_table would not remove the common prefix
in the join table name, unlike ActiveRecord::Reflections. A HABTM
between Music::Artist and Music::Record would use a table
music_artists_records, while create_join table would create
music_artists_music_records.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/migration/create_join_table_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/create_join_table_test.rb b/activerecord/test/cases/migration/create_join_table_test.rb index 62b60f7f7b..bea9d6b2c9 100644 --- a/activerecord/test/cases/migration/create_join_table_test.rb +++ b/activerecord/test/cases/migration/create_join_table_test.rb @@ -119,6 +119,30 @@ module ActiveRecord assert !connection.tables.include?('artists_musics') end + + def test_create_and_drop_join_table_with_common_prefix + with_table_cleanup do + connection.create_join_table 'audio_artists', 'audio_musics' + assert_includes connection.tables, 'audio_artists_musics' + + connection.drop_join_table 'audio_artists', 'audio_musics' + assert !connection.tables.include?('audio_artists_musics'), "Should have dropped join table, but didn't" + end + end + + private + + def with_table_cleanup + tables_before = connection.tables + + yield + ensure + tables_after = connection.tables - tables_before + + tables_after.each do |table| + connection.execute "DROP TABLE #{table}" + end + end end end end |