Skip to content
Permalink
Browse files

Allow `column_exists?` giving options without type

  • Loading branch information...
kamipo committed Jan 26, 2019
1 parent 662ea46 commit 17901d876460f013c22dd155a148bbf7671433e2
@@ -130,7 +130,7 @@ def columns(table_name)
# column_exists?(:suppliers, :name, :string, null: false)
# column_exists?(:suppliers, :tax, :decimal, precision: 8, scale: 2)
#
def column_exists?(table_name, column_name, type = nil, options = {})
def column_exists?(table_name, column_name, type = nil, **options)
column_name = column_name.to_s
checks = []
checks << lambda { |c| c.name == column_name }
@@ -116,8 +116,8 @@ def test_timestamps_without_null_set_null_to_false_on_create_table
end
end

assert_not @connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
assert_not @connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
assert @connection.column_exists?(:has_timestamps, :created_at, null: false)
assert @connection.column_exists?(:has_timestamps, :updated_at, null: false)
end

def test_timestamps_without_null_set_null_to_false_on_change_table
@@ -129,8 +129,8 @@ def test_timestamps_without_null_set_null_to_false_on_change_table
end
end

assert_not @connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
assert_not @connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
assert @connection.column_exists?(:has_timestamps, :created_at, null: false)
assert @connection.column_exists?(:has_timestamps, :updated_at, null: false)
end

def test_timestamps_without_null_set_null_to_false_on_add_timestamps
@@ -139,7 +139,7 @@ def test_timestamps_without_null_set_null_to_false_on_add_timestamps
add_timestamps :has_timestamps, default: Time.now
end

assert_not @connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
assert_not @connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
assert @connection.column_exists?(:has_timestamps, :created_at, null: false)
assert @connection.column_exists?(:has_timestamps, :updated_at, null: false)
end
end
@@ -86,8 +86,8 @@ def migrate(x)

ActiveRecord::Migrator.new(:up, [migration]).migrate

assert connection.columns(:more_testings).find { |c| c.name == "created_at" }.null
assert connection.columns(:more_testings).find { |c| c.name == "updated_at" }.null
assert connection.column_exists?(:more_testings, :created_at, null: true)
assert connection.column_exists?(:more_testings, :updated_at, null: true)
ensure
connection.drop_table :more_testings rescue nil
end
@@ -103,8 +103,8 @@ def migrate(x)

ActiveRecord::Migrator.new(:up, [migration]).migrate

assert connection.columns(:testings).find { |c| c.name == "created_at" }.null
assert connection.columns(:testings).find { |c| c.name == "updated_at" }.null
assert connection.column_exists?(:testings, :created_at, null: true)
assert connection.column_exists?(:testings, :updated_at, null: true)
end

def test_timestamps_have_null_constraints_if_not_present_in_migration_for_adding_timestamps_to_existing_table
@@ -116,8 +116,8 @@ def migrate(x)

ActiveRecord::Migrator.new(:up, [migration]).migrate

assert connection.columns(:testings).find { |c| c.name == "created_at" }.null
assert connection.columns(:testings).find { |c| c.name == "updated_at" }.null
assert connection.column_exists?(:testings, :created_at, null: true)
assert connection.column_exists?(:testings, :updated_at, null: true)
end

def test_legacy_migrations_raises_exception_when_inherited

0 comments on commit 17901d8

Please sign in to comment.
You can’t perform that action at this time.