Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jsonapi/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def show_related_resources
(paginator && paginator.class.requires_record_count) ||
(JSONAPI.configuration.top_level_meta_include_page_count))
related_resource_records = source_resource.public_send("records_for_" + relationship_type)
records = resource_klass.filter_records(verified_filters, {},
records = resource_klass.filter_records(verified_filters, rel_opts,
related_resource_records)

record_count = resource_klass.count_records(records)
Expand Down
39 changes: 39 additions & 0 deletions test/controllers/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2754,6 +2754,45 @@ def test_get_related_resources_with_filters
end
end

class Api::V2::BooksControllerTest < ActionController::TestCase
def test_get_related_resources_with_filters
$test_user = Person.find(5)
original_config = JSONAPI.configuration.dup
JSONAPI.configuration.top_level_meta_include_record_count = true
JSONAPI.configuration.json_key_format = :dasherized_key
assert_cacheable_get :get_related_resources,
params: {
author_id: '1',
relationship: 'books',
source: 'api/v2/authors',
filter: { fiction: 'true' }
}
assert_response :success
assert_equal 1, json_response['meta']['record-count']
ensure
JSONAPI.configuration = original_config
end

def test_get_related_resources_with_filters_2
# Admin user can find an author's banned books
$test_user = Person.find(5)
original_config = JSONAPI.configuration.dup
JSONAPI.configuration.top_level_meta_include_record_count = true
JSONAPI.configuration.json_key_format = :dasherized_key
assert_cacheable_get :get_related_resources,
params: {
author_id: '1',
relationship: 'books',
source: 'api/v2/authors',
filter: { banned: 'true' }
}
assert_response :success
assert_equal 1, json_response['meta']['record-count']
ensure
JSONAPI.configuration = original_config
end
end

class BreedsControllerTest < ActionController::TestCase
# Note: Breed names go through the TitleValueFormatter

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,8 @@ def apply_filter_banned(records, value, options)
# Only book admins might filter for banned books
if current_user && current_user.book_admin
records.where('books.banned = ?', value[0] == 'true')
else
records
end
end

Expand Down