@@ -1449,6 +1449,13 @@ def test_schema_dump_includes_decimal_options_coerced
1449
1449
output = dump_all_table_schema ( [ /^[^n]/ ] )
1450
1450
assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: 2\. 78} , output
1451
1451
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
1452
1459
end
1453
1460
1454
1461
class SchemaDumperDefaultsTest < ActiveRecord ::TestCase
@@ -2150,7 +2157,7 @@ def test_in_order_of_with_enums_keys_coerced
2150
2157
coerce_tests! :test_in_order_of_with_nil
2151
2158
def test_in_order_of_with_nil_coerced
2152
2159
Book . connection . remove_index ( :books , column : [ :author_id , :name ] )
2153
-
2160
+
2154
2161
original_test_in_order_of_with_nil
2155
2162
ensure
2156
2163
Book . where ( author_id : nil , name : nil ) . delete_all
@@ -2294,3 +2301,51 @@ class ActiveRecord::Encryption::EncryptableRecordTest < ActiveRecord::Encryption
2294
2301
assert_not author . valid?
2295
2302
end
2296
2303
end
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