Skip to content

Commit ace72f8

Browse files
hatch-carllgebhardt
authored andcommitted
Include directives may be nil if no includes are directed
closes gh-1235
1 parent ee7aac5 commit ace72f8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/jsonapi/request_parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def parse_filters(filters)
265265
return @errors.concat(Exceptions::FilterNotAllowed.new(filter_method).errors)
266266
end
267267

268-
unless @include_directives.include_config(relationship.name.to_sym).present?
268+
unless @include_directives&.include_config(relationship.name.to_sym).present?
269269
return @errors.concat(Exceptions::FilterNotAllowed.new(filter_method).errors)
270270
end
271271

test/controllers/controller_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,6 +2635,13 @@ def test_show_with_filters_and_included_resources_with_filters
26352635
assert_equal 2, json_response['included'].size
26362636
assert_equal '4', json_response['included'][0]['id']
26372637
end
2638+
2639+
def test_show_with_filters_and_no_included_resources
2640+
get :show, params: { id: 1, filter: { 'paintings.category' => 'oil' } }
2641+
assert_response :bad_request
2642+
assert_equal('Filter not allowed', json_response['errors'][0]['title'])
2643+
assert_equal('category is not allowed.', json_response['errors'][0]['detail'])
2644+
end
26382645
end
26392646

26402647
class Api::V5::AuthorsControllerTest < ActionController::TestCase

0 commit comments

Comments
 (0)