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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/jsonapi/cached_response_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def initialize(resource_klass, id, type, context, fetchable_fields, relationship
@fetchable_fields = Set.new(fetchable_fields)

# Relationships left uncompiled because we'll often want to insert included ids on retrieval
@relationships = relationships

# Remove the data since that should not be cached
@relationships = relationships&.transform_values {|v| v.delete_if {|k, _v| k == 'data'} }
@links_json = CompiledJson.of(links_json)
@attributes_json = CompiledJson.of(attributes_json)
@meta_json = CompiledJson.of(meta_json)
Expand Down
16 changes: 16 additions & 0 deletions test/controllers/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,22 @@ def test_index_filter_not_allowed
JSONAPI.configuration.allow_filter = true
end

def test_cached_result_does_not_include_relationship_data
JSONAPI.configuration.resource_cache = ActiveSupport::Cache::MemoryStore.new
JSONAPI.configuration.default_caching = true

get :show, params: {id: '1', include: 'author'}
assert_response :success
assert json_response['data']['relationships']['author']['data']

get :show, params: {id: '1'}
assert_response :success
refute json_response['data']['relationships']['author']['data']
ensure
JSONAPI.configuration.resource_cache = nil
JSONAPI.configuration.default_caching = false
end

def test_index_include_one_level_query_count
assert_query_count(4) do
assert_cacheable_get :index, params: {include: 'author'}
Expand Down