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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zendesk_api/client.rb +1 -1
  3. data/lib/zendesk_api/middleware/response/parse_json.rb +0 -1
  4. data/lib/zendesk_api/version.rb +1 -1
  5. metadata +10 -205
  6. data/.gitignore +0 -15
  7. data/.rspec +0 -2
  8. data/.travis.yml +0 -10
  9. data/.yardopts +0 -10
  10. data/Gemfile +0 -14
  11. data/LICENSE +0 -176
  12. data/README.md +0 -425
  13. data/Rakefile +0 -52
  14. data/spec/core/association_spec.rb +0 -256
  15. data/spec/core/bulk_actions_spec.rb +0 -69
  16. data/spec/core/client_spec.rb +0 -280
  17. data/spec/core/collection_spec.rb +0 -901
  18. data/spec/core/configuration_spec.rb +0 -28
  19. data/spec/core/create_resource_spec.rb +0 -39
  20. data/spec/core/data_namespace_spec.rb +0 -15
  21. data/spec/core/data_resource_spec.rb +0 -239
  22. data/spec/core/inflection_spec.rb +0 -7
  23. data/spec/core/lru_cache_spec.rb +0 -26
  24. data/spec/core/middleware/request/encode_json_spec.rb +0 -73
  25. data/spec/core/middleware/request/etag_cache_spec.rb +0 -21
  26. data/spec/core/middleware/request/retry_spec.rb +0 -49
  27. data/spec/core/middleware/request/test.jpg +0 -0
  28. data/spec/core/middleware/request/upload_spec.rb +0 -164
  29. data/spec/core/middleware/response/callback_spec.rb +0 -17
  30. data/spec/core/middleware/response/deflate_spec.rb +0 -21
  31. data/spec/core/middleware/response/gzip_spec.rb +0 -25
  32. data/spec/core/middleware/response/parse_iso_dates_spec.rb +0 -44
  33. data/spec/core/middleware/response/parse_json_spec.rb +0 -53
  34. data/spec/core/middleware/response/raise_error_spec.rb +0 -128
  35. data/spec/core/middleware/response/sanitize_response_spec.rb +0 -19
  36. data/spec/core/read_resource_spec.rb +0 -97
  37. data/spec/core/resource_spec.rb +0 -541
  38. data/spec/core/resources/automation_spec.rb +0 -81
  39. data/spec/core/resources/macro_spec.rb +0 -27
  40. data/spec/core/resources/trigger_spec.rb +0 -67
  41. data/spec/core/resources/view_spec.rb +0 -97
  42. data/spec/core/search_spec.rb +0 -23
  43. data/spec/core/spec_helper.rb +0 -162
  44. data/spec/core/trackie_spec.rb +0 -129
  45. data/spec/fixtures/Argentina.gif +0 -0
  46. data/spec/fixtures/Argentina2.gif +0 -0
  47. data/spec/fixtures/credentials.yml.example +0 -3
  48. data/spec/fixtures/sample_app.zip +0 -0
  49. data/spec/fixtures/test_resources.rb +0 -22
  50. data/spec/fixtures/zendesk.rb +0 -109
  51. data/spec/live/Readme.md +0 -4
  52. data/spec/live/activity_spec.rb +0 -12
  53. data/spec/live/app_installation_spec.rb +0 -58
  54. data/spec/live/app_spec.rb +0 -58
  55. data/spec/live/audit_spec.rb +0 -15
  56. data/spec/live/automation_spec.rb +0 -23
  57. data/spec/live/bookmark_spec.rb +0 -11
  58. data/spec/live/brand_spec.rb +0 -14
  59. data/spec/live/category_spec.rb +0 -12
  60. data/spec/live/collection_spec.rb +0 -64
  61. data/spec/live/custom_role_spec.rb +0 -5
  62. data/spec/live/dynamic_content/item_spec.rb +0 -16
  63. data/spec/live/dynamic_content/variant_spec.rb +0 -19
  64. data/spec/live/forum_spec.rb +0 -14
  65. data/spec/live/forum_subscription_spec.rb +0 -12
  66. data/spec/live/group_membership_spec.rb +0 -18
  67. data/spec/live/group_spec.rb +0 -32
  68. data/spec/live/identity_spec.rb +0 -14
  69. data/spec/live/locale_spec.rb +0 -9
  70. data/spec/live/macro_spec.rb +0 -44
  71. data/spec/live/organization_field_spec.rb +0 -12
  72. data/spec/live/organization_membership_spec.rb +0 -11
  73. data/spec/live/organization_spec.rb +0 -12
  74. data/spec/live/push_notification_device_spec.rb +0 -21
  75. data/spec/live/request_spec.rb +0 -38
  76. data/spec/live/satisfaction_rating_spec.rb +0 -6
  77. data/spec/live/setting_spec.rb +0 -25
  78. data/spec/live/suspended_ticket_spec.rb +0 -8
  79. data/spec/live/tag_spec.rb +0 -58
  80. data/spec/live/target_spec.rb +0 -17
  81. data/spec/live/ticket_field_spec.rb +0 -12
  82. data/spec/live/ticket_form_spec.rb +0 -14
  83. data/spec/live/ticket_metrics_spec.rb +0 -6
  84. data/spec/live/ticket_spec.rb +0 -136
  85. data/spec/live/topic_comment_spec.rb +0 -52
  86. data/spec/live/topic_spec.rb +0 -46
  87. data/spec/live/topic_subscription_spec.rb +0 -12
  88. data/spec/live/topic_vote_spec.rb +0 -13
  89. data/spec/live/trigger_spec.rb +0 -23
  90. data/spec/live/upload_spec.rb +0 -10
  91. data/spec/live/user_field_spec.rb +0 -12
  92. data/spec/live/user_spec.rb +0 -71
  93. data/spec/live/user_view_spec.rb +0 -16
  94. data/spec/live/view_spec.rb +0 -22
  95. data/spec/live/voice/phone_number_spec.rb +0 -13
  96. data/spec/macros/resource_macros.rb +0 -169
  97. data/zendesk_api.gemspec +0 -38
@@ -1,19 +0,0 @@
1
- require 'core/spec_helper'
2
-
3
- describe ZendeskAPI::Middleware::Response::SanitizeResponse do
4
- def fake_response(data)
5
- stub_json_request(:get, %r{blergh}, data)
6
- response = client.connection.get('blergh')
7
- expect(response.status).to eq(200)
8
- response
9
- end
10
-
11
- describe 'with bad characters' do
12
- let(:response) { fake_response("{\"x\":\"2012-02-01T13:14:15Z\", \"y\":\"\u0315\u0316\u01333\u0270\u022712awesome!\ud83d\udc4d\"}") }
13
-
14
- it 'removes bad characters' do
15
- expect(response.body.to_s.valid_encoding?).to be(true)
16
- expect(response.body['y'].to_s).to eq("\u0315\u0316\u01333\u0270\u022712awesome!")
17
- end
18
- end
19
- end
@@ -1,97 +0,0 @@
1
- require 'core/spec_helper'
2
-
3
- describe ZendeskAPI::ReadResource do
4
- context "find" do
5
- let(:id) { 1 }
6
- subject { ZendeskAPI::TestResource }
7
-
8
- context "normal request" do
9
- before(:each) do
10
- stub_json_request(:get, %r{test_resources/#{id}}, json("test_resource" => {}))
11
- end
12
-
13
- it "should return instance of resource" do
14
- expect(subject.find(client, :id => id)).to be_instance_of(subject)
15
- end
16
- end
17
-
18
- it "should blow up without an id which would build an invalid url" do
19
- expect{
20
- ZendeskAPI::User.find(client, :foo => :bar)
21
- }.to raise_error("No :id given")
22
- end
23
-
24
- context "with overriden handle_response" do
25
- subject do
26
- Class.new(ZendeskAPI::TestResource) do
27
- def self.singular_resource_name
28
- 'hello'
29
- end
30
-
31
- def handle_response(response)
32
- @attributes.replace(response.body)
33
- end
34
- end
35
- end
36
-
37
- before(:each) do
38
- stub_json_request(:get, %r{hellos/#{id}}, json(:testing => 1))
39
- end
40
-
41
- it "should return instance of resource" do
42
- object = subject.find(client, :id => id)
43
- expect(object).to be_instance_of(subject)
44
- expect(object.testing).to eq(1)
45
- end
46
- end
47
-
48
- context "with side loads" do
49
- before(:each) do
50
- stub_json_request(:get, %r{test_resources/#{id}\?include=nil_resource}, json(
51
- "test_resource" => { :id => 1, :nil_resource_id => 2 },
52
- "nil_resources" => [{ :id => 1, :name => :bye }, { :id => 2, :name => :hi }]
53
- ))
54
-
55
- subject.has ZendeskAPI::NilResource
56
- @resource = subject.find(client, :id => id, :include => :nil_resource)
57
- end
58
-
59
- it "should side load nil resource" do
60
- expect(@resource.nil_resource.name).to eq("hi")
61
- end
62
- end
63
-
64
- context "with client error" do
65
- it "should handle 500 properly" do
66
- stub_request(:get, %r{test_resources/#{id}}).to_return(:status => 500)
67
- expect(subject.find(client, :id => id)).to eq(nil)
68
- end
69
-
70
- it "should handle 404 properly" do
71
- stub_request(:get, %r{test_resources/#{id}}).to_return(:status => 404)
72
- expect(subject.find(client, :id => id)).to eq(nil)
73
- end
74
- end
75
- end
76
-
77
- context "#reload!" do
78
- let(:id) { 2 }
79
-
80
- subject { ZendeskAPI::TestResource.new(client, :id => id, :name => 'Old Name') }
81
-
82
- before(:each) do
83
- stub_json_request(:get, %r{test_resources/#{id}}, json("test_resource" => {:id => id, :name => "New Name" }))
84
- end
85
-
86
- it "reloads the data" do
87
- expect(subject.name).to eq('Old Name')
88
- assert_not_requested(:get, %r{test_resources/#{id}})
89
-
90
- subject.reload!
91
-
92
- assert_requested(:get, %r{test_resources/#{id}})
93
- expect(subject.name).to eq('New Name')
94
- end
95
- end
96
- end
97
-
@@ -1,541 +0,0 @@
1
- require 'core/spec_helper'
2
-
3
- describe ZendeskAPI::Resource do
4
- context "initialize" do
5
- context "with :global as part of attributes" do
6
- it "should set @global_params" do
7
- resource = ZendeskAPI::TestResource.new(client, { :global => { :something => 'hey' }})
8
- expect(resource.instance_variable_get(:@global_params)).to eq({ :something => 'hey' })
9
- end
10
- end
11
- end
12
-
13
- context "#update" do
14
- context "class method" do
15
- let(:id) { 1 }
16
- subject { ZendeskAPI::TestResource }
17
-
18
- before(:each) do
19
- stub_json_request(:put, %r{test_resources/#{id}}).with(:body => json({ :test_resource => { :test => :hello } }))
20
- end
21
-
22
- it "should return instance of resource" do
23
- expect(subject.update(client, :id => id, :test => :hello)).to be_truthy
24
- end
25
-
26
- context "with global params" do
27
- before(:each) do
28
- stub_json_request(:put, %r{test_resources/#{id}}).with(:body => json({ :test_resource => { :test => :hello }, :something => "something"}))
29
- end
30
-
31
- it "should return instance of resource" do
32
- expect(subject.update(client, :id => id, :test => :hello, :global => {:something => "something"})).to be_truthy
33
- end
34
- end
35
-
36
- context "with client error" do
37
- before(:each) do
38
- stub_request(:put, %r{test_resources/#{id}}).to_return(:status => 500)
39
- end
40
-
41
- it "should handle it properly" do
42
- expect { silence_logger{ expect(subject.update(client, :id => id)).to be(false) } }.to_not raise_error
43
- end
44
- end
45
- end
46
- end
47
-
48
- context "#destroy" do
49
- context "class method" do
50
- let(:id) { 1 }
51
- subject { ZendeskAPI::TestResource }
52
-
53
- before(:each) do
54
- stub_json_request(:delete, %r{test_resources/#{id}})
55
- end
56
-
57
- it "should return instance of resource" do
58
- expect(subject.destroy(client, :id => id)).to be(true)
59
- end
60
-
61
- context "with client error" do
62
- before(:each) do
63
- stub_request(:delete, %r{test_resources/#{id}}).to_return(:status => 500)
64
- end
65
-
66
- it "should handle it properly" do
67
- expect { silence_logger{ expect(subject.destroy(client, :id => id)).to be(false) } }.to_not raise_error
68
- end
69
- end
70
- end
71
-
72
- context "instance method" do
73
- subject { ZendeskAPI::TestResource.new(client, :id => 1) }
74
-
75
- before(:each) do
76
- stub_request(:delete, %r{test_resources}).to_return(:status => 200)
77
- end
78
-
79
- it "should return true and set destroyed" do
80
- expect(subject.destroy).to be(true)
81
- expect(subject.destroyed?).to be(true)
82
- expect(subject.destroy).to be(false)
83
- end
84
-
85
- context "with client error" do
86
- before(:each) do
87
- stub_request(:delete, %r{test_resources}).to_return(:status => 500)
88
- end
89
-
90
- it "should return false and not set destroyed" do
91
- silence_logger{ expect(subject.destroy).to be(false) }
92
- expect(subject.destroyed?).to be(false)
93
- end
94
- end
95
- end
96
- end
97
-
98
- context "#save!" do
99
- subject { ZendeskAPI::TestResource.new(client, :id => 1) }
100
-
101
- before(:each) do
102
- stub_request(:put, %r{test_resources/1}).to_return(:status => 422)
103
- end
104
-
105
- it "should raise if save fails" do
106
- expect { subject.save! }.to raise_error(ZendeskAPI::Error::RecordInvalid)
107
- end
108
- end
109
-
110
- context "#save" do
111
- let(:id) { 1 }
112
- let(:attr) { { :param => "test" } }
113
- subject { ZendeskAPI::TestResource.new(client, attr.merge(:id => id)) }
114
-
115
- before :each do
116
- stub_json_request(:put, %r{test_resources/#{id}}, json(:test_resource => { :param => "abc" }))
117
- end
118
-
119
- it "should not save if already destroyed" do
120
- expect(subject).to receive(:destroyed?).and_return(true)
121
- expect(subject.save).to be(false)
122
- end
123
-
124
- it "should not be a new record with an id" do
125
- expect(subject.new_record?).to be(false)
126
- end
127
-
128
- it "should put on save" do
129
- expect(subject.save).to be(true)
130
- expect(subject[:param]).to eq("abc")
131
- end
132
-
133
- context "with unused associations" do
134
- before do
135
- ZendeskAPI::TestResource.associations.clear
136
- ZendeskAPI::TestResource.has :child, :class => ZendeskAPI::TestResource::TestChild
137
- ZendeskAPI::TestResource.has_many :children, :class => ZendeskAPI::TestResource::TestChild
138
- end
139
-
140
- it "should not touch them" do
141
- expect(subject.save).to eq(true)
142
- end
143
- end
144
-
145
- context "with client error" do
146
- before :each do
147
- stub_request(:put, %r{test_resources/1}).to_return(:status => 500)
148
- end
149
-
150
- it "should be properly handled" do
151
- expect { silence_logger { expect(subject.save).to be(false) } }.to_not raise_error
152
- end
153
- end
154
-
155
- context "new record" do
156
- subject { ZendeskAPI::TestResource.new(client, attr) }
157
-
158
- before :each do
159
- stub_json_request(:post, %r{test_resources}, json(:test_resource => attr.merge(:id => id)), :status => 201)
160
- end
161
-
162
- it "should be true without an id" do
163
- expect(subject.new_record?).to be(true)
164
- end
165
-
166
- it "should be false after creating" do
167
- expect(subject.save).to be(true)
168
- expect(subject.new_record?).to be(false)
169
- expect(subject.id).to eq(id)
170
- end
171
- end
172
-
173
- context "with nested associations to save" do
174
- context "has" do
175
- before(:each) do
176
- ZendeskAPI::TestResource.associations.clear
177
- ZendeskAPI::TestResource.has :child, :class => ZendeskAPI::TestResource::TestChild
178
- stub_json_request(:put, %r{test_resources})
179
- subject.child = { :id => 2 }
180
- end
181
-
182
- it "should call save on the association" do
183
- subject.child.foo = "bar"
184
- expect(subject.child).to receive(:save)
185
-
186
- subject.save
187
-
188
- expect(subject.instance_variable_get(:@child)).to be_nil
189
- end
190
-
191
- it "should not call save on the association if they are synced" do
192
- expect(subject.child).to_not receive(:save)
193
-
194
- subject.save
195
-
196
- expect(subject.instance_variable_get(:@child)).to be_nil
197
- end
198
- end
199
-
200
- context "has_many" do
201
- before(:each) do
202
- ZendeskAPI::TestResource.associations.clear
203
- ZendeskAPI::TestResource.has_many :children, :class => ZendeskAPI::TestResource::TestChild
204
-
205
- stub_json_request(:put, %r{test_resources})
206
- stub_json_request(:get, %r{children}, json(:test_children => []))
207
- end
208
-
209
- it "should reset children_ids on save" do
210
- subject.children = [2, 3]
211
- subject.children_ids = [1]
212
- subject.save
213
- expect(subject.children_ids).to eq([2,3])
214
- expect(subject.instance_variable_get(:@children)).to be_nil
215
- end
216
-
217
- it "should not save the associated objects when there are no changes" do
218
- subject.children = [2]
219
- expect(subject.children.first).to_not receive(:save)
220
- subject.save
221
- expect(subject.instance_variable_get(:@children)).to be_nil
222
- end
223
-
224
- it "should save the associated objects when it is new" do
225
- subject.children = [{:foo => "bar"}]
226
- expect(subject.children.first).to receive(:save)
227
- subject.save
228
- expect(subject.instance_variable_get(:@children)).to be_nil
229
- end
230
-
231
- it "should not save the associated objects when it is set via full hash" do
232
- subject.children = [{:id => 1, :foo => "bar"}]
233
- expect(subject.children.first).to_not receive(:save)
234
- subject.save
235
- expect(subject.instance_variable_get(:@children)).to be_nil
236
- end
237
-
238
- it "should save the associated objects when it is changes" do
239
- subject.children = [{:id => 1}]
240
- subject.children.first.foo = "bar"
241
- expect(subject.children.first).to receive(:save)
242
- subject.save
243
- expect(subject.instance_variable_get(:@children)).to be_nil
244
- end
245
- end
246
-
247
- context "inline" do
248
- before(:each) do
249
- class ZendeskAPI::NilResource
250
- def to_param; "TESTDATA"; end
251
- end
252
-
253
- ZendeskAPI::TestResource.associations.clear
254
- end
255
-
256
- context "true" do
257
- before(:each) do
258
- ZendeskAPI::TestResource.has :nil, :class => ZendeskAPI::NilResource, :inline => true
259
-
260
- subject.nil = { :abc => :def }
261
- end
262
-
263
- it "should save param data" do
264
- subject.save_associations
265
-
266
- expect(subject.attributes[:nil]).to eq("TESTDATA")
267
- end
268
-
269
- it "should not save param data when unchanged" do
270
- subject.nil.clear_changes
271
- subject.save_associations
272
-
273
- expect(subject.attributes[:nil]).to be_nil
274
- end
275
- end
276
-
277
- context "create" do
278
- before(:each) do
279
- ZendeskAPI::TestResource.has :nil, :class => ZendeskAPI::NilResource, :inline => :create
280
- subject.nil = { :abc => :def }
281
- end
282
-
283
- context "with a new record" do
284
- before(:each) do
285
- subject.id = nil
286
- subject.save_associations
287
- end
288
-
289
- it "should save param data" do
290
- expect(subject.attributes[:nil]).to eq("TESTDATA")
291
- end
292
- end
293
-
294
- context "with a saved record" do
295
- before(:each) do
296
- subject.save_associations
297
- end
298
-
299
- it "should not save param data" do
300
- expect(subject.attributes[:nil]).to be_nil
301
- end
302
- end
303
- end
304
- end
305
- end
306
- end
307
-
308
- context "on any" do
309
- let(:method) { "test_any_method" }
310
-
311
- before(:each) do
312
- ZendeskAPI::TestResource.any method
313
- end
314
-
315
- context "class method" do
316
- subject { ZendeskAPI::TestResource }
317
-
318
- it "should create a method of the same name" do
319
- expect(subject.instance_methods.map(&:to_s)).to include(method)
320
- end
321
- end
322
-
323
- context "instance method" do
324
- subject { ZendeskAPI::TestResource.new(client, :id => 1) }
325
-
326
- it "throws an argumenterror without a :verb" do
327
- expect { subject.send(method) }.to raise_error(ArgumentError)
328
- end
329
-
330
- context "with an array response" do
331
- before(:each) do
332
- stub_json_request(:put, %r{test_resources/1/#{method}}, json(:test_resources => [{ :id => 1, :method => method }]))
333
- end
334
-
335
- it "should return true" do
336
- expect(subject.send(method, :verb => :put)).to be(true)
337
- end
338
-
339
- it "should update the attributes if they exist" do
340
- subject.send(method, :verb => :put)
341
- expect(subject[:method]).to eq(method)
342
- end
343
- end
344
-
345
- context "with a resource response" do
346
- before(:each) do
347
- stub_json_request(:put, %r{test_resources/1/#{method}}, json(:test_resource => { :id => 1, :method => method }))
348
- end
349
-
350
- it "should return true" do
351
- expect(subject.send(method, :verb => :put)).to be(true)
352
- end
353
-
354
- it "should update the attributes if they exist" do
355
- subject.send(method, :verb => :put)
356
- expect(subject[:method]).to eq(method)
357
- end
358
- end
359
-
360
- context "with client error" do
361
- before(:each) do
362
- stub_request(:put, %r{test_resources/1/#{method}}).to_return(:status => 500)
363
- end
364
-
365
- it "doesn't raise without bang" do
366
- silence_logger { expect(subject.send("#{method}", :verb => :put)).to be(false) }
367
- end
368
-
369
- it "raises with bang" do
370
- expect { silence_logger{ subject.send("#{method}!", :verb => :put) } }.to raise_error(ZendeskAPI::Error::ClientError)
371
- end
372
- end
373
- end
374
- end
375
-
376
- %w{put post delete}.each do |verb|
377
- context "on #{verb}" do
378
- let(:method) { "test_#{verb}_method" }
379
- before(:each) do
380
- ZendeskAPI::TestResource.send(verb, method)
381
- end
382
-
383
- context "class method" do
384
- subject { ZendeskAPI::TestResource }
385
-
386
- it "should create a method of the same name" do
387
- expect(subject.instance_methods.map(&:to_s)).to include(method)
388
- end
389
- end
390
-
391
- context "instance method" do
392
- subject { ZendeskAPI::TestResource.new(client, :id => 1) }
393
-
394
- context "with an array response" do
395
- before(:each) do
396
- stub_json_request(verb.to_sym, %r{test_resources/1/#{method}}, json(:test_resources => [{ :id => 1, :method => method }]))
397
- end
398
-
399
- it "should return true" do
400
- expect(subject.send(method)).to be(true)
401
- end
402
-
403
- it "should update the attributes if they exist" do
404
- subject.send(method)
405
- expect(subject[:method]).to eq(method)
406
- end
407
- end
408
-
409
- context "with a resource response" do
410
- before(:each) do
411
- stub_json_request(verb.to_sym, %r{test_resources/1/#{method}}, json(:test_resource => { :id => 1, :method => method }))
412
- end
413
-
414
- it "should return true" do
415
- expect(subject.send(method)).to be(true)
416
- end
417
-
418
- it "should update the attributes if they exist" do
419
- subject.send(method)
420
- expect(subject[:method]).to eq(method)
421
- end
422
- end
423
-
424
- context "with client error" do
425
- before(:each) do
426
- stub_request(verb.to_sym, %r{test_resources/1/#{method}}).to_return(:status => 500)
427
- end
428
-
429
- it "doesn't raise without bang" do
430
- silence_logger { expect(subject.send("#{method}")).to be(false) }
431
- end
432
-
433
- it "raises with bang" do
434
- expect { silence_logger{ subject.send("#{method}!") } }.to raise_error(ZendeskAPI::Error::ClientError)
435
- end
436
- end
437
- end
438
- end
439
- end
440
-
441
- context "#inspect" do
442
- it "should display nicely" do
443
- expect(ZendeskAPI::User.new(client, :foo => :bar).inspect).to eq("#<ZendeskAPI::User {\"foo\"=>:bar}>")
444
- end
445
- end
446
-
447
- context "#to_json" do
448
- subject { ZendeskAPI::TestResource.new(client, :id => 1) }
449
-
450
- it "should call #to_json on @attributes" do
451
- expect(subject.attributes).to receive(:to_json)
452
- subject.to_json
453
- end
454
- end
455
-
456
- context "#==" do
457
- it "is same when id is same" do
458
- expect(ZendeskAPI::TestResource.new(client, :id => 1, "bar" => "baz")).to eq(ZendeskAPI::TestResource.new(client, :id => 1, "foo" => "bar"))
459
- end
460
-
461
- it "is same when object_id is same" do
462
- object = ZendeskAPI::TestResource.new(client, "bar" => "baz")
463
- expect(object).to eq(object)
464
- end
465
-
466
- it "is different when both have no id" do
467
- expect(ZendeskAPI::TestResource.new(client)).to_not eq(ZendeskAPI::TestResource.new(client))
468
- end
469
-
470
- it "is different when id is different" do
471
- expect(ZendeskAPI::TestResource.new(client, :id => 2)).to_not eq(ZendeskAPI::TestResource.new(client, :id => 1))
472
- end
473
-
474
- it "is same when class is Data" do
475
- expect(ZendeskAPI::TestResource.new(client, :id => 2)).to eq(ZendeskAPI::TestResource::TestChild.new(client, :id => 2))
476
- end
477
-
478
- it "is same when class is Integer" do
479
- expect(ZendeskAPI::TestResource.new(client, :id => 2)).to eq(2)
480
- end
481
-
482
- it "is different when class is Integer" do
483
- expect(ZendeskAPI::TestResource.new(client, :id => 2)).to_not eq(3)
484
- end
485
-
486
- it "is different when other is no resource" do
487
- expect(ZendeskAPI::TestResource.new(client, :id => 2)).to_not eq(nil)
488
- end
489
-
490
- it "warns about weird comparissons" do
491
- object = ZendeskAPI::TestResource.new(client, :id => 2)
492
- expect(object).to receive(:warn)
493
- expect(object).to_not eq("xxx")
494
- end
495
- end
496
-
497
- context "SingularTestResource" do
498
- context "#find" do
499
- before do
500
- stub_json_request(:get, %r{/singular_test_resource})
501
- end
502
-
503
- it "should not require an id" do
504
- expect do
505
- ZendeskAPI::SingularTestResource.find(client)
506
- end.to_not raise_error
507
- end
508
- end
509
-
510
- context "#update" do
511
- before do
512
- stub_json_request(:put, %r{/singular_test_resource})
513
- end
514
-
515
- it "should always PUT" do
516
- ZendeskAPI::SingularTestResource.update(client, :test => :test)
517
- end
518
- end
519
- end
520
-
521
- context "Ticket#assignee" do
522
- subject { ZendeskAPI::Ticket.new(client, :id => 1, :assignee_id => nil) }
523
-
524
- it "should not try and make a request" do
525
- expect(subject.assignee).to be_nil
526
- end
527
- end
528
-
529
- context "#new" do
530
- it "builds with hash" do
531
- object = ZendeskAPI::TestResource.new(client, {})
532
- expect(object.attributes).to eq({})
533
- end
534
-
535
- it "fails to build with nil (e.g. empty response from server)" do
536
- expect{
537
- ZendeskAPI::TestResource.new(client, nil)
538
- }.to raise_error(/Expected a Hash/i)
539
- end
540
- end
541
- end