@@ -1449,6 +1449,13 @@ def test_schema_dump_includes_decimal_options_coerced
14491449 output = dump_all_table_schema ( [ /^[^n]/ ] )
14501450 assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: 2\. 78} , output
14511451 end
1452+
1453+ # SQL Server formats the check constraint expression differently.
1454+ coerce_tests! :test_schema_dumps_check_constraints
1455+ def test_schema_dumps_check_constraints_coerced
1456+ constraint_definition = dump_table_schema ( "products" ) . split ( /\n / ) . grep ( /t.check_constraint.*products_price_check/ ) . first . strip
1457+ assert_equal 't.check_constraint "[price]>[discounted_price]", name: "products_price_check"' , constraint_definition
1458+ end
14521459end
14531460
14541461class SchemaDumperDefaultsTest < ActiveRecord ::TestCase
@@ -2150,7 +2157,7 @@ def test_in_order_of_with_enums_keys_coerced
21502157 coerce_tests! :test_in_order_of_with_nil
21512158 def test_in_order_of_with_nil_coerced
21522159 Book . connection . remove_index ( :books , column : [ :author_id , :name ] )
2153-
2160+
21542161 original_test_in_order_of_with_nil
21552162 ensure
21562163 Book . where ( author_id : nil , name : nil ) . delete_all
@@ -2294,3 +2301,51 @@ class ActiveRecord::Encryption::EncryptableRecordTest < ActiveRecord::Encryption
22942301 assert_not author . valid?
22952302 end
22962303end
2304+
2305+ module ActiveRecord
2306+ class Migration
2307+ class CheckConstraintTest < ActiveRecord ::TestCase
2308+ # SQL Server formats the check constraint expression differently.
2309+ coerce_tests! :test_check_constraints
2310+ def test_check_constraints_coerced
2311+ check_constraints = @connection . check_constraints ( "products" )
2312+ assert_equal 1 , check_constraints . size
2313+
2314+ constraint = check_constraints . first
2315+ assert_equal "products" , constraint . table_name
2316+ assert_equal "products_price_check" , constraint . name
2317+ assert_equal "[price]>[discounted_price]" , constraint . expression
2318+ end
2319+
2320+ # SQL Server formats the check constraint expression differently.
2321+ coerce_tests! :test_add_check_constraint
2322+ def test_add_check_constraint_coerced
2323+ @connection . add_check_constraint :trades , "quantity > 0"
2324+
2325+ check_constraints = @connection . check_constraints ( "trades" )
2326+ assert_equal 1 , check_constraints . size
2327+
2328+ constraint = check_constraints . first
2329+ assert_equal "trades" , constraint . table_name
2330+ assert_equal "chk_rails_2189e9f96c" , constraint . name
2331+ assert_equal "[quantity]>(0)" , constraint . expression
2332+ end
2333+
2334+ # SQL Server formats the check constraint expression differently.
2335+ coerce_tests! :test_remove_check_constraint
2336+ def test_remove_check_constraint_coerced
2337+ @connection . add_check_constraint :trades , "price > 0" , name : "price_check"
2338+ @connection . add_check_constraint :trades , "quantity > 0" , name : "quantity_check"
2339+
2340+ assert_equal 2 , @connection . check_constraints ( "trades" ) . size
2341+ @connection . remove_check_constraint :trades , name : "quantity_check"
2342+ assert_equal 1 , @connection . check_constraints ( "trades" ) . size
2343+
2344+ constraint = @connection . check_constraints ( "trades" ) . first
2345+ assert_equal "trades" , constraint . table_name
2346+ assert_equal "price_check" , constraint . name
2347+ assert_equal "[price]>(0)" , constraint . expression
2348+ end
2349+ end
2350+ end
2351+ end
0 commit comments