21
21
require "models/ship"
22
22
require "models/admin"
23
23
require "models/admin/user"
24
+ require "models/cpk"
24
25
25
26
class PersistenceTest < ActiveRecord ::TestCase
26
27
fixtures :topics , :companies , :developers , :accounts , :minimalistics , :authors , :author_addresses ,
@@ -1448,25 +1449,14 @@ def test_query_constraints_list_is_nil_if_primary_key_is_nil
1448
1449
assert_nil klass . query_constraints_list
1449
1450
end
1450
1451
1451
- def test_query_constraints_uses_primary_key_by_default
1452
- post = posts ( :welcome )
1453
- assert_uses_query_constraints_on_reload ( post , "id" )
1452
+ def test_query_constraints_list_is_nil_for_non_cpk_model
1453
+ assert_nil Post . query_constraints_list
1454
+ assert_nil Dashboard . query_constraints_list
1454
1455
end
1455
1456
1456
- def test_query_constraints_uses_manually_configured_primary_key
1457
- dashboard = dashboards ( :cool_first )
1458
- assert_uses_query_constraints_on_reload ( dashboard , "dashboard_id" )
1459
- end
1460
-
1461
- def test_child_overriden_primary_key_is_used_as_query_constraint
1462
- topic = topics ( :first )
1463
- assert_uses_query_constraints_on_reload ( topic , "id" )
1464
-
1465
- title_pk_topic = topic . becomes ( TitlePrimaryKeyTopic )
1466
- title_pk_topic . author_name = "Nikita"
1467
-
1468
- sql = capture_sql { title_pk_topic . save } . first
1469
- assert_match ( /WHERE .*title/ , sql )
1457
+ def test_query_constraints_list_equals_to_composite_primary_key
1458
+ assert_equal ( [ "shop_id" , "id" ] , Cpk ::Order . query_constraints_list )
1459
+ assert_equal ( [ "author_id" , "number" ] , Cpk ::Book . query_constraints_list )
1470
1460
end
1471
1461
1472
1462
def test_child_keeps_parents_query_constraints
@@ -1477,6 +1467,10 @@ def test_child_keeps_parents_query_constraints
1477
1467
assert_uses_query_constraints_on_reload ( used_clothing_item , [ "clothing_type" , "color" ] )
1478
1468
end
1479
1469
1470
+ def test_child_keeps_parents_query_contraints_derived_from_composite_pk
1471
+ assert_equal ( [ "author_id" , "number" ] , Cpk ::BestSeller . query_constraints_list )
1472
+ end
1473
+
1480
1474
def assert_uses_query_constraints_on_reload ( object , columns )
1481
1475
flunk ( "columns argument must not be empty" ) if columns . blank?
1482
1476
0 commit comments