@@ -3599,3 +3599,70 @@ def test_whitelisted_error_in_controller
35993599 $PostProcessorRaisesErrors = false
36003600 end
36013601end
3602+
3603+
3604+ class Api ::BoxesControllerTest < ActionController ::TestCase
3605+ def test_complex_includes_base
3606+ get :index
3607+ assert_response :success
3608+ end
3609+
3610+ def test_complex_includes_two_level
3611+ get :index , params : { include : 'things,things.user' }
3612+
3613+ assert_response :success
3614+
3615+ assert_equal '1' , json_response [ 'included' ] [ 0 ] [ 'id' ]
3616+ assert_equal 'users' , json_response [ 'included' ] [ 0 ] [ 'type' ]
3617+ assert_nil json_response [ 'included' ] [ 0 ] [ 'relationships' ] [ 'things' ] [ 'data' ]
3618+
3619+ # 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
3620+ assert_equal '1' , json_response [ 'included' ] [ 1 ] [ 'id' ]
3621+ assert_equal 'things' , json_response [ 'included' ] [ 1 ] [ 'type' ]
3622+ assert_equal '1' , json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'user' ] [ 'data' ] [ 'id' ]
3623+ assert_nil json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'things' ] [ 'data' ]
3624+
3625+ assert_equal '2' , json_response [ 'included' ] [ 2 ] [ 'id' ]
3626+ assert_equal 'things' , json_response [ 'included' ] [ 2 ] [ 'type' ]
3627+ assert_equal '1' , json_response [ 'included' ] [ 2 ] [ 'relationships' ] [ 'user' ] [ 'data' ] [ 'id' ]
3628+ assert_nil json_response [ 'included' ] [ 2 ] [ 'relationships' ] [ 'things' ] [ 'data' ]
3629+ end
3630+
3631+ def test_complex_includes_things_nested_things
3632+ get :index , params : { include : 'things,things.things' }
3633+
3634+ assert_response :success
3635+
3636+ # 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
3637+ assert_equal '2' , json_response [ 'included' ] [ 0 ] [ 'id' ]
3638+ assert_equal 'things' , json_response [ 'included' ] [ 0 ] [ 'type' ]
3639+ assert_nil json_response [ 'included' ] [ 0 ] [ 'relationships' ] [ 'user' ] [ 'data' ]
3640+ assert_equal '1' , json_response [ 'included' ] [ 0 ] [ 'relationships' ] [ 'things' ] [ 'data' ] [ 0 ] [ 'id' ]
3641+
3642+ assert_equal '1' , json_response [ 'included' ] [ 1 ] [ 'id' ]
3643+ assert_equal 'things' , json_response [ 'included' ] [ 1 ] [ 'type' ]
3644+ assert_nil json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'user' ] [ 'data' ]
3645+ assert_equal '2' , json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'things' ] [ 'data' ] [ 0 ] [ 'id' ]
3646+ end
3647+
3648+ def test_complex_includes_nested_things_secondary_users
3649+ get :index , params : { include : 'things,things.user,things.things' }
3650+
3651+ assert_response :success
3652+
3653+ assert_equal '1' , json_response [ 'included' ] [ 0 ] [ 'id' ]
3654+ assert_equal 'users' , json_response [ 'included' ] [ 0 ] [ 'type' ]
3655+ assert_nil json_response [ 'included' ] [ 0 ] [ 'relationships' ] [ 'things' ] [ 'data' ]
3656+
3657+ # 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
3658+ assert_equal '2' , json_response [ 'included' ] [ 1 ] [ 'id' ]
3659+ assert_equal 'things' , json_response [ 'included' ] [ 1 ] [ 'type' ]
3660+ assert_equal '1' , json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'user' ] [ 'data' ] [ 'id' ]
3661+ assert_equal '1' , json_response [ 'included' ] [ 1 ] [ 'relationships' ] [ 'things' ] [ 'data' ] [ 0 ] [ 'id' ]
3662+
3663+ assert_equal '1' , json_response [ 'included' ] [ 2 ] [ 'id' ]
3664+ assert_equal 'things' , json_response [ 'included' ] [ 2 ] [ 'type' ]
3665+ assert_equal '1' , json_response [ 'included' ] [ 2 ] [ 'relationships' ] [ 'user' ] [ 'data' ] [ 'id' ]
3666+ assert_equal '2' , json_response [ 'included' ] [ 2 ] [ 'relationships' ] [ 'things' ] [ 'data' ] [ 0 ] [ 'id' ]
3667+ end
3668+ end
0 commit comments