@@ -423,7 +423,7 @@ def test_sorting_by_relationship_field
423423 assert_cacheable_get :index , params : { sort : 'author.name' }
424424
425425 assert_response :success
426- assert json_response [ 'data' ] . length > 10 , 'there are enough recordsto show sort'
426+ assert json_response [ 'data' ] . length > 10 , 'there are enough records to show sort'
427427 assert_equal '17' , json_response [ 'data' ] [ 0 ] [ 'id' ] , 'nil is at the top'
428428 assert_equal post . id . to_s , json_response [ 'data' ] [ 1 ] [ 'id' ] , 'alphabetically first user is second'
429429 end
@@ -438,6 +438,16 @@ def test_desc_sorting_by_relationship_field
438438 assert_equal post . id . to_s , json_response [ 'data' ] [ -2 ] [ 'id' ] , 'alphabetically first user is second last'
439439 end
440440
441+ def test_sorting_by_relationship_field_include
442+ post = create_alphabetically_first_user_and_post
443+ assert_cacheable_get :index , params : { include : 'author' , sort : 'author.name' }
444+
445+ assert_response :success
446+ assert json_response [ 'data' ] . length > 10 , 'there are enough records to show sort'
447+ assert_equal '17' , json_response [ 'data' ] [ 0 ] [ 'id' ] , 'nil is at the top'
448+ assert_equal post . id . to_s , json_response [ 'data' ] [ 1 ] [ 'id' ] , 'alphabetically first user is second'
449+ end
450+
441451 def test_invalid_sort_param
442452 assert_cacheable_get :index , params : { sort : 'asdfg' }
443453
@@ -1921,6 +1931,15 @@ def test_tags_show_multiple_with_nonexistent_ids_at_the_beginning
19211931 assert_response :bad_request
19221932 assert_match /99,9,100 is not a valid value for id/ , response . body
19231933 end
1934+
1935+ def test_nested_includes_sort
1936+ assert_cacheable_get :index , params : { filter : { id : '6,7,8,9' } ,
1937+ include : 'posts.tags,posts.author.posts' ,
1938+ sort : 'name' }
1939+ assert_response :success
1940+ assert_equal 4 , json_response [ 'data' ] . size
1941+ assert_equal 3 , json_response [ 'included' ] . size
1942+ end
19241943end
19251944
19261945class PicturesControllerTest < ActionController ::TestCase
0 commit comments