@@ -2577,6 +2577,50 @@ def test_index_with_caching_enabled_uses_context
25772577 end
25782578end
25792579
2580+ class Api ::V5 ::PaintersControllerTest < ActionController ::TestCase
2581+ def test_index_with_included_resources_with_filters
2582+ # There are two painters, but by filtering the included relationship, the
2583+ # painters are limited due to the join, thus only the painter with oil
2584+ # paintings is returned.
2585+ get :index , params : { include : 'paintings' , filter : { 'paintings.category' => 'oil' } }
2586+ assert_response :success
2587+ assert_equal 1 , json_response [ 'data' ] . size , 'Size of data is wrong'
2588+ assert_equal '1' , json_response [ 'data' ] [ 0 ] [ 'id' ]
2589+ assert_equal 2 , json_response [ 'included' ] . size , 'Size of included data is wrong'
2590+ assert_equal '4' , json_response [ 'included' ] [ 0 ] [ 'id' ]
2591+ assert_equal '5' , json_response [ 'included' ] [ 1 ] [ 'id' ]
2592+ end
2593+
2594+ def test_index_with_filters_and_included_resources_with_filters
2595+ get :index , params : { include : 'paintings' , filter : { 'name' => 'Wyspianski' , 'paintings.category' => 'oil' } }
2596+
2597+ assert_response :success
2598+ assert_equal 1 , json_response [ 'data' ] . size
2599+ assert_equal '1' , json_response [ 'data' ] [ 0 ] [ 'id' ]
2600+ assert_equal 2 , json_response [ 'included' ] . size
2601+ assert_equal '4' , json_response [ 'included' ] [ 0 ] [ 'id' ]
2602+ end
2603+
2604+ def test_index_with_filters_and_included_resources_with_multiple_filters
2605+ # Painting 5 is the genuine, but painting 6 is a fake. Verify that multiple nested filters are merged and only the oil painting is returned.
2606+ get :index , params : { include : 'paintings' , filter : { 'name' => 'Wyspianski' , 'paintings.category' => 'oil' , 'paintings.title' => 'Motherhood' } }
2607+
2608+ assert_response :success
2609+ assert_equal 1 , json_response [ 'data' ] . size
2610+ assert_equal '1' , json_response [ 'data' ] [ 0 ] [ 'id' ]
2611+ assert_equal 1 , json_response [ 'included' ] . size
2612+ assert_equal '5' , json_response [ 'included' ] [ 0 ] [ 'id' ]
2613+ end
2614+
2615+ def test_show_with_filters_and_included_resources_with_filters
2616+ get :show , params : { id : 1 , include : 'paintings' , filter : { 'paintings.category' => 'oil' } }
2617+ assert_response :success
2618+ assert_equal '1' , json_response [ 'data' ] [ 'id' ]
2619+ assert_equal 2 , json_response [ 'included' ] . size
2620+ assert_equal '4' , json_response [ 'included' ] [ 0 ] [ 'id' ]
2621+ end
2622+ end
2623+
25802624class Api ::V5 ::AuthorsControllerTest < ActionController ::TestCase
25812625 def test_get_person_as_author
25822626 assert_cacheable_get :index , params : { filter : { id : '1' } }
0 commit comments