From 371bd51b73480bb5a5d76ded56eead2f8275436f Mon Sep 17 00:00:00 2001 From: Vilius Luneckas Date: Fri, 22 Feb 2019 17:06:54 +0200 Subject: [PATCH] =?UTF-8?q?Unify=20Simple=20and=20Cached=20resource=20outp?= =?UTF-8?q?ut=20=E2=80=93=20both=20returns=20array=20of=20hash=20objects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/jsonapi/renderer/cached_resources_processor.rb | 10 +--------- spec/caching_spec.rb | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/jsonapi/renderer/cached_resources_processor.rb b/lib/jsonapi/renderer/cached_resources_processor.rb index de42cb9..2e77f7d 100644 --- a/lib/jsonapi/renderer/cached_resources_processor.rb +++ b/lib/jsonapi/renderer/cached_resources_processor.rb @@ -4,12 +4,6 @@ module JSONAPI class Renderer # @private class CachedResourcesProcessor < ResourcesProcessor - class JSONString < String - def to_json(*) - self - end - end - def initialize(cache) @cache = cache end @@ -19,9 +13,7 @@ def process_resources cache_hash = cache_key_map(resources) processed_resources = @cache.fetch_multi(*cache_hash.keys) do |key| res, include, fields = cache_hash[key] - json = res.as_jsonapi(include: include, fields: fields).to_json - - JSONString.new(json) + res.as_jsonapi(include: include, fields: fields) end resources.replace(processed_resources.values) diff --git a/spec/caching_spec.rb b/spec/caching_spec.rb index 35c605c..9de4c94 100644 --- a/spec/caching_spec.rb +++ b/spec/caching_spec.rb @@ -96,6 +96,6 @@ def fetch_multi(*keys) } expect(JSON.parse(actual.to_json)).to eq(JSON.parse(expected.to_json)) - expect(actual[:data]).to be_a(JSONAPI::Renderer::CachedResourcesProcessor::JSONString) + expect(actual[:data]).to be_a(Hash) end end