-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathcontent_types_spec.rb
78 lines (62 loc) · 1.88 KB
/
content_types_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
# frozen_string_literal: true
describe Grape::ContentTypes do
describe 'DEFAULTS' do
subject { described_class::DEFAULTS }
let(:expected_value) do
{
xml: 'application/xml',
serializable_hash: 'application/json',
json: 'application/json',
binary: 'application/octet-stream',
txt: 'text/plain'
}.freeze
end
it { is_expected.to eq(expected_value) }
end
describe 'MIME_TYPES' do
subject { described_class::MIME_TYPES }
let(:expected_value) do
{
'application/xml' => :xml,
'application/json' => :json,
'application/octet-stream' => :binary,
'text/plain' => :txt
}.freeze
end
it { is_expected.to eq(expected_value) }
end
describe '.content_types_for' do
subject { described_class.content_types_for(from_settings) }
context 'when from_settings is present' do
let(:from_settings) { { a: :b } }
it { is_expected.to eq(from_settings) }
end
context 'when from_settings is not present' do
let(:from_settings) { nil }
it { is_expected.to be(described_class::DEFAULTS) }
end
end
describe '.mime_types_for' do
subject { described_class.mime_types_for(from_settings) }
context 'when from_settings is equal to Grape::ContentTypes::DEFAULTS' do
let(:from_settings) do
{
xml: 'application/xml',
serializable_hash: 'application/json',
json: 'application/json',
binary: 'application/octet-stream',
txt: 'text/plain'
}.freeze
end
it { is_expected.to be(described_class::MIME_TYPES) }
end
context 'when from_settings is not equal to Grape::ContentTypes::DEFAULTS' do
let(:from_settings) do
{
xml: 'application/xml;charset=utf-8'
}
end
it { is_expected.to eq('application/xml' => :xml) }
end
end
end