Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6914 from lexmag/migration_tests

Refactor migration test_helper
  • Loading branch information...
commit 36938b410e7c7396ee5934246fddc048b898f7ef 2 parents 2ee3fa1 + 0fb1327
@rafaelfranca rafaelfranca authored
View
21 activerecord/test/cases/migration/create_join_table_test.rb
@@ -10,60 +10,53 @@ def setup
@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
View
27 activerecord/test/cases/migration/helper.rb
@@ -14,8 +14,10 @@ def puts(text="")
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 @@ def teardown
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
Please sign in to comment.
Something went wrong with that request. Please try again.