Skip to content

Commit

Permalink
Allow column_exists? giving options without type
Browse files Browse the repository at this point in the history
  • Loading branch information
kamipo committed Jan 26, 2019
1 parent 662ea46 commit 17901d8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Expand Up @@ -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 }
Expand Down
12 changes: 6 additions & 6 deletions activerecord/test/cases/ar_schema_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
12 changes: 6 additions & 6 deletions activerecord/test/cases/migration/compatibility_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 17901d8

Please sign in to comment.