@@ -3638,3 +3638,69 @@ def test_caching_with_join_to_resource_with_sql_fragment
36383638 assert_response :success
36393639 end
36403640end
3641+
3642+ class Api ::BoxesControllerTest < ActionController ::TestCase
3643+ def test_complex_includes_base
3644+ assert_cacheable_get :index
3645+ assert_response :success
3646+ end
3647+
3648+ def test_complex_includes_two_level
3649+ assert_cacheable_get :index , params : { include : 'things,things.user' }
3650+
3651+ assert_response :success
3652+
3653+ # The test is hardcoded with the include order. This should be changed at some point since either thing could come first and still be valid
3654+ assert_equal '1' , json_response [ 'included' ] [ 0 ] [ 'id' ]
3655+ assert_equal 'things' , json_response [ 'included' ] [ 0 ] [ 'type' ]
3656+ assert_equal '1' , json_response [ 'included' ] [ 0 ] [ 'relationships' ] [ 'user' ] [ 'data' ] [ 'id' ]
3657+ assert_nil json_response [ 'included' ] [ 0 ] [ 'relationships' ] [ 'things' ] [ 'data' ]
3658+
3659+ assert_equal '2' , json_response [ 'included' ] [ 1 ] [ 'id' ]
3660+ assert_equal 'things' , json_response [ 'included' ] [ 1 ] [ 'type' ]
3661+ assert_equal '1' , json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'user' ] [ 'data' ] [ 'id' ]
3662+ assert_nil json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'things' ] [ 'data' ]
3663+
3664+ assert_equal '1' , json_response [ 'included' ] [ 2 ] [ 'id' ]
3665+ assert_equal 'users' , json_response [ 'included' ] [ 2 ] [ 'type' ]
3666+ assert_nil json_response [ 'included' ] [ 2 ] [ 'relationships' ] [ 'things' ] [ 'data' ]
3667+ end
3668+
3669+ def test_complex_includes_things_nested_things
3670+ assert_cacheable_get :index , params : { include : 'things,things.things' }
3671+
3672+ assert_response :success
3673+
3674+ # The test is hardcoded with the include order. This should be changed at some point since either thing could come first and still be valid
3675+ assert_equal '2' , json_response [ 'included' ] [ 0 ] [ 'id' ]
3676+ assert_equal 'things' , json_response [ 'included' ] [ 0 ] [ 'type' ]
3677+ assert_nil json_response [ 'included' ] [ 0 ] [ 'relationships' ] [ 'user' ] [ 'data' ]
3678+ assert_equal '1' , json_response [ 'included' ] [ 0 ] [ 'relationships' ] [ 'things' ] [ 'data' ] [ 0 ] [ 'id' ]
3679+
3680+ assert_equal '1' , json_response [ 'included' ] [ 1 ] [ 'id' ]
3681+ assert_equal 'things' , json_response [ 'included' ] [ 1 ] [ 'type' ]
3682+ assert_nil json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'user' ] [ 'data' ]
3683+ assert_equal '2' , json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'things' ] [ 'data' ] [ 0 ] [ 'id' ]
3684+ end
3685+
3686+ def test_complex_includes_nested_things_secondary_users
3687+ assert_cacheable_get :index , params : { include : 'things,things.user,things.things' }
3688+
3689+ assert_response :success
3690+
3691+ # The test is hardcoded with the include order. This should be changed at some point since either thing could come first and still be valid
3692+ assert_equal '1' , json_response [ 'included' ] [ 2 ] [ 'id' ]
3693+ assert_equal 'users' , json_response [ 'included' ] [ 2 ] [ 'type' ]
3694+ assert_nil json_response [ 'included' ] [ 2 ] [ 'relationships' ] [ 'things' ] [ 'data' ]
3695+
3696+ assert_equal '2' , json_response [ 'included' ] [ 0 ] [ 'id' ]
3697+ assert_equal 'things' , json_response [ 'included' ] [ 0 ] [ 'type' ]
3698+ assert_equal '1' , json_response [ 'included' ] [ 0 ] [ 'relationships' ] [ 'user' ] [ 'data' ] [ 'id' ]
3699+ assert_equal '1' , json_response [ 'included' ] [ 0 ] [ 'relationships' ] [ 'things' ] [ 'data' ] [ 0 ] [ 'id' ]
3700+
3701+ assert_equal '1' , json_response [ 'included' ] [ 1 ] [ 'id' ]
3702+ assert_equal 'things' , json_response [ 'included' ] [ 1 ] [ 'type' ]
3703+ assert_equal '1' , json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'user' ] [ 'data' ] [ 'id' ]
3704+ assert_equal '2' , json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'things' ] [ 'data' ] [ 0 ] [ 'id' ]
3705+ end
3706+ end
0 commit comments