zendesk_api 1.13.1 → 1.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/zendesk_api/client.rb +1 -1
- data/lib/zendesk_api/middleware/response/parse_json.rb +0 -1
- data/lib/zendesk_api/version.rb +1 -1
- metadata +10 -205
- data/.gitignore +0 -15
- data/.rspec +0 -2
- data/.travis.yml +0 -10
- data/.yardopts +0 -10
- data/Gemfile +0 -14
- data/LICENSE +0 -176
- data/README.md +0 -425
- data/Rakefile +0 -52
- data/spec/core/association_spec.rb +0 -256
- data/spec/core/bulk_actions_spec.rb +0 -69
- data/spec/core/client_spec.rb +0 -280
- data/spec/core/collection_spec.rb +0 -901
- data/spec/core/configuration_spec.rb +0 -28
- data/spec/core/create_resource_spec.rb +0 -39
- data/spec/core/data_namespace_spec.rb +0 -15
- data/spec/core/data_resource_spec.rb +0 -239
- data/spec/core/inflection_spec.rb +0 -7
- data/spec/core/lru_cache_spec.rb +0 -26
- data/spec/core/middleware/request/encode_json_spec.rb +0 -73
- data/spec/core/middleware/request/etag_cache_spec.rb +0 -21
- data/spec/core/middleware/request/retry_spec.rb +0 -49
- data/spec/core/middleware/request/test.jpg +0 -0
- data/spec/core/middleware/request/upload_spec.rb +0 -164
- data/spec/core/middleware/response/callback_spec.rb +0 -17
- data/spec/core/middleware/response/deflate_spec.rb +0 -21
- data/spec/core/middleware/response/gzip_spec.rb +0 -25
- data/spec/core/middleware/response/parse_iso_dates_spec.rb +0 -44
- data/spec/core/middleware/response/parse_json_spec.rb +0 -53
- data/spec/core/middleware/response/raise_error_spec.rb +0 -128
- data/spec/core/middleware/response/sanitize_response_spec.rb +0 -19
- data/spec/core/read_resource_spec.rb +0 -97
- data/spec/core/resource_spec.rb +0 -541
- data/spec/core/resources/automation_spec.rb +0 -81
- data/spec/core/resources/macro_spec.rb +0 -27
- data/spec/core/resources/trigger_spec.rb +0 -67
- data/spec/core/resources/view_spec.rb +0 -97
- data/spec/core/search_spec.rb +0 -23
- data/spec/core/spec_helper.rb +0 -162
- data/spec/core/trackie_spec.rb +0 -129
- data/spec/fixtures/Argentina.gif +0 -0
- data/spec/fixtures/Argentina2.gif +0 -0
- data/spec/fixtures/credentials.yml.example +0 -3
- data/spec/fixtures/sample_app.zip +0 -0
- data/spec/fixtures/test_resources.rb +0 -22
- data/spec/fixtures/zendesk.rb +0 -109
- data/spec/live/Readme.md +0 -4
- data/spec/live/activity_spec.rb +0 -12
- data/spec/live/app_installation_spec.rb +0 -58
- data/spec/live/app_spec.rb +0 -58
- data/spec/live/audit_spec.rb +0 -15
- data/spec/live/automation_spec.rb +0 -23
- data/spec/live/bookmark_spec.rb +0 -11
- data/spec/live/brand_spec.rb +0 -14
- data/spec/live/category_spec.rb +0 -12
- data/spec/live/collection_spec.rb +0 -64
- data/spec/live/custom_role_spec.rb +0 -5
- data/spec/live/dynamic_content/item_spec.rb +0 -16
- data/spec/live/dynamic_content/variant_spec.rb +0 -19
- data/spec/live/forum_spec.rb +0 -14
- data/spec/live/forum_subscription_spec.rb +0 -12
- data/spec/live/group_membership_spec.rb +0 -18
- data/spec/live/group_spec.rb +0 -32
- data/spec/live/identity_spec.rb +0 -14
- data/spec/live/locale_spec.rb +0 -9
- data/spec/live/macro_spec.rb +0 -44
- data/spec/live/organization_field_spec.rb +0 -12
- data/spec/live/organization_membership_spec.rb +0 -11
- data/spec/live/organization_spec.rb +0 -12
- data/spec/live/push_notification_device_spec.rb +0 -21
- data/spec/live/request_spec.rb +0 -38
- data/spec/live/satisfaction_rating_spec.rb +0 -6
- data/spec/live/setting_spec.rb +0 -25
- data/spec/live/suspended_ticket_spec.rb +0 -8
- data/spec/live/tag_spec.rb +0 -58
- data/spec/live/target_spec.rb +0 -17
- data/spec/live/ticket_field_spec.rb +0 -12
- data/spec/live/ticket_form_spec.rb +0 -14
- data/spec/live/ticket_metrics_spec.rb +0 -6
- data/spec/live/ticket_spec.rb +0 -136
- data/spec/live/topic_comment_spec.rb +0 -52
- data/spec/live/topic_spec.rb +0 -46
- data/spec/live/topic_subscription_spec.rb +0 -12
- data/spec/live/topic_vote_spec.rb +0 -13
- data/spec/live/trigger_spec.rb +0 -23
- data/spec/live/upload_spec.rb +0 -10
- data/spec/live/user_field_spec.rb +0 -12
- data/spec/live/user_spec.rb +0 -71
- data/spec/live/user_view_spec.rb +0 -16
- data/spec/live/view_spec.rb +0 -22
- data/spec/live/voice/phone_number_spec.rb +0 -13
- data/spec/macros/resource_macros.rb +0 -169
- data/zendesk_api.gemspec +0 -38
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'core/spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ZendeskAPI::Configuration do
|
|
4
|
-
subject { ZendeskAPI::Configuration.new }
|
|
5
|
-
|
|
6
|
-
it "should properly merge options" do
|
|
7
|
-
url = "test.host"
|
|
8
|
-
subject.url = url
|
|
9
|
-
expect(subject.options[:url]).to eq(url)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "should set accept header properly" do
|
|
13
|
-
expect(subject.options[:headers][:accept]).to eq('application/json')
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "should set user agent header properly" do
|
|
17
|
-
expect(subject.options[:headers][:user_agent]).to match(/ZendeskAPI Ruby/)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should set a default open_timeout" do
|
|
21
|
-
expect(subject.options[:request][:open_timeout]).to eq(10)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should merge options with client_options" do
|
|
25
|
-
subject.client_options = {:ssl => false}
|
|
26
|
-
expect(subject.options[:ssl]).to eq(false)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
require 'core/spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ZendeskAPI::CreateResource do
|
|
4
|
-
context "create" do
|
|
5
|
-
let(:attr) { { :test_field => "blah" } }
|
|
6
|
-
subject { ZendeskAPI::TestResource }
|
|
7
|
-
|
|
8
|
-
before(:each) do
|
|
9
|
-
stub_request(:post, %r{test_resources}).to_return(:body => json)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "should return instance of resource" do
|
|
13
|
-
expect(subject.create(client, attr)).to be_instance_of(subject)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
context "with client error" do
|
|
17
|
-
before(:each) do
|
|
18
|
-
stub_request(:post, %r{test_resources}).to_return(:status => 500)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "should handle it properly" do
|
|
22
|
-
expect { silence_logger { expect(subject.create(client, attr)).to be_nil } }.to_not raise_error
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context "create!" do
|
|
28
|
-
subject { ZendeskAPI::TestResource }
|
|
29
|
-
|
|
30
|
-
before(:each) do
|
|
31
|
-
stub_request(:post, %r{test_resources}).to_return(:status => 500)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "should raise if save fails" do
|
|
35
|
-
expect { subject.create!(client, :test_field => "blah") }.to raise_error(ZendeskAPI::Error::NetworkError)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require 'core/spec_helper'
|
|
2
|
-
|
|
3
|
-
class ZendeskAPI::DataNamespaceTest; end
|
|
4
|
-
|
|
5
|
-
describe ZendeskAPI::DataNamespace do
|
|
6
|
-
describe "descendants" do
|
|
7
|
-
let(:target_klass) { ZendeskAPI::DataNamespaceTest }
|
|
8
|
-
it "adds class to its descendants list when included" do
|
|
9
|
-
expect(ZendeskAPI::DataNamespace.descendants).not_to include(target_klass)
|
|
10
|
-
expect { target_klass.send(:include, ZendeskAPI::DataNamespace) }.
|
|
11
|
-
to change { ZendeskAPI::DataNamespace.descendants.count }.by(1)
|
|
12
|
-
expect(ZendeskAPI::DataNamespace.descendants).to include(target_klass)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
require 'core/spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ZendeskAPI::DataResource do
|
|
4
|
-
specify "singular resource name" do
|
|
5
|
-
expect(ZendeskAPI::Ticket.singular_resource_name).to eq("ticket")
|
|
6
|
-
expect(ZendeskAPI::TicketField.singular_resource_name).to eq("ticket_field")
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
specify "resource name" do
|
|
10
|
-
expect(ZendeskAPI::Ticket.resource_name).to eq("tickets")
|
|
11
|
-
expect(ZendeskAPI::TicketField.resource_name).to eq("ticket_fields")
|
|
12
|
-
expect(ZendeskAPI::Category.resource_name).to eq("categories")
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context "association" do
|
|
16
|
-
subject { ZendeskAPI::TestResource.new(client, :id => 1) }
|
|
17
|
-
let(:options) {{}}
|
|
18
|
-
|
|
19
|
-
before(:each) do
|
|
20
|
-
ZendeskAPI::TestResource.has :nil, options.merge(:class => ZendeskAPI::NilDataResource)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "should try and find non-existent object" do
|
|
24
|
-
stub_json_request(:get, %r{test_resources/1/nil}, json(:nil_data_resource => {}))
|
|
25
|
-
|
|
26
|
-
expect(subject.nil).to be_instance_of(ZendeskAPI::NilDataResource)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "inline => true" do
|
|
30
|
-
let(:options) {{ :inline => true }}
|
|
31
|
-
|
|
32
|
-
it "should not try and find non-existent object" do
|
|
33
|
-
subject.nil
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context "user" do
|
|
39
|
-
context "with first order attributes" do
|
|
40
|
-
subject { ZendeskAPI::TestResource.new(client) }
|
|
41
|
-
before(:each) { subject.attributes[:priority] = "normal" }
|
|
42
|
-
|
|
43
|
-
it "should be able to access underlying attributes" do
|
|
44
|
-
expect(subject.priority).to eq("normal")
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "should be able to change underlying attributes" do
|
|
48
|
-
expect { subject.priority = "urgent" }.to_not raise_error
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "should be able to iterate over underlying attributes" do
|
|
52
|
-
expect do
|
|
53
|
-
subject.map do |k, v|
|
|
54
|
-
[k.to_sym, v]
|
|
55
|
-
end
|
|
56
|
-
end.to_not raise_error
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context "with second order attributes" do
|
|
61
|
-
subject { ZendeskAPI::TestResource.new(client) }
|
|
62
|
-
before(:each) { subject.priority = "normal" }
|
|
63
|
-
|
|
64
|
-
it "should be able to change underlying attributes" do
|
|
65
|
-
expect(subject.priority).to eq("normal")
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "should be able to change underlying attributes" do
|
|
69
|
-
expect { subject.priority = "urgent" }.to_not raise_error
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "should be able to iterate over underlying attributes" do
|
|
73
|
-
expect do
|
|
74
|
-
subject.map do |k, v|
|
|
75
|
-
[k.to_sym, v]
|
|
76
|
-
end
|
|
77
|
-
end.to_not raise_error
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
context "has" do
|
|
83
|
-
before(:each) { ZendeskAPI::TestResource.has ZendeskAPI::TestResource }
|
|
84
|
-
|
|
85
|
-
context "class methods" do
|
|
86
|
-
subject { ZendeskAPI::TestResource }
|
|
87
|
-
|
|
88
|
-
it "should define a method with the same name" do
|
|
89
|
-
expect(subject.instance_methods.map(&:to_s)).to include("test_resource")
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
context "with explicit class name" do
|
|
93
|
-
before(:all) { ZendeskAPI::TestResource.has :baz, :class => ZendeskAPI::TestResource }
|
|
94
|
-
|
|
95
|
-
it "should define a method with the same name" do
|
|
96
|
-
expect(subject.instance_methods.map(&:to_s)).to include("baz")
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
context "instance method" do
|
|
102
|
-
context "with no side-loading" do
|
|
103
|
-
subject { ZendeskAPI::TestResource.new(client, :id => 1, :test_resource_id => 1) }
|
|
104
|
-
before(:each) { stub_json_request(:get, %r{test_resources/\d+}, json(:test_resource => {})) }
|
|
105
|
-
|
|
106
|
-
it "should attempt to grab the resource from the host" do
|
|
107
|
-
expect(subject.test_resource).to be_instance_of(ZendeskAPI::TestResource)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it "should pass the path on to the resource" do
|
|
111
|
-
expect(subject.test_resource.path).to eq("test_resources")
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
context "with a client error" do
|
|
115
|
-
before(:each) { stub_request(:get, %r{test_resources/\d+}).to_return(:status => 500) }
|
|
116
|
-
|
|
117
|
-
it "should handle it properly" do
|
|
118
|
-
expect { silence_logger{ expect(subject.test_resource).to be_nil } }.to_not raise_error
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
context "with an explicit path set" do
|
|
123
|
-
before(:each) do
|
|
124
|
-
ZendeskAPI::TestResource.has ZendeskAPI::TestResource, :path => "blergh"
|
|
125
|
-
stub_json_request(:get, %r{blergh/\d+}, json(:test_resource => {}))
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it "should call the right path" do
|
|
129
|
-
expect(subject.test_resource).to be_instance_of(ZendeskAPI::TestResource)
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
context "with side-loading of resource" do
|
|
135
|
-
let(:test_resource) { { :message => "FOO_OBJ" } }
|
|
136
|
-
subject { ZendeskAPI::TestResource.new(client, :test_resource => test_resource).test_resource }
|
|
137
|
-
|
|
138
|
-
it "should load the correct instance" do
|
|
139
|
-
expect(subject).to be_instance_of(ZendeskAPI::TestResource)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
it "should load foo from the hash" do
|
|
143
|
-
expect(subject.message).to eq("FOO_OBJ")
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
context "with side-loading of id" do
|
|
148
|
-
subject { ZendeskAPI::TestResource.new(client, :test_resource_id => 1) }
|
|
149
|
-
before(:each) do
|
|
150
|
-
stub_json_request(:get, %r{test_resources/1}, json("test_resource" => {}))
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
it "should find foo_id and load it from the api" do
|
|
154
|
-
subject.test_resource
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "should handle nil response from find api" do
|
|
158
|
-
expect(ZendeskAPI::TestResource).to receive(:find).twice.and_return(nil)
|
|
159
|
-
expect(subject.test_resource).to be_nil
|
|
160
|
-
subject.test_resource
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
context "has_many" do
|
|
167
|
-
before(:each) { ZendeskAPI::TestResource.has_many ZendeskAPI::TestResource }
|
|
168
|
-
|
|
169
|
-
context "class methods" do
|
|
170
|
-
subject { ZendeskAPI::TestResource }
|
|
171
|
-
|
|
172
|
-
it "should define a method with the same name" do
|
|
173
|
-
expect(subject.instance_methods.map(&:to_s)).to include("test_resources")
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
context "with explicit class name" do
|
|
177
|
-
before(:each) { ZendeskAPI::TestResource.has_many :cats, :class => ZendeskAPI::TestResource }
|
|
178
|
-
|
|
179
|
-
it "should define a method with the same name" do
|
|
180
|
-
expect(subject.instance_methods.map(&:to_s)).to include("cats")
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
context "instance method" do
|
|
186
|
-
context "with no side-loading" do
|
|
187
|
-
subject { ZendeskAPI::TestResource.new(client, :id => 1) }
|
|
188
|
-
|
|
189
|
-
it "should not attempt to grab the resource from the host" do
|
|
190
|
-
expect(subject.test_resources).to be_instance_of(ZendeskAPI::Collection)
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
it "should pass the path on to the resource" do
|
|
194
|
-
expect(subject.test_resources.path).to eq("test_resources/1/test_resources")
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
context "with an explicit path set" do
|
|
198
|
-
before(:each) do
|
|
199
|
-
ZendeskAPI::TestResource.has_many ZendeskAPI::TestResource, :path => "blargh"
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
it "should call the right path" do
|
|
203
|
-
expect(subject.test_resources.path).to eq("test_resources/1/blargh")
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
context "with side-loading of resource" do
|
|
209
|
-
let(:test_resources) { [{ :message => "FOO_OBJ" }] }
|
|
210
|
-
subject { ZendeskAPI::TestResource.new(client, :test_resources => test_resources).test_resources.first }
|
|
211
|
-
|
|
212
|
-
it "should properly create instance" do
|
|
213
|
-
expect(subject.message).to eq("FOO_OBJ")
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
it "should map bars onto TestResource class" do
|
|
217
|
-
expect(subject).to be_instance_of(ZendeskAPI::TestResource)
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
context "with side-loading of id" do
|
|
222
|
-
let(:test_resource_ids) { [1, 2, 3] }
|
|
223
|
-
subject { ZendeskAPI::TestResource.new(client, :test_resource_ids => test_resource_ids) }
|
|
224
|
-
|
|
225
|
-
it "should find foo_id and load it from the api" do
|
|
226
|
-
expect(ZendeskAPI::TestResource).to receive(:find).with(client, kind_of(Hash)).exactly(test_resource_ids.length).times
|
|
227
|
-
subject.test_resources
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
it "should handle nil response from find api" do
|
|
231
|
-
expect(ZendeskAPI::TestResource).to receive(:find).with(client, kind_of(Hash)).exactly(test_resource_ids.length).times.and_return(nil)
|
|
232
|
-
expect(subject.test_resources).to be_empty
|
|
233
|
-
subject.test_resources # Test expectations
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
|
data/spec/core/lru_cache_spec.rb
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
require 'core/spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ZendeskAPI::LRUCache do
|
|
4
|
-
let(:cache){ ZendeskAPI::LRUCache.new(2) }
|
|
5
|
-
|
|
6
|
-
it "writes and reads" do
|
|
7
|
-
expect(cache.write("x", 1)).to eq(1)
|
|
8
|
-
expect(cache.read("x")).to eq(1)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "drops" do
|
|
12
|
-
cache.write("x", 1)
|
|
13
|
-
cache.write("y", 1)
|
|
14
|
-
cache.write("x", 1)
|
|
15
|
-
cache.write("z", 1)
|
|
16
|
-
expect(cache.read("z")).to eq(1)
|
|
17
|
-
expect(cache.read("x")).to eq(1)
|
|
18
|
-
expect(cache.read("y")).to eq(nil)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "fetches" do
|
|
22
|
-
expect(cache.fetch("x"){ 1 }).to eq(1)
|
|
23
|
-
expect(cache.read("x")).to eq(1)
|
|
24
|
-
expect(cache.fetch("x"){ 2 }).to eq(1)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
require 'core/spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ZendeskAPI::Middleware::Request::EncodeJson do
|
|
4
|
-
let(:app) do
|
|
5
|
-
ZendeskAPI::Middleware::Request::EncodeJson.new(lambda {|x| x})
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
let(:response) { app.call({ :request_headers => {} }.merge(env)) }
|
|
9
|
-
|
|
10
|
-
context 'with a nil body' do
|
|
11
|
-
let(:env) {{ :body => nil }}
|
|
12
|
-
|
|
13
|
-
it 'should not return json' do
|
|
14
|
-
expect(response[:body]).to be_nil
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'with an empty body' do
|
|
19
|
-
let(:env) {{ :body => '' }}
|
|
20
|
-
|
|
21
|
-
it 'should not return json' do
|
|
22
|
-
expect(response[:body]).to eq('')
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context 'with a proper mime type' do
|
|
27
|
-
context 'empty' do
|
|
28
|
-
let(:env) {{ :body => { :a => :b } }}
|
|
29
|
-
|
|
30
|
-
it 'encodes json' do
|
|
31
|
-
expect(response[:body]).to eq(JSON.dump(:a => :b))
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'sets the content type' do
|
|
35
|
-
expect(response[:request_headers]['Content-Type']).to eq('application/json')
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context 'application/json' do
|
|
40
|
-
let(:env) {{
|
|
41
|
-
:body => { :a => :b },
|
|
42
|
-
:request_headers => {
|
|
43
|
-
'Content-Type' => 'application/json'
|
|
44
|
-
}
|
|
45
|
-
}}
|
|
46
|
-
|
|
47
|
-
it 'encodes json' do
|
|
48
|
-
expect(response[:body]).to eq(JSON.dump(:a => :b))
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'keeps the content type' do
|
|
52
|
-
expect(response[:request_headers]['Content-Type']).to eq('application/json')
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
context 'application/json; encoding=utf-8' do
|
|
57
|
-
let(:env) {{
|
|
58
|
-
:body => { :a => :b },
|
|
59
|
-
:request_headers => {
|
|
60
|
-
'Content-Type' => 'application/json; encoding=utf-8'
|
|
61
|
-
}
|
|
62
|
-
}}
|
|
63
|
-
|
|
64
|
-
it 'encodes json' do
|
|
65
|
-
expect(response[:body]).to eq(JSON.dump(:a => :b))
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it 'keeps the content type' do
|
|
69
|
-
expect(response[:request_headers]['Content-Type']).to eq('application/json; encoding=utf-8')
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require 'core/spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ZendeskAPI::Middleware::Request::EtagCache do
|
|
4
|
-
it "caches" do
|
|
5
|
-
client.config.cache.size = 1
|
|
6
|
-
|
|
7
|
-
stub_json_request(:get, %r{blergh}, '{"x":1}', :headers => {"Etag" => "x"})
|
|
8
|
-
first_response = client.connection.get("blergh")
|
|
9
|
-
expect(first_response.status).to eq(200)
|
|
10
|
-
expect(first_response.body).to eq({"x"=>1})
|
|
11
|
-
|
|
12
|
-
stub_request(:get, %r{blergh}).to_return(:status => 304, :headers => {"Etag" => "x"})
|
|
13
|
-
response = client.connection.get("blergh")
|
|
14
|
-
expect(response.status).to eq(304)
|
|
15
|
-
expect(response.body).to eq({"x"=>1})
|
|
16
|
-
|
|
17
|
-
%w{content_encoding content_type content_length etag}.each do |header|
|
|
18
|
-
expect(response.headers[header]).to eq(first_response.headers[header])
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|