-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathrepresenter_spec.rb
46 lines (39 loc) · 1.14 KB
/
representer_spec.rb
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
# frozen_string_literal: true
describe Grape::Roar do
include_context 'Grape API App'
context 'representer' do
context 'with a known model' do
before do
subject.get('/article/:id') do
Article.new(title: 'Lonestar', id: params[:id])
end
end
it 'returns a hypermedia representation' do
get '/article/666'
expect(last_response.body).to eq '{"title":"Lonestar","id":"666","links":[{"rel":"self","href":"/article/666"}]}'
end
end
context 'without an instance singleton' do
context 'as nil' do
before do
subject.get('/article/:id') do
present(nil, with: ArticleRepresenter)
end
end
it 'raises TypeError' do
expect { get '/article/666' }.to raise_error(TypeError)
end
end
context 'as another immediate value' do
before do
subject.get('/article/:id') do
present(5, with: ArticleRepresenter)
end
end
it 'raises TypeError' do
expect { get '/article/666' }.to raise_error(TypeError)
end
end
end
end
end