Skip to content

Commit

Permalink
move column ordering tests to it's own class
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 10, 2012
1 parent 42fd164 commit 4663070
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
12 changes: 2 additions & 10 deletions activerecord/lib/active_record/migration.rb
Expand Up @@ -610,18 +610,10 @@ def migrations_path
migrations_paths.first
end

def migrations(paths, *args)
if args.empty?
subdirectories = true
else
subdirectories = args.first
ActiveSupport::Deprecation.warn "The `subdirectories` argument to `migrations` is deprecated"
end

def migrations(paths)
paths = Array(paths)

glob = subdirectories ? "**/" : ""
files = Dir[*paths.map { |p| "#{p}/#{glob}[0-9]*_*.rb" }]
files = Dir[*paths.map { |p| "#{p}/**/[0-9]*_*.rb" }]

seen = Hash.new false

Expand Down
46 changes: 0 additions & 46 deletions activerecord/test/cases/migration/change_schema_test.rb
Expand Up @@ -244,38 +244,6 @@ def test_add_column_not_null_with_default
end
end

def test_column_positioning
testing_table_for_positioning do |conn|
assert_equal %w(first second third), conn.columns(:testings).map {|c| c.name }
end
end

def test_add_column_with_positioning
testing_table_for_positioning do |conn|
conn.add_column :testings, :new_col, :integer
assert_equal %w(first second third new_col), conn.columns(:testings).map {|c| c.name }
end
testing_table_for_positioning do |conn|
conn.add_column :testings, :new_col, :integer, :first => true
assert_equal %w(new_col first second third), conn.columns(:testings).map {|c| c.name }
end
testing_table_for_positioning do |conn|
conn.add_column :testings, :new_col, :integer, :after => :first
assert_equal %w(first new_col second third), conn.columns(:testings).map {|c| c.name }
end
end

def test_change_column_with_positioning
testing_table_for_positioning do |conn|
conn.change_column :testings, :second, :integer, :first => true
assert_equal %w(second first third), conn.columns(:testings).map {|c| c.name }
end
testing_table_for_positioning do |conn|
conn.change_column :testings, :second, :integer, :after => :third
assert_equal %w(first third second), conn.columns(:testings).map {|c| c.name }
end
end

def test_change_column_quotes_column_names
connection.create_table :testings do |t|
t.column :select, :string
Expand Down Expand Up @@ -395,20 +363,6 @@ def testing_table_with_only_foo_attribute

yield
end

def testing_table_for_positioning
unless current_adapter?(:MysqlAdapter, :Mysql2Adapter)
skip "not supported on #{connection.class}"
end

connection.create_table :testings, :id => false do |t|
t.column :first, :integer
t.column :second, :integer
t.column :third, :integer
end

yield connection
end
end
end
end
58 changes: 58 additions & 0 deletions activerecord/test/cases/migration/column_positioning_test.rb
@@ -0,0 +1,58 @@
module ActiveRecord
class Migration
class ColumnPositioningTest < ActiveRecord::TestCase
attr_reader :connection, :table_name
alias :conn :connection

def setup
super

unless current_adapter?(:MysqlAdapter, :Mysql2Adapter)
skip "not supported on #{connection.class}"
end

@connection = ActiveRecord::Base.connection

connection.create_table :testings, :id => false do |t|
t.column :first, :integer
t.column :second, :integer
t.column :third, :integer
end
end

def teardown
super
connection.drop_table :testings rescue nil
ActiveRecord::Base.primary_key_prefix_type = nil
end

def test_column_positioning
assert_equal %w(first second third), conn.columns(:testings).map {|c| c.name }
end

def test_add_column_with_positioning
conn.add_column :testings, :new_col, :integer
assert_equal %w(first second third new_col), conn.columns(:testings).map {|c| c.name }
end

def test_add_column_with_positioning_first
conn.add_column :testings, :new_col, :integer, :first => true
assert_equal %w(new_col first second third), conn.columns(:testings).map {|c| c.name }
end

def test_add_column_with_positioning_after
conn.add_column :testings, :new_col, :integer, :after => :first
assert_equal %w(first new_col second third), conn.columns(:testings).map {|c| c.name }
end

def test_change_column_with_positioning
conn.change_column :testings, :second, :integer, :first => true
assert_equal %w(second first third), conn.columns(:testings).map {|c| c.name }

conn.change_column :testings, :second, :integer, :after => :third
assert_equal %w(first third second), conn.columns(:testings).map {|c| c.name }
end

end
end
end

0 comments on commit 4663070

Please sign in to comment.