Skip to content

Commit de7711d

Browse files
authored
Merge pull request #943 from cerebris/test_recursive_include
Add a test for recursive includes.
2 parents c657fcb + 57032fa commit de7711d

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

test/controllers/controller_test.rb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3606,6 +3606,23 @@ def test_caching_with_join_to_resource_with_sql_fragment
36063606
end
36073607
end
36083608

3609+
class AuthorsControllerTest < ActionController::TestCase
3610+
def test_show_author_recursive
3611+
get :show, params: {id: '2', include: 'books.authors'}
3612+
assert_response :success
3613+
assert_equal '2', json_response['data']['id']
3614+
assert_equal 'authors', json_response['data']['type']
3615+
assert_equal 'Fred Reader', json_response['data']['attributes']['name']
3616+
3617+
# The test is hardcoded with the include order. This should be changed at some
3618+
# point since either thing could come first and still be valid
3619+
assert_equal '1', json_response['included'][0]['id']
3620+
assert_equal 'authors', json_response['included'][0]['type']
3621+
assert_equal '2', json_response['included'][1]['id']
3622+
assert_equal 'books', json_response['included'][1]['type']
3623+
end
3624+
end
3625+
36093626
class Api::BoxesControllerTest < ActionController::TestCase
36103627
def test_complex_includes_base
36113628
assert_cacheable_get :index
@@ -3617,7 +3634,8 @@ def test_complex_includes_two_level
36173634

36183635
assert_response :success
36193636

3620-
# 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+
# The test is hardcoded with the include order. This should be changed at some
3638+
# point since either thing could come first and still be valid
36213639
assert_equal '1', json_response['included'][0]['id']
36223640
assert_equal 'things', json_response['included'][0]['type']
36233641
assert_equal '1', json_response['included'][0]['relationships']['user']['data']['id']
@@ -3638,7 +3656,8 @@ def test_complex_includes_things_nested_things
36383656

36393657
assert_response :success
36403658

3641-
# 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
3659+
# The test is hardcoded with the include order. This should be changed at some
3660+
# point since either thing could come first and still be valid
36423661
assert_equal '2', json_response['included'][0]['id']
36433662
assert_equal 'things', json_response['included'][0]['type']
36443663
assert_nil json_response['included'][0]['relationships']['user']['data']
@@ -3655,7 +3674,8 @@ def test_complex_includes_nested_things_secondary_users
36553674

36563675
assert_response :success
36573676

3658-
# 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
3677+
# The test is hardcoded with the include order. This should be changed at some
3678+
# point since either thing could come first and still be valid
36593679
assert_equal '1', json_response['included'][2]['id']
36603680
assert_equal 'users', json_response['included'][2]['type']
36613681
assert_nil json_response['included'][2]['relationships']['things']['data']

0 commit comments

Comments
 (0)