From 321eeec8adbd7a5de3f055866b08380ad573b06f Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Fri, 7 Jan 2022 16:08:45 +0000 Subject: [PATCH] Fix passing options to check_constraint from change_table This was causing warnings on ruby 2.7 and failing outright from 3.0, due to the change in keyword argument handling --- .../abstract/schema_definitions.rb | 8 ++++---- .../cases/migration/check_constraint_test.rb | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 6122a2bd12..6357322625 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -838,8 +838,8 @@ module ActiveRecord # t.check_constraint("price > 0", name: "price_check") # # See {connection.add_check_constraint}[rdoc-ref:SchemaStatements#add_check_constraint] - def check_constraint(*args) - @base.add_check_constraint(name, *args) + def check_constraint(*args, **options) + @base.add_check_constraint(name, *args, **options) end # Removes the given check constraint from the table. @@ -847,8 +847,8 @@ module ActiveRecord # t.remove_check_constraint(name: "price_check") # # See {connection.remove_check_constraint}[rdoc-ref:SchemaStatements#remove_check_constraint] - def remove_check_constraint(*args) - @base.remove_check_constraint(name, *args) + def remove_check_constraint(*args, **options) + @base.remove_check_constraint(name, *args, **options) end private diff --git a/activerecord/test/cases/migration/check_constraint_test.rb b/activerecord/test/cases/migration/check_constraint_test.rb index 670cf9e276..a7d119ea72 100644 --- a/activerecord/test/cases/migration/check_constraint_test.rb +++ b/activerecord/test/cases/migration/check_constraint_test.rb @@ -170,6 +170,26 @@ if ActiveRecord::Base.connection.supports_check_constraints? @connection.remove_check_constraint :trades, name: "nonexistent" end end + + def test_add_constraint_from_change_table_with_options + @connection.change_table :trades do |t| + t.check_constraint "price > 0", name: "price_check" + end + + constraint = @connection.check_constraints("trades").first + assert_equal "trades", constraint.table_name + assert_equal "price_check", constraint.name + end + + def test_remove_constraint_from_change_table_with_options + @connection.add_check_constraint :trades, "price > 0", name: "price_check" + + @connection.change_table :trades do |t| + t.remove_check_constraint "price > 0", name: "price_check" + end + + assert_equal 0, @connection.check_constraints("trades").size + end end end end