File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ def register_renderers
57
57
ActiveSupport ::Notifications . instrument ( 'render.jsonapi-rails' ,
58
58
resources : resources ,
59
59
options : options ) do
60
- renderer . render ( resources , options , self ) . to_json
60
+ JSON . generate ( renderer . render ( resources , options , self ) )
61
61
end
62
62
end
63
63
end
Original file line number Diff line number Diff line change @@ -17,4 +17,38 @@ def index
17
17
expect ( subject . key? ( 'data' ) ) . to be true
18
18
end
19
19
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
20
54
end
You can’t perform that action at this time.
0 commit comments