@@ -36,6 +36,33 @@ def test_destroy
3636 assert_equal ( 1 , user . id )
3737 end
3838
39+ def test_destroy_custom_primary_key
40+ stub_request ( :get , "http://example.com/user_preferences/105" )
41+ . to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
42+ data : [
43+ { attributes : { user_id : 105 , name : "Jeff Ching" , email_address : "ching.jeff@gmail.com" } }
44+ ]
45+ } . to_json )
46+
47+ $print_load = true
48+ user_prefrence = UserPreference . find ( 105 ) . first
49+ assert ( user_prefrence . persisted? )
50+ $print_load = false
51+ assert_equal ( false , user_prefrence . new_record? )
52+ assert_equal ( false , user_prefrence . destroyed? )
53+
54+ stub_request ( :delete , "http://example.com/user_preferences/105" )
55+ . to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
56+ data : [ ]
57+ } . to_json )
58+
59+ assert ( user_prefrence . destroy , "successful deletion should return truish value" )
60+ assert_equal ( false , user_prefrence . persisted? )
61+ assert_equal ( false , user_prefrence . new_record? )
62+ assert ( user_prefrence . destroyed? )
63+ assert_equal ( 105 , user_prefrence . user_id )
64+ end
65+
3966 def test_destroy_no_content
4067 stub_request ( :delete , "http://example.com/users/6" )
4168 . to_return ( headers : { content_type : "application/vnd.api+json" } , body : nil )
0 commit comments