zendesk_api 0.3.14 → 0.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/.yardopts +6 -2
  2. data/Gemfile +3 -2
  3. data/Gemfile.lock +4 -4
  4. data/Readme.md +3 -268
  5. data/lib/zendesk_api/actions.rb +51 -46
  6. data/lib/zendesk_api/association.rb +1 -1
  7. data/lib/zendesk_api/associations.rb +2 -6
  8. data/lib/zendesk_api/client.rb +8 -9
  9. data/lib/zendesk_api/collection.rb +84 -50
  10. data/lib/zendesk_api/configuration.rb +4 -0
  11. data/lib/zendesk_api/error.rb +22 -0
  12. data/lib/zendesk_api/middleware/request/etag_cache.rb +1 -7
  13. data/lib/zendesk_api/middleware/request/upload.rb +1 -2
  14. data/lib/zendesk_api/middleware/response/raise_error.rb +20 -0
  15. data/lib/zendesk_api/resource.rb +33 -5
  16. data/lib/zendesk_api/resources.rb +36 -11
  17. data/lib/zendesk_api/server/base.rb +1 -1
  18. data/lib/zendesk_api/server/helper.rb +3 -3
  19. data/lib/zendesk_api/server/models/zlib_json.rb +1 -1
  20. data/lib/zendesk_api/server/public/doc/ZendeskAPI.html +7 -7
  21. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Ability.html +415 -13
  22. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Activity.html +414 -51
  23. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Attachment.html +321 -25
  24. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Automation.html +413 -46
  25. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Bookmark.html +389 -26
  26. data/lib/zendesk_api/server/public/doc/ZendeskAPI/CRMData.html +415 -13
  27. data/lib/zendesk_api/server/public/doc/ZendeskAPI/CRMDataStatus.html +415 -13
  28. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Category.html +410 -47
  29. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Client.html +98 -362
  30. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Collection.html +457 -676
  31. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Configuration.html +110 -20
  32. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Create.html +264 -6
  33. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Create/ClassMethods.html +43 -82
  34. data/lib/zendesk_api/server/public/doc/ZendeskAPI/CreateResource.html +671 -15
  35. data/lib/zendesk_api/server/public/doc/ZendeskAPI/CustomRole.html +415 -13
  36. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Data.html +207 -233
  37. data/lib/zendesk_api/server/public/doc/ZendeskAPI/DataResource.html +499 -24
  38. data/lib/zendesk_api/server/public/doc/ZendeskAPI/DeleteResource.html +614 -15
  39. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Destroy.html +73 -23
  40. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Destroy/ClassMethod.html +68 -18
  41. data/lib/zendesk_api/server/public/doc/ZendeskAPI/{FormatError.html → Error.html} +19 -27
  42. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Error/ClientError.html +127 -0
  43. data/lib/zendesk_api/server/public/doc/ZendeskAPI/{Server/UserRequest.html → Error/NetworkError.html} +18 -16
  44. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Error/RecordInvalid.html +371 -0
  45. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Error/RecordNotFound.html +127 -0
  46. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Forum.html +426 -63
  47. data/lib/zendesk_api/server/public/doc/ZendeskAPI/ForumSubscription.html +414 -51
  48. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Group.html +389 -26
  49. data/lib/zendesk_api/server/public/doc/ZendeskAPI/GroupMembership.html +414 -51
  50. data/lib/zendesk_api/server/public/doc/ZendeskAPI/JobStatus.html +405 -16
  51. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Locale.html +405 -16
  52. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Macro.html +413 -46
  53. data/lib/zendesk_api/server/public/doc/ZendeskAPI/MobileDevice.html +404 -41
  54. data/lib/zendesk_api/server/public/doc/ZendeskAPI/OAuthClient.html +606 -0
  55. data/lib/zendesk_api/server/public/doc/ZendeskAPI/OAuthToken.html +810 -0
  56. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Organization.html +422 -59
  57. data/lib/zendesk_api/server/public/doc/ZendeskAPI/OrganizationField.html +606 -0
  58. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Read.html +75 -12
  59. data/lib/zendesk_api/server/public/doc/ZendeskAPI/ReadResource.html +593 -16
  60. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Request.html +418 -55
  61. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Request/Comment.html +420 -31
  62. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Resource.html +1025 -20
  63. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Role.html +415 -13
  64. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Rule.html +610 -0
  65. data/lib/zendesk_api/server/public/doc/ZendeskAPI/RuleExecution.html +317 -21
  66. data/lib/zendesk_api/server/public/doc/ZendeskAPI/SatisfactionRating.html +428 -39
  67. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Save.html +63 -79
  68. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Search.html +34 -26
  69. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Search/Result.html +305 -9
  70. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Setting.html +433 -41
  71. data/lib/zendesk_api/server/public/doc/ZendeskAPI/SharingAgreement.html +405 -16
  72. data/lib/zendesk_api/server/public/doc/ZendeskAPI/SingularResource.html +389 -26
  73. data/lib/zendesk_api/server/public/doc/ZendeskAPI/SuspendedTicket.html +600 -31
  74. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Ticket.html +464 -101
  75. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Ticket/Audit.html +427 -25
  76. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Ticket/Comment.html +435 -32
  77. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Ticket/Tag.html +389 -26
  78. data/lib/zendesk_api/server/public/doc/ZendeskAPI/TicketField.html +389 -26
  79. data/lib/zendesk_api/server/public/doc/ZendeskAPI/TicketMetric.html +592 -15
  80. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Topic.html +427 -64
  81. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Topic/TopicComment.html +907 -17
  82. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Topic/TopicVote.html +414 -55
  83. data/lib/zendesk_api/server/public/doc/ZendeskAPI/TopicComment.html +325 -29
  84. data/lib/zendesk_api/server/public/doc/ZendeskAPI/TopicSubscription.html +414 -51
  85. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Trigger.html +413 -46
  86. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Update.html +258 -6
  87. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Update/ClassMethod.html +62 -12
  88. data/lib/zendesk_api/server/public/doc/ZendeskAPI/UpdateResource.html +671 -15
  89. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Upload.html +800 -28
  90. data/lib/zendesk_api/server/public/doc/ZendeskAPI/User.html +505 -142
  91. data/lib/zendesk_api/server/public/doc/ZendeskAPI/User/Identity.html +412 -49
  92. data/lib/zendesk_api/server/public/doc/ZendeskAPI/User/TopicComment.html +475 -13
  93. data/lib/zendesk_api/server/public/doc/ZendeskAPI/UserField.html +606 -0
  94. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Verbs.html +9 -15
  95. data/lib/zendesk_api/server/public/doc/ZendeskAPI/View.html +433 -66
  96. data/lib/zendesk_api/server/public/doc/ZendeskAPI/ViewCount.html +415 -13
  97. data/lib/zendesk_api/server/public/doc/ZendeskAPI/ViewRow.html +451 -49
  98. data/lib/zendesk_api/server/public/doc/_index.html +72 -72
  99. data/lib/zendesk_api/server/public/doc/class_list.html +1 -1
  100. data/lib/zendesk_api/server/public/doc/css/style.css +10 -0
  101. data/lib/zendesk_api/server/public/doc/file.Readme.html +20 -260
  102. data/lib/zendesk_api/server/public/doc/file_list.html +1 -1
  103. data/lib/zendesk_api/server/public/doc/frames.html +1 -1
  104. data/lib/zendesk_api/server/public/doc/index.html +20 -260
  105. data/lib/zendesk_api/server/public/doc/method_list.html +309 -517
  106. data/lib/zendesk_api/server/public/doc/top-level-namespace.html +3 -35
  107. data/lib/zendesk_api/verbs.rb +0 -4
  108. data/lib/zendesk_api/version.rb +1 -1
  109. data/spec/core/client_spec.rb +53 -13
  110. data/spec/core/collection_spec.rb +32 -4
  111. data/spec/core/create_resource_spec.rb +1 -1
  112. data/spec/core/data_resource_spec.rb +2 -2
  113. data/spec/core/middleware/request/etag_cache_spec.rb +6 -7
  114. data/spec/core/middleware/request/upload_spec.rb +2 -10
  115. data/spec/core/middleware/response/callback_spec.rb +1 -1
  116. data/spec/core/middleware/response/raise_error_spec.rb +40 -0
  117. data/spec/core/read_resource_spec.rb +0 -2
  118. data/spec/core/resource_spec.rb +13 -5
  119. data/spec/core/search_spec.rb +1 -1
  120. data/spec/core/spec_helper.rb +3 -3
  121. data/spec/live/automation_spec.rb +23 -0
  122. data/spec/live/organization_field_spec.rb +12 -0
  123. data/spec/live/ticket_spec.rb +8 -2
  124. data/spec/live/trigger_spec.rb +23 -0
  125. data/spec/live/user_field_spec.rb +12 -0
  126. data/spec/live/user_spec.rb +0 -2
  127. data/spec/live/view_spec.rb +17 -1
  128. data/spec/server/spec_helper.rb +2 -2
  129. data/zendesk_api.gemspec +1 -1
  130. metadata +88 -51
  131. checksums.yaml +0 -7
  132. data/lib/zendesk_api/rescue.rb +0 -63
  133. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Console.html +0 -860
  134. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Console/Eval.html +0 -190
  135. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server.html +0 -131
  136. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server/App.html +0 -523
  137. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server/Helper.html +0 -684
  138. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server/HtmlRenderer.html +0 -303
  139. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server/HtmlRenderer/RedcarpetRenderer.html +0 -508
  140. data/lib/zendesk_api/server/public/doc/ZendeskAPI/Server/ZlibJSON.html +0 -244
  141. data/spec/core/rescue_spec.rb +0 -151
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Documentation by YARD 0.8.4.1
9
+ &mdash; Documentation by YARD 0.8.5.2
10
10
 
11
11
  </title>
12
12
 
@@ -73,10 +73,6 @@
73
73
 
74
74
 
75
75
 
76
- <dt class="r1">Extended by:</dt>
77
- <dd class="r1"><span class='object_link'><a href="ZendeskAPI/Console.html" title="ZendeskAPI::Console (module)">ZendeskAPI::Console</a></span>, <span class='object_link'><a href="ZendeskAPI/Console/Eval.html" title="ZendeskAPI::Console::Eval (module)">ZendeskAPI::Console::Eval</a></span></dd>
78
-
79
-
80
76
 
81
77
 
82
78
 
@@ -98,46 +94,18 @@
98
94
 
99
95
 
100
96
 
101
- <h2>Constant Summary</h2>
102
-
103
- <h3 class="inherited">Constants included
104
- from <span class='object_link'><a href="ZendeskAPI/Console.html" title="ZendeskAPI::Console (module)">ZendeskAPI::Console</a></span></h3>
105
- <p class="inherited"><span class='object_link'><a href="ZendeskAPI/Console.html#ZD_DIRUP-constant" title="ZendeskAPI::Console::ZD_DIRUP (constant)">ZendeskAPI::Console::ZD_DIRUP</a></span></p>
106
-
107
-
108
-
109
97
 
110
98
 
111
99
 
112
-
113
-
114
-
115
-
116
-
117
-
118
- <h2>Method Summary</h2>
119
-
120
- <h3 class="inherited">Methods included from <span class='object_link'><a href="ZendeskAPI/Console/Eval.html" title="ZendeskAPI::Console::Eval (module)">ZendeskAPI::Console::Eval</a></span></h3>
121
- <p class="inherited"><span class='object_link'><a href="ZendeskAPI/Console/Eval.html#loop_eval-instance_method" title="ZendeskAPI::Console::Eval#loop_eval (method)">loop_eval</a></span></p>
122
100
 
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
- <h3 class="inherited">Methods included from <span class='object_link'><a href="ZendeskAPI/Console.html" title="ZendeskAPI::Console (module)">ZendeskAPI::Console</a></span></h3>
132
- <p class="inherited"><span class='object_link'><a href="ZendeskAPI/Console.html#basic_auth-instance_method" title="ZendeskAPI::Console#basic_auth (method)">basic_auth</a></span>, <span class='object_link'><a href="ZendeskAPI/Console.html#cd-instance_method" title="ZendeskAPI::Console#cd (method)">cd</a></span>, <span class='object_link'><a href="ZendeskAPI/Console.html#client-instance_method" title="ZendeskAPI::Console#client (method)">client</a></span>, <span class='object_link'><a href="ZendeskAPI/Console.html#config-instance_method" title="ZendeskAPI::Console#config (method)">config</a></span>, <span class='object_link'><a href="ZendeskAPI/Console.html#cwd-instance_method" title="ZendeskAPI::Console#cwd (method)">cwd</a></span>, <span class='object_link'><a href="ZendeskAPI/Console.html#help-instance_method" title="ZendeskAPI::Console#help (method)">help</a></span>, <span class='object_link'><a href="ZendeskAPI/Console.html#ls-instance_method" title="ZendeskAPI::Console#ls (method)">ls</a></span>, <span class='object_link'><a href="ZendeskAPI/Console.html#method_missing-instance_method" title="ZendeskAPI::Console#method_missing (method)">method_missing</a></span>, <span class='object_link'><a href="ZendeskAPI/Console.html#password-instance_method" title="ZendeskAPI::Console#password (method)">password</a></span>, <span class='object_link'><a href="ZendeskAPI/Console.html#url-instance_method" title="ZendeskAPI::Console#url (method)">url</a></span>, <span class='object_link'><a href="ZendeskAPI/Console.html#username-instance_method" title="ZendeskAPI::Console#username (method)">username</a></span></p>
133
101
 
134
102
 
135
103
  </div>
136
104
 
137
105
  <div id="footer">
138
- Generated on Mon Feb 11 17:45:36 2013 by
106
+ Generated on Wed May 15 18:59:28 2013 by
139
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
140
- 0.8.4.1 (ruby-1.9.3).
108
+ 0.8.5.2 (ruby-1.9.3).
141
109
  </div>
142
110
 
143
111
  </body>
@@ -1,8 +1,6 @@
1
1
  module ZendeskAPI
2
2
  # Creates put, post, delete class methods for custom resource methods.
3
3
  module Verbs
4
- include Rescue
5
-
6
4
  class << self
7
5
  private
8
6
 
@@ -30,8 +28,6 @@ module ZendeskAPI
30
28
 
31
29
  true
32
30
  end
33
-
34
- rescue_client_error method, :with => false
35
31
  end
36
32
  end
37
33
  end
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "0.3.14"
2
+ VERSION = "0.4.0.rc1"
3
3
  end
@@ -39,15 +39,55 @@ describe ZendeskAPI::Client do
39
39
  end
40
40
  end
41
41
 
42
+ context "basic_auth" do
43
+ subject do
44
+ ZendeskAPI::Client.new do |config|
45
+ config.url = "https://example.zendesk.com"
46
+ config.username = "hello"
47
+ config.password = "token"
48
+ end
49
+ end
50
+
51
+ it "should build basic auth middleware" do
52
+ subject.connection.builder.handlers.index(Faraday::Request::BasicAuthentication).should_not be_nil
53
+ end
54
+
55
+ it "should not build token middleware" do
56
+ subject.connection.headers["Authorization"].should be_nil
57
+ end
58
+ end
59
+
60
+ context "access token" do
61
+ subject do
62
+ ZendeskAPI::Client.new do |config|
63
+ config.url = "https://example.zendesk.com"
64
+ config.access_token = "hello"
65
+ end
66
+ end
67
+
68
+ it "should not build basic auth middleware" do
69
+ subject.connection.builder.handlers.index(Faraday::Request::BasicAuthentication).should be_nil
70
+ end
71
+
72
+ it "should build token middleware" do
73
+ subject.connection.headers["Authorization"].should match(/Bearer/)
74
+ end
75
+ end
76
+
42
77
  context "#token" do
43
- context "with a username with /token" do
44
- subject do
45
- ZendeskAPI::Client.new do |config|
46
- config.url = "https://example.zendesk.com"
47
- config.username = "hello/token"
48
- config.token = "token"
49
- end.config
78
+ let(:client) do
79
+ ZendeskAPI::Client.new do |config|
80
+ config.url = "https://example.zendesk.com"
81
+ config.username = username
82
+ config.token = "token"
50
83
  end
84
+ end
85
+
86
+ subject { client.config }
87
+ let(:username) { "hello" }
88
+
89
+ context "with a username with /token" do
90
+ let(:username) { "hello/token" }
51
91
 
52
92
  it "should not add /token to the username" do
53
93
  subject.username.should == "hello/token"
@@ -55,12 +95,12 @@ describe ZendeskAPI::Client do
55
95
  end
56
96
 
57
97
  context "with no password" do
58
- subject do
59
- ZendeskAPI::Client.new do |config|
60
- config.url = "https://example.zendesk.com"
61
- config.username = "hello"
62
- config.token = "token"
63
- end.config
98
+ it "should build basic auth middleware" do
99
+ client.connection.builder.handlers.index(Faraday::Request::BasicAuthentication).should_not be_nil
100
+ end
101
+
102
+ it "should not build token middleware" do
103
+ client.connection.builder.handlers.index(Faraday::Request::TokenAuthentication).should be_nil
64
104
  end
65
105
 
66
106
  it "should copy token to password" do
@@ -44,6 +44,20 @@ describe ZendeskAPI::Collection do
44
44
  subject.update(:id => 1)
45
45
  end
46
46
 
47
+ context "when class doesn't have method" do
48
+ subject do
49
+ ZendeskAPI::Collection.new(client, ZendeskAPI::NilDataResource)
50
+ end
51
+
52
+ it "should raise NoMethodError" do
53
+ expect { subject.create }.to raise_error(NoMethodError)
54
+ end
55
+
56
+ it "should raise NoMethodError" do
57
+ expect { subject.create! }.to raise_error(NoMethodError)
58
+ end
59
+ end
60
+
47
61
  context "with a class with a parent" do
48
62
  let(:association) do
49
63
  ZendeskAPI::Association.new(:class => ZendeskAPI::TestResource::TestChild,
@@ -165,7 +179,7 @@ describe ZendeskAPI::Collection do
165
179
  end
166
180
  end
167
181
 
168
- context "each_page" do
182
+ context "all" do
169
183
  context "Faraday errors" do
170
184
  before(:each) do
171
185
  stub_json_request(:get, %r{test_resources$}, json(
@@ -190,7 +204,7 @@ describe ZendeskAPI::Collection do
190
204
  end
191
205
 
192
206
  begin
193
- silence_logger { subject.each_page(&b) }
207
+ silence_logger { subject.all(&b) }
194
208
  rescue SearchError
195
209
  retry
196
210
  end
@@ -199,6 +213,20 @@ describe ZendeskAPI::Collection do
199
213
  [ZendeskAPI::TestResource.new(client, :id => 2), 2]
200
214
  )
201
215
  end
216
+
217
+ it "should retry from the same page!" do
218
+ expect do |b|
219
+ begin
220
+ subject.all!(&b)
221
+ rescue ZendeskAPI::Error::NetworkError
222
+ retry
223
+ rescue ZendeskAPI::Error::ClientError
224
+ end
225
+ end.to yield_successive_args(
226
+ [ZendeskAPI::TestResource.new(client, :id => 1), 1],
227
+ [ZendeskAPI::TestResource.new(client, :id => 2), 2]
228
+ )
229
+ end
202
230
  end
203
231
 
204
232
  context "successful requests" do
@@ -231,7 +259,7 @@ describe ZendeskAPI::Collection do
231
259
  end
232
260
  end
233
261
 
234
- silence_logger { subject.each_page(&block) }
262
+ silence_logger { subject.all(&block) }
235
263
  end.to yield_successive_args(
236
264
  ZendeskAPI::TestResource.new(client, :id => 1),
237
265
  ZendeskAPI::TestResource.new(client, :id => 2)
@@ -240,7 +268,7 @@ describe ZendeskAPI::Collection do
240
268
 
241
269
  it "should yield resource and page" do
242
270
  expect do |b|
243
- silence_logger { subject.each_page(&b) }
271
+ silence_logger { subject.all(&b) }
244
272
  end.to yield_successive_args(
245
273
  [ZendeskAPI::TestResource.new(client, :id => 1), 1],
246
274
  [ZendeskAPI::TestResource.new(client, :id => 2), 2]
@@ -28,7 +28,7 @@ describe ZendeskAPI::CreateResource do
28
28
  subject { ZendeskAPI::TestResource }
29
29
 
30
30
  before(:each) do
31
- subject.should_receive(:create).and_return(nil)
31
+ stub_request(:post, %r{test_resources}).to_return(:status => 500)
32
32
  end
33
33
 
34
34
  it "should raise if save fails" do
@@ -20,7 +20,7 @@ describe ZendeskAPI::DataResource do
20
20
  ZendeskAPI::TestResource.has :nil, options.merge(:class => ZendeskAPI::NilDataResource)
21
21
  end
22
22
 
23
- it "should try and find non-existant object" do
23
+ it "should try and find non-existent object" do
24
24
  stub_json_request(:get, %r{test_resources/1/nil}, json(:nil_data_resource => {}))
25
25
 
26
26
  subject.nil.should be_instance_of(ZendeskAPI::NilDataResource)
@@ -29,7 +29,7 @@ describe ZendeskAPI::DataResource do
29
29
  context "inline => true" do
30
30
  let(:options) {{ :inline => true }}
31
31
 
32
- it "should not try and find non-existant object" do
32
+ it "should not try and find non-existent object" do
33
33
  subject.nil
34
34
  end
35
35
  end
@@ -5,17 +5,16 @@ describe ZendeskAPI::Middleware::Request::EtagCache do
5
5
  client.config.cache.size = 1
6
6
 
7
7
  stub_json_request(:get, %r{blergh}, '{"x":1}', :headers => {"Etag" => "x"})
8
- first_response = client.connection.get("blergh")
9
- first_response.status.should == 200
10
- first_response.body.should == {"x"=>1}
8
+ response = client.connection.get("blergh")
9
+ response.status.should == 200
10
+ response.body.should == {"x"=>1}
11
+
12
+ headers = response.headers
11
13
 
12
14
  stub_request(:get, %r{blergh}).to_return(:status => 304, :headers => {"Etag" => "x"})
13
15
  response = client.connection.get("blergh")
14
16
  response.status.should == 304
15
17
  response.body.should == {"x"=>1}
16
-
17
- %w{content_encoding content_type content_length etag}.each do |header|
18
- response.headers[header].should == first_response.headers[header]
19
- end
18
+ response.headers.should == headers
20
19
  end
21
20
  end
@@ -10,7 +10,7 @@ describe ZendeskAPI::Middleware::Request::Upload do
10
10
  end
11
11
 
12
12
  it "should handle body with no file" do
13
- subject.call(:body => {})[:body].should == {}
13
+ subject.call(:body => {})[:body].should == {}
14
14
  end
15
15
 
16
16
  it "should handle invalid types" do
@@ -58,7 +58,7 @@ describe ZendeskAPI::Middleware::Request::Upload do
58
58
 
59
59
  context "with an ActionDispatch::Http::UploadedFile" do
60
60
  before(:each) do
61
- @upload = ActionDispatch::Http::UploadedFile.new(:filename => "hello.jpg", :tempfile => Tempfile.new(File.basename(filename)))
61
+ @upload = ActionDispatch::Http::UploadedFile.new(:filename => "hello", :tempfile => Tempfile.new(File.basename(filename)))
62
62
  @env = subject.call(:body => { :file => @upload })
63
63
  end
64
64
 
@@ -73,14 +73,6 @@ describe ZendeskAPI::Middleware::Request::Upload do
73
73
  it "should add filename if none exist" do
74
74
  @env[:body][:filename].should == "hello"
75
75
  end
76
-
77
- context "when path does not resolve a mime_type" do
78
- it "should use the content_type of ActionDispatch::Http::UploadedFile " do
79
- @upload.tempfile.path = "XXX"
80
- @env = subject.call(:body => { :file => @upload })
81
- @env[:body][:uploaded_data][:content_type].should == "image/jpeg"
82
- end
83
- end
84
76
  end
85
77
  end
86
78
 
@@ -8,7 +8,7 @@ describe ZendeskAPI::Middleware::Response::Callback do
8
8
  env[:body] = response
9
9
  end
10
10
 
11
- stub_request(:get, %r{test_endpoint}).to_return(:body => JSON.dump({ "ABC" => "DEF" }))
11
+ stub_request(:get, %r{test_endpoint}).to_return(:body => MultiJson.dump({ "ABC" => "DEF" }))
12
12
  end
13
13
 
14
14
  it "should call callbacks " do
@@ -0,0 +1,40 @@
1
+ require 'core/spec_helper'
2
+
3
+ describe ZendeskAPI::Middleware::Response::RaiseError do
4
+ before(:each) do
5
+ stub_request(:any, /.*/).to_return(:status => status)
6
+ end
7
+
8
+ context "with status = 404" do
9
+ let(:status) { 404 }
10
+
11
+ it "should raise RecordNotFound when status is 404" do
12
+ expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::RecordNotFound)
13
+ end
14
+ end
15
+
16
+ context "with status in 400...600" do
17
+ let(:status) { 500 }
18
+
19
+ it "should raise NetworkError" do
20
+ expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::NetworkError)
21
+ end
22
+ end
23
+
24
+ context "with status = 422" do
25
+ let(:status) { 422 }
26
+
27
+ it "should raise RecordInvalid" do
28
+ expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::RecordInvalid)
29
+ end
30
+ end
31
+
32
+ context "with status = 200" do
33
+ let(:status) { 200 }
34
+
35
+ it "should not raise" do
36
+ client.connection.get "/abcdef"
37
+ end
38
+ end
39
+ end
40
+
@@ -40,13 +40,11 @@ describe ZendeskAPI::ReadResource do
40
40
  context "with client error" do
41
41
  it "should handle 500 properly" do
42
42
  stub_request(:get, %r{test_resources/#{id}}).to_return(:status => 500)
43
- client.config.logger.should_receive(:warn).at_least(:once)
44
43
  subject.find(client, :id => id).should == nil
45
44
  end
46
45
 
47
46
  it "should handle 404 properly" do
48
47
  stub_request(:get, %r{test_resources/#{id}}).to_return(:status => 404)
49
- client.config.logger.should_receive(:warn).at_least(:once)
50
48
  subject.find(client, :id => id).should == nil
51
49
  end
52
50
  end
@@ -99,7 +99,7 @@ describe ZendeskAPI::Resource do
99
99
  subject { ZendeskAPI::TestResource.new(client, :id => 1) }
100
100
 
101
101
  before(:each) do
102
- subject.should_receive(:save).and_return(false)
102
+ stub_request(:put, %r{test_resources/1}).to_return(:status => 422)
103
103
  end
104
104
 
105
105
  it "should raise if save fails" do
@@ -341,8 +341,8 @@ describe ZendeskAPI::Resource do
341
341
  stub_request(verb.to_sym, %r{test_resources/1/#{method}}).to_return(:status => 500)
342
342
  end
343
343
 
344
- it "should return false" do
345
- expect { silence_logger{ subject.send(method).should be_false } }.to_not raise_error
344
+ it "should raise" do
345
+ expect { silence_logger{ subject.send(method) } }.to raise_error(ZendeskAPI::Error::ClientError)
346
346
  end
347
347
  end
348
348
  end
@@ -382,8 +382,16 @@ describe ZendeskAPI::Resource do
382
382
  ZendeskAPI::TestResource.new(client, :id => 2).should_not == ZendeskAPI::TestResource.new(client, :id => 1)
383
383
  end
384
384
 
385
- it "is different when class is different" do
386
- ZendeskAPI::TestResource.new(client, :id => 2).should_not == ZendeskAPI::TestResource::TestChild.new(client, :id => 2)
385
+ it "is same when class is Data" do
386
+ ZendeskAPI::TestResource.new(client, :id => 2).should == ZendeskAPI::TestResource::TestChild.new(client, :id => 2)
387
+ end
388
+
389
+ it "is same when class is Integer" do
390
+ ZendeskAPI::TestResource.new(client, :id => 2).should == 2
391
+ end
392
+
393
+ it "is different when class is Integer" do
394
+ ZendeskAPI::TestResource.new(client, :id => 2).should_not == 3
387
395
  end
388
396
 
389
397
  it "is different when other is no resource" do
@@ -8,7 +8,7 @@ describe ZendeskAPI::Search do
8
8
  end
9
9
  end
10
10
 
11
- context "when given a nonexistant class" do
11
+ context "when given a nonexistent class" do
12
12
  it "should return an object of the type Search::Result" do
13
13
  ZendeskAPI::Search.new(nil, { "result_type" => "blah" }).should be_instance_of(ZendeskAPI::Search::Result)
14
14
  end