diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-01 08:56:51 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-01 08:56:51 -0700 |
commit | 36938b410e7c7396ee5934246fddc048b898f7ef (patch) | |
tree | 7b1a2d0113f860afcf6f593684fd8634b7ede8df /activerecord | |
parent | 2ee3fa1a48513a2c42833e2e1f60fe03769bc295 (diff) | |
parent | 0fb13277aa1dff987e2cb644354fc81b94afb8a1 (diff) | |
download | rails-36938b410e7c7396ee5934246fddc048b898f7ef.tar.gz rails-36938b410e7c7396ee5934246fddc048b898f7ef.tar.bz2 rails-36938b410e7c7396ee5934246fddc048b898f7ef.zip |
Merge pull request #6914 from lexmag/migration_tests
Refactor migration test_helper
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/migration/create_join_table_test.rb | 21 | ||||
-rw-r--r-- | activerecord/test/cases/migration/helper.rb | 27 |
2 files changed, 11 insertions, 37 deletions
diff --git a/activerecord/test/cases/migration/create_join_table_test.rb b/activerecord/test/cases/migration/create_join_table_test.rb index 0428d9ba76..04a5e06992 100644 --- a/activerecord/test/cases/migration/create_join_table_test.rb +++ b/activerecord/test/cases/migration/create_join_table_test.rb @@ -10,60 +10,53 @@ module ActiveRecord @connection = ActiveRecord::Base.connection end + def teardown + super + [:artists_musics, :musics_videos, :catalog].each do |table_name| + connection.drop_table table_name if connection.tables.include?(table_name) + end + end + def test_create_join_table connection.create_join_table :artists, :musics assert_equal %w(artist_id music_id), connection.columns(:artists_musics).map(&:name).sort - ensure - connection.drop_table :artists_musics end def test_create_join_table_set_not_null_by_default connection.create_join_table :artists, :musics assert_equal [false, false], connection.columns(:artists_musics).map(&:null) - ensure - connection.drop_table :artists_musics end def test_create_join_table_with_strings connection.create_join_table 'artists', 'musics' assert_equal %w(artist_id music_id), connection.columns(:artists_musics).map(&:name).sort - ensure - connection.drop_table :artists_musics end def test_create_join_table_with_the_proper_order connection.create_join_table :videos, :musics assert_equal %w(music_id video_id), connection.columns(:musics_videos).map(&:name).sort - ensure - connection.drop_table :musics_videos end def test_create_join_table_with_the_table_name connection.create_join_table :artists, :musics, :table_name => :catalog assert_equal %w(artist_id music_id), connection.columns(:catalog).map(&:name).sort - ensure - connection.drop_table :catalog end def test_create_join_table_with_the_table_name_as_string connection.create_join_table :artists, :musics, :table_name => 'catalog' assert_equal %w(artist_id music_id), connection.columns(:catalog).map(&:name).sort - ensure - connection.drop_table :catalog end def test_create_join_table_with_column_options connection.create_join_table :artists, :musics, :column_options => {:null => true} assert_equal [true, true], connection.columns(:artists_musics).map(&:null) - ensure - connection.drop_table :artists_musics end end end diff --git a/activerecord/test/cases/migration/helper.rb b/activerecord/test/cases/migration/helper.rb index fe53510ba2..20f26786f0 100644 --- a/activerecord/test/cases/migration/helper.rb +++ b/activerecord/test/cases/migration/helper.rb @@ -14,8 +14,10 @@ module ActiveRecord module TestHelper attr_reader :connection, :table_name + CONNECTION_METHODS = %w[add_column remove_column rename_column add_index change_column rename_table] + class TestModel < ActiveRecord::Base - self.table_name = 'test_models' + self.table_name = :test_models end def setup @@ -36,29 +38,8 @@ module ActiveRecord end private - def add_column(*args) - connection.add_column(*args) - end - - def remove_column(*args) - connection.remove_column(*args) - end - - def rename_column(*args) - connection.rename_column(*args) - end - def add_index(*args) - connection.add_index(*args) - end - - def change_column(*args) - connection.change_column(*args) - end - - def rename_table(*args) - connection.rename_table(*args) - end + delegate(*CONNECTION_METHODS, to: :connection) end end end |