-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpatch_method_helpers_spec.rb
86 lines (72 loc) · 1.81 KB
/
patch_method_helpers_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# frozen_string_literal: true
describe Grape::API::Helpers do
let(:patch_public) do
Class.new(Grape::API) do
format :json
version 'public-v1', using: :header, vendor: 'grape'
get do
{ ok: 'public' }
end
end
end
let(:auth_methods) do
Module.new do
def authenticate!; end
end
end
let(:patch_private) do
context = self
Class.new(Grape::API) do
format :json
version 'private-v1', using: :header, vendor: 'grape'
helpers context.auth_methods
before do
authenticate!
end
get do
{ ok: 'private' }
end
end
end
let(:main) do
context = self
Class.new(Grape::API) do
mount context.patch_public
mount context.patch_private
end
end
def app
main
end
context 'patch' do
it 'public' do
patch '/', {}, 'HTTP_ACCEPT' => 'application/vnd.grape-public-v1+json'
expect(last_response.status).to eq 405
end
it 'private' do
patch '/', {}, 'HTTP_ACCEPT' => 'application/vnd.grape-private-v1+json'
expect(last_response.status).to eq 405
end
it 'default' do
patch '/'
expect(last_response.status).to eq 405
end
end
context 'default' do
it 'public' do
get '/', {}, 'HTTP_ACCEPT' => 'application/vnd.grape-public-v1+json'
expect(last_response.status).to eq 200
expect(last_response.body).to eq({ ok: 'public' }.to_json)
end
it 'private' do
get '/', {}, 'HTTP_ACCEPT' => 'application/vnd.grape-private-v1+json'
expect(last_response.status).to eq 200
expect(last_response.body).to eq({ ok: 'private' }.to_json)
end
it 'default' do
get '/'
expect(last_response.status).to eq 200
expect(last_response.body).to eq({ ok: 'public' }.to_json)
end
end
end