File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 11source 'https://rubygems.org'
22
3+ # TODO(beauby): Remove before merging.
4+ gem 'jsonapi-renderer' , github : 'jsonapi-rb/jsonapi-renderer'
5+
36gemspec
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ def register_renderers
5454 ActiveSupport ::Notifications . instrument ( 'render.jsonapi-rails' ,
5555 resources : resources ,
5656 options : options ) do
57- renderer . render ( resources , options , self ) . to_json
57+ JSON . generate ( renderer . render ( resources , options , self ) )
5858 end
5959 end
6060 end
Original file line number Diff line number Diff line change @@ -17,4 +17,38 @@ def index
1717 expect ( subject . key? ( 'data' ) ) . to be true
1818 end
1919 end
20+
21+ context 'when using a cache' do
22+ controller do
23+ def serializer
24+ Class . new ( JSONAPI ::Serializable ::Resource ) do
25+ type 'users'
26+ attribute :name
27+
28+ def jsonapi_cache_key ( *)
29+ 'foo'
30+ end
31+ end
32+ end
33+
34+ def index
35+ user = OpenStruct . new ( id : 1 , name : 'Lucas' )
36+
37+ render jsonapi : user ,
38+ class : { OpenStruct : serializer } ,
39+ cache : Rails . cache
40+ end
41+ end
42+
43+ subject { JSON . parse ( response . body ) }
44+
45+ it 'renders a JSON API success document' do
46+ get :index
47+ expect ( Rails . cache . exist? ( 'foo' ) ) . to be true
48+ get :index
49+
50+ expect ( response . content_type ) . to eq ( 'application/vnd.api+json' )
51+ expect ( subject . key? ( 'data' ) ) . to be true
52+ end
53+ end
2054end
You can’t perform that action at this time.
0 commit comments