-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathrender_jsonapi_spec.rb
More file actions
54 lines (43 loc) · 1.21 KB
/
render_jsonapi_spec.rb
File metadata and controls
54 lines (43 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'rails_helper'
describe ActionController::Base, '#render', type: :controller do
context 'when calling render jsonapi:' do
controller do
def index
render jsonapi: nil
end
end
subject { JSON.parse(response.body) }
it 'renders a JSON API success document' do
get :index
expect(response.content_type).to eq('application/vnd.api+json')
expect(subject.key?('data')).to be true
end
end
context 'when using a cache' do
controller do
def serializer
Class.new(JSONAPI::Serializable::Resource) do
type 'users'
attribute :name
def jsonapi_cache_key(*)
'foo'
end
end
end
def index
user = OpenStruct.new(id: 1, name: 'Lucas')
render jsonapi: user,
class: { OpenStruct: serializer },
cache: Rails.cache
end
end
subject { JSON.parse(response.body) }
it 'renders a JSON API success document' do
get :index
expect(Rails.cache.exist?('foo')).to be true
get :index
expect(response.content_type).to eq('application/vnd.api+json')
expect(subject.key?('data')).to be true
end
end
end