contentful 2.16.0 → 2.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/lib/contentful/version.rb +1 -1
  4. metadata +3 -370
  5. data/.gitignore +0 -7
  6. data/.rspec +0 -1
  7. data/.rubocop.yml +0 -31
  8. data/.rubocop_todo.yml +0 -35
  9. data/.travis.yml +0 -15
  10. data/.yardopts +0 -4
  11. data/Gemfile +0 -9
  12. data/Guardfile +0 -24
  13. data/RELEASE.md +0 -8
  14. data/Rakefile +0 -33
  15. data/contentful.gemspec +0 -44
  16. data/examples/custom_classes.rb +0 -39
  17. data/examples/example_queries.rb +0 -26
  18. data/examples/raise_errors.rb +0 -20
  19. data/examples/raw_mode.rb +0 -14
  20. data/spec/array_spec.rb +0 -187
  21. data/spec/asset_spec.rb +0 -220
  22. data/spec/auto_includes_spec.rb +0 -12
  23. data/spec/client_class_spec.rb +0 -86
  24. data/spec/client_configuration_spec.rb +0 -394
  25. data/spec/content_type_spec.rb +0 -49
  26. data/spec/deleted_asset_spec.rb +0 -38
  27. data/spec/deleted_entry_spec.rb +0 -38
  28. data/spec/entry_spec.rb +0 -815
  29. data/spec/error_class_spec.rb +0 -327
  30. data/spec/error_requests_spec.rb +0 -87
  31. data/spec/field_spec.rb +0 -95
  32. data/spec/file_spec.rb +0 -33
  33. data/spec/fixtures/json_responses/400_details_errors_object.json +0 -14
  34. data/spec/fixtures/json_responses/400_details_errors_string.json +0 -12
  35. data/spec/fixtures/json_responses/400_details_string.json +0 -8
  36. data/spec/fixtures/json_responses/403_reasons.json +0 -13
  37. data/spec/fixtures/json_responses/404_details_string.json +0 -8
  38. data/spec/fixtures/json_responses/404_id.json +0 -11
  39. data/spec/fixtures/json_responses/404_sys_type.json +0 -12
  40. data/spec/fixtures/json_responses/404_type.json +0 -10
  41. data/spec/fixtures/json_responses/content_type.json +0 -83
  42. data/spec/fixtures/json_responses/default_400.json +0 -7
  43. data/spec/fixtures/json_responses/default_401.json +0 -7
  44. data/spec/fixtures/json_responses/default_403.json +0 -7
  45. data/spec/fixtures/json_responses/default_404.json +0 -7
  46. data/spec/fixtures/json_responses/default_429.json +0 -7
  47. data/spec/fixtures/json_responses/default_500.json +0 -7
  48. data/spec/fixtures/json_responses/default_502.json +0 -7
  49. data/spec/fixtures/json_responses/default_503.json +0 -7
  50. data/spec/fixtures/json_responses/includes.json +0 -111
  51. data/spec/fixtures/json_responses/link_array.json +0 -43
  52. data/spec/fixtures/json_responses/not_found.json +0 -13
  53. data/spec/fixtures/json_responses/nyancat.json +0 -48
  54. data/spec/fixtures/json_responses/other_error.json +0 -9
  55. data/spec/fixtures/json_responses/other_error_no_details.json +0 -8
  56. data/spec/fixtures/json_responses/other_error_no_message.json +0 -8
  57. data/spec/fixtures/json_responses/other_error_no_request_id.json +0 -8
  58. data/spec/fixtures/json_responses/other_error_nothing.json +0 -6
  59. data/spec/fixtures/json_responses/self_link.json +0 -82
  60. data/spec/fixtures/json_responses/unparsable.json +0 -13
  61. data/spec/fixtures/vcr_cassettes/array.yml +0 -288
  62. data/spec/fixtures/vcr_cassettes/array/marshal_custom_classes.yml +0 -159
  63. data/spec/fixtures/vcr_cassettes/array/marshal_unpublished.yml +0 -315
  64. data/spec/fixtures/vcr_cassettes/array/nested_resources.yml +0 -159
  65. data/spec/fixtures/vcr_cassettes/arrayField.yml +0 -87
  66. data/spec/fixtures/vcr_cassettes/array_page_1.yml +0 -106
  67. data/spec/fixtures/vcr_cassettes/array_page_2.yml +0 -73
  68. data/spec/fixtures/vcr_cassettes/asset.yml +0 -96
  69. data/spec/fixtures/vcr_cassettes/asset/select_empty_array.yml +0 -104
  70. data/spec/fixtures/vcr_cassettes/asset/select_no_sys.yml +0 -119
  71. data/spec/fixtures/vcr_cassettes/asset/select_one_field.yml +0 -97
  72. data/spec/fixtures/vcr_cassettes/asset/select_only_sys.yml +0 -88
  73. data/spec/fixtures/vcr_cassettes/asset/with_tags.yml +0 -138
  74. data/spec/fixtures/vcr_cassettes/assets/issues_129.yml +0 -90
  75. data/spec/fixtures/vcr_cassettes/assets/issues_jekyll_46.yml +0 -115
  76. data/spec/fixtures/vcr_cassettes/bad_request.yml +0 -76
  77. data/spec/fixtures/vcr_cassettes/content_type.yml +0 -147
  78. data/spec/fixtures/vcr_cassettes/entries.yml +0 -561
  79. data/spec/fixtures/vcr_cassettes/entries/empty_fields.yml +0 -246
  80. data/spec/fixtures/vcr_cassettes/entries/issue_117.yml +0 -201
  81. data/spec/fixtures/vcr_cassettes/entries/issue_125.yml +0 -198
  82. data/spec/fixtures/vcr_cassettes/entries/rich_text.yml +0 -1707
  83. data/spec/fixtures/vcr_cassettes/entries/rich_text_hydration_issue.yml +0 -460
  84. data/spec/fixtures/vcr_cassettes/entries/rich_text_nested_fields.yml +0 -653
  85. data/spec/fixtures/vcr_cassettes/entries/rich_text_unresolved_relationships.yml +0 -983
  86. data/spec/fixtures/vcr_cassettes/entries/unresolvable_assets.yml +0 -89
  87. data/spec/fixtures/vcr_cassettes/entries/unresolvable_filter.yml +0 -159
  88. data/spec/fixtures/vcr_cassettes/entries/unresolvable_filter_deeply_nested.yml +0 -167
  89. data/spec/fixtures/vcr_cassettes/entry.yml +0 -102
  90. data/spec/fixtures/vcr_cassettes/entry/custom_resource.yml +0 -168
  91. data/spec/fixtures/vcr_cassettes/entry/include_resolution.yml +0 -101
  92. data/spec/fixtures/vcr_cassettes/entry/include_resolution_uniques.yml +0 -81
  93. data/spec/fixtures/vcr_cassettes/entry/json_objects.yml +0 -88
  94. data/spec/fixtures/vcr_cassettes/entry/json_objects_client.yml +0 -86
  95. data/spec/fixtures/vcr_cassettes/entry/marshal_138.yml +0 -159
  96. data/spec/fixtures/vcr_cassettes/entry/marshal_unpublished.yml +0 -303
  97. data/spec/fixtures/vcr_cassettes/entry/marshall.yml +0 -293
  98. data/spec/fixtures/vcr_cassettes/entry/raw.yml +0 -201
  99. data/spec/fixtures/vcr_cassettes/entry/search_link_to_asset.yml +0 -81
  100. data/spec/fixtures/vcr_cassettes/entry/search_link_to_entry.yml +0 -81
  101. data/spec/fixtures/vcr_cassettes/entry/search_link_to_entry_with_custom_query.yml +0 -115
  102. data/spec/fixtures/vcr_cassettes/entry/select_empty_array.yml +0 -111
  103. data/spec/fixtures/vcr_cassettes/entry/select_no_sys.yml +0 -102
  104. data/spec/fixtures/vcr_cassettes/entry/select_one_field.yml +0 -76
  105. data/spec/fixtures/vcr_cassettes/entry/select_one_field_proper.yml +0 -114
  106. data/spec/fixtures/vcr_cassettes/entry/select_only_sys.yml +0 -111
  107. data/spec/fixtures/vcr_cassettes/entry/with_tags.yml +0 -238
  108. data/spec/fixtures/vcr_cassettes/entry_cache.yml +0 -288
  109. data/spec/fixtures/vcr_cassettes/entry_locales.yml +0 -104
  110. data/spec/fixtures/vcr_cassettes/field.yml +0 -147
  111. data/spec/fixtures/vcr_cassettes/human.yml +0 -118
  112. data/spec/fixtures/vcr_cassettes/linkField.yml +0 -83
  113. data/spec/fixtures/vcr_cassettes/locale.yml +0 -83
  114. data/spec/fixtures/vcr_cassettes/locale_from_environment.yml +0 -121
  115. data/spec/fixtures/vcr_cassettes/location.yml +0 -193
  116. data/spec/fixtures/vcr_cassettes/multi_locale_array_reference.yml +0 -196
  117. data/spec/fixtures/vcr_cassettes/multi_locale_reference.yml +0 -214
  118. data/spec/fixtures/vcr_cassettes/not_found.yml +0 -76
  119. data/spec/fixtures/vcr_cassettes/nyancat.yml +0 -102
  120. data/spec/fixtures/vcr_cassettes/query_array_1.yml +0 -89
  121. data/spec/fixtures/vcr_cassettes/query_array_2.yml +0 -89
  122. data/spec/fixtures/vcr_cassettes/ratelimit.yml +0 -64
  123. data/spec/fixtures/vcr_cassettes/ratelimit_retry.yml +0 -294
  124. data/spec/fixtures/vcr_cassettes/reloaded_entry.yml +0 -102
  125. data/spec/fixtures/vcr_cassettes/space.yml +0 -83
  126. data/spec/fixtures/vcr_cassettes/sync_deleted_asset.yml +0 -174
  127. data/spec/fixtures/vcr_cassettes/sync_deleted_entry.yml +0 -89
  128. data/spec/fixtures/vcr_cassettes/sync_deletion.yml +0 -191
  129. data/spec/fixtures/vcr_cassettes/sync_environment.yml +0 -81
  130. data/spec/fixtures/vcr_cassettes/sync_page.yml +0 -637
  131. data/spec/fixtures/vcr_cassettes/sync_page_2.yml +0 -71
  132. data/spec/fixtures/vcr_cassettes/sync_page_short.yml +0 -106
  133. data/spec/fixtures/vcr_cassettes/unauthorized.yml +0 -64
  134. data/spec/fixtures/vcr_cassettes/unavailable.yml +0 -76
  135. data/spec/link_spec.rb +0 -50
  136. data/spec/locale_spec.rb +0 -37
  137. data/spec/location_spec.rb +0 -25
  138. data/spec/request_spec.rb +0 -57
  139. data/spec/resource_building_spec.rb +0 -31
  140. data/spec/response_spec.rb +0 -62
  141. data/spec/space_spec.rb +0 -31
  142. data/spec/spec_helper.rb +0 -14
  143. data/spec/support/client.rb +0 -6
  144. data/spec/support/json_responses.rb +0 -18
  145. data/spec/support/vcr.rb +0 -16
  146. data/spec/sync_page_spec.rb +0 -103
  147. data/spec/sync_spec.rb +0 -180
@@ -1,327 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Contentful::Error do
4
- let(:r) { Contentful::Response.new raw_fixture('not_found', 404) }
5
-
6
- describe '#response' do
7
- it 'returns the response the error has been initialized with' do
8
- expect(Contentful::Error.new(r).response).to be r
9
- end
10
- end
11
-
12
- describe '#message' do
13
- it 'returns the message found in the response json' do
14
- message = "HTTP status code: 404\n"\
15
- "Message: The resource could not be found.\n"\
16
- "Details: {\"type\"=>\"Entry\", \"space\"=>\"cfexampleapi\", \"id\"=>\"not found\"}\n"\
17
- "Request ID: 85f-351076632"
18
- expect(Contentful::Error.new(r).message).not_to be_nil
19
- expect(Contentful::Error.new(r).message).to eq message
20
- end
21
-
22
- describe 'message types' do
23
- describe 'default messages' do
24
- it '400' do
25
- response = Contentful::Response.new raw_fixture('default_400', 400)
26
- error = Contentful::Error[response.raw.status].new(response)
27
-
28
- message = "HTTP status code: 400\n"\
29
- "Message: The request was malformed or missing a required parameter.\n"\
30
- "Request ID: 85f-351076632"
31
- expect(error.message).to eq message
32
- end
33
-
34
- it '401' do
35
- response = Contentful::Response.new raw_fixture('default_401', 401)
36
- error = Contentful::Error[response.raw.status].new(response)
37
-
38
- message = "HTTP status code: 401\n"\
39
- "Message: The authorization token was invalid.\n"\
40
- "Request ID: 85f-351076632"
41
- expect(error.message).to eq message
42
- end
43
-
44
- it '403' do
45
- response = Contentful::Response.new raw_fixture('default_403', 403)
46
- error = Contentful::Error[response.raw.status].new(response)
47
-
48
- message = "HTTP status code: 403\n"\
49
- "Message: The specified token does not have access to the requested resource.\n"\
50
- "Request ID: 85f-351076632"
51
- expect(error.message).to eq message
52
- end
53
-
54
- it '404' do
55
- response = Contentful::Response.new raw_fixture('default_404', 404)
56
- error = Contentful::Error[response.raw.status].new(response)
57
-
58
- message = "HTTP status code: 404\n"\
59
- "Message: The requested resource or endpoint could not be found.\n"\
60
- "Request ID: 85f-351076632"
61
- expect(error.message).to eq message
62
- end
63
-
64
- it '429' do
65
- response = Contentful::Response.new raw_fixture('default_429', 429)
66
- error = Contentful::Error[response.raw.status].new(response)
67
-
68
- message = "HTTP status code: 429\n"\
69
- "Message: Rate limit exceeded. Too many requests.\n"\
70
- "Request ID: 85f-351076632"
71
- expect(error.message).to eq message
72
- end
73
-
74
- it '500' do
75
- response = Contentful::Response.new raw_fixture('default_500', 500)
76
- error = Contentful::Error[response.raw.status].new(response)
77
-
78
- message = "HTTP status code: 500\n"\
79
- "Message: Internal server error.\n"\
80
- "Request ID: 85f-351076632"
81
- expect(error.message).to eq message
82
- end
83
-
84
- it '502' do
85
- response = Contentful::Response.new raw_fixture('default_502', 502)
86
- error = Contentful::Error[response.raw.status].new(response)
87
-
88
- message = "HTTP status code: 502\n"\
89
- "Message: The requested space is hibernated.\n"\
90
- "Request ID: 85f-351076632"
91
- expect(error.message).to eq message
92
- end
93
-
94
- it '503' do
95
- response = Contentful::Response.new raw_fixture('default_503', 503)
96
- error = Contentful::Error[response.raw.status].new(response)
97
-
98
- message = "HTTP status code: 503\n"\
99
- "Message: The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.\n"\
100
- "Request ID: 85f-351076632"
101
- expect(error.message).to eq message
102
- end
103
- end
104
-
105
- describe 'special cases' do
106
- describe '400' do
107
- it 'details is a string' do
108
- response = Contentful::Response.new raw_fixture('400_details_string', 400)
109
- error = Contentful::Error[response.raw.status].new(response)
110
-
111
- message = "HTTP status code: 400\n"\
112
- "Message: The request was malformed or missing a required parameter.\n"\
113
- "Details: some error\n"\
114
- "Request ID: 85f-351076632"
115
- expect(error.message).to eq message
116
- end
117
-
118
- it 'details is an object, internal errors are strings' do
119
- response = Contentful::Response.new raw_fixture('400_details_errors_string', 400)
120
- error = Contentful::Error[response.raw.status].new(response)
121
-
122
- message = "HTTP status code: 400\n"\
123
- "Message: The request was malformed or missing a required parameter.\n"\
124
- "Details: some error\n"\
125
- "Request ID: 85f-351076632"
126
- expect(error.message).to eq message
127
- end
128
-
129
- it 'details is an object, internal errors are objects which have details' do
130
- response = Contentful::Response.new raw_fixture('400_details_errors_object', 400)
131
- error = Contentful::Error[response.raw.status].new(response)
132
-
133
- message = "HTTP status code: 400\n"\
134
- "Message: The request was malformed or missing a required parameter.\n"\
135
- "Details: some error\n"\
136
- "Request ID: 85f-351076632"
137
- expect(error.message).to eq message
138
- end
139
- end
140
-
141
- describe '403' do
142
- it 'has an array of reasons' do
143
- response = Contentful::Response.new raw_fixture('403_reasons', 403)
144
- error = Contentful::Error[response.raw.status].new(response)
145
-
146
- message = "HTTP status code: 403\n"\
147
- "Message: The specified token does not have access to the requested resource.\n"\
148
- "Details: \n\tReasons:\n"\
149
- "\t\tfoo\n"\
150
- "\t\tbar\n"\
151
- "Request ID: 85f-351076632"
152
- expect(error.message).to eq message
153
- end
154
- end
155
-
156
- describe '404' do
157
- it 'details is a string' do
158
- response = Contentful::Response.new raw_fixture('404_details_string', 404)
159
- error = Contentful::Error[response.raw.status].new(response)
160
-
161
- message = "HTTP status code: 404\n"\
162
- "Message: The requested resource or endpoint could not be found.\n"\
163
- "Details: The resource could not be found\n"\
164
- "Request ID: 85f-351076632"
165
- expect(error.message).to eq message
166
- end
167
-
168
- describe 'has a type' do
169
- it 'type is on the top level' do
170
- response = Contentful::Response.new raw_fixture('404_type', 404)
171
- error = Contentful::Error[response.raw.status].new(response)
172
-
173
- message = "HTTP status code: 404\n"\
174
- "Message: The requested resource or endpoint could not be found.\n"\
175
- "Details: The requested Asset could not be found.\n"\
176
- "Request ID: 85f-351076632"
177
- expect(error.message).to eq message
178
- end
179
-
180
- it 'type is not on the top level' do
181
- response = Contentful::Response.new raw_fixture('404_sys_type', 404)
182
- error = Contentful::Error[response.raw.status].new(response)
183
-
184
- message = "HTTP status code: 404\n"\
185
- "Message: The requested resource or endpoint could not be found.\n"\
186
- "Details: The requested Space could not be found.\n"\
187
- "Request ID: 85f-351076632"
188
- expect(error.message).to eq message
189
- end
190
- end
191
-
192
- it 'can specify the resource id' do
193
- response = Contentful::Response.new raw_fixture('404_id', 404)
194
- error = Contentful::Error[response.raw.status].new(response)
195
-
196
- message = "HTTP status code: 404\n"\
197
- "Message: The requested resource or endpoint could not be found.\n"\
198
- "Details: The requested Asset could not be found. ID: foobar.\n"\
199
- "Request ID: 85f-351076632"
200
- expect(error.message).to eq message
201
- end
202
- end
203
-
204
- describe '429' do
205
- it 'can show the time until reset' do
206
- response = Contentful::Response.new raw_fixture('default_429', 429, false, {'x-contentful-ratelimit-reset' => 60})
207
- error = Contentful::Error[response.raw.status].new(response)
208
-
209
- message = "HTTP status code: 429\n"\
210
- "Message: Rate limit exceeded. Too many requests.\n"\
211
- "Request ID: 85f-351076632\n"\
212
- "Time until reset (seconds): 60"
213
- expect(error.message).to eq message
214
- end
215
- end
216
- end
217
-
218
- describe 'generic error' do
219
- it 'with everything' do
220
- response = Contentful::Response.new raw_fixture('other_error', 512)
221
- error = Contentful::Error[response.raw.status].new(response)
222
-
223
- message = "HTTP status code: 512\n"\
224
- "Message: Some error occurred.\n"\
225
- "Details: some text\n"\
226
- "Request ID: 85f-351076632"
227
- expect(error.message).to eq message
228
- end
229
-
230
- it 'no details' do
231
- response = Contentful::Response.new raw_fixture('other_error_no_details', 512)
232
- error = Contentful::Error[response.raw.status].new(response)
233
-
234
- message = "HTTP status code: 512\n"\
235
- "Message: Some error occurred.\n"\
236
- "Request ID: 85f-351076632"
237
- expect(error.message).to eq message
238
- end
239
-
240
- it 'no request id' do
241
- response = Contentful::Response.new raw_fixture('other_error_no_request_id', 512)
242
- error = Contentful::Error[response.raw.status].new(response)
243
-
244
- message = "HTTP status code: 512\n"\
245
- "Message: Some error occurred.\n"\
246
- "Details: some text"
247
- expect(error.message).to eq message
248
- end
249
-
250
- it 'no message' do
251
- response = Contentful::Response.new raw_fixture('other_error_no_message', 512)
252
- error = Contentful::Error[response.raw.status].new(response)
253
-
254
- message = "HTTP status code: 512\n"\
255
- "Message: The following error was received: {\n"\
256
- " \"sys\": {\n"\
257
- " \"type\": \"Error\",\n"\
258
- " \"id\": \"SomeError\"\n"\
259
- " },\n"\
260
- " \"details\": \"some text\",\n"\
261
- " \"requestId\": \"85f-351076632\"\n"\
262
- "}\n"\
263
- "\n"\
264
- "Details: some text\n"\
265
- "Request ID: 85f-351076632"
266
- expect(error.message).to eq message
267
- end
268
-
269
- it 'nothing' do
270
- response = Contentful::Response.new raw_fixture('other_error_nothing', 512)
271
- error = Contentful::Error[response.raw.status].new(response)
272
-
273
- message = "HTTP status code: 512\n"\
274
- "Message: The following error was received: {\n"\
275
- " \"sys\": {\n"\
276
- " \"type\": \"Error\",\n"\
277
- " \"id\": \"SomeError\"\n"\
278
- " }\n"\
279
- "}\n"
280
- expect(error.message).to eq message
281
- end
282
- end
283
- end
284
- end
285
-
286
- describe Contentful::UnparsableJson do
287
- describe '#message' do
288
- it 'returns the json parser\'s message' do
289
- uj = Contentful::Response.new raw_fixture('unparsable')
290
- expect(Contentful::UnparsableJson.new(uj).message).to \
291
- include 'unexpected token'
292
- end
293
- end
294
- end
295
-
296
- describe '.[]' do
297
- it 'returns BadRequest error class for 400' do
298
- expect(Contentful::Error[400]).to eq Contentful::BadRequest
299
- end
300
-
301
- it 'returns Unauthorized error class for 401' do
302
- expect(Contentful::Error[401]).to eq Contentful::Unauthorized
303
- end
304
-
305
- it 'returns AccessDenied error class for 403' do
306
- expect(Contentful::Error[403]).to eq Contentful::AccessDenied
307
- end
308
-
309
- it 'returns NotFound error class for 404' do
310
- expect(Contentful::Error[404]).to eq Contentful::NotFound
311
- end
312
-
313
- it 'returns ServerError error class for 500' do
314
- expect(Contentful::Error[500]).to eq Contentful::ServerError
315
- end
316
-
317
- it 'returns ServiceUnavailable error class for 503' do
318
- expect(Contentful::Error[503]).to eq Contentful::ServiceUnavailable
319
- end
320
-
321
- it 'returns generic error class for any other value' do
322
- expect(Contentful::Error[nil]).to eq Contentful::Error
323
- expect(Contentful::Error[200]).to eq Contentful::Error
324
- end
325
- end
326
-
327
- end
@@ -1,87 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class NonCachingClient < Contentful::Client
4
- def request_headers
5
- headers = super
6
- headers['Cf-No-Cache'] = 'foobar'
7
- headers
8
- end
9
- end
10
-
11
- class RetryLoggerMock < Logger
12
- attr_reader :retry_attempts
13
-
14
- def initialize(*)
15
- super
16
- @retry_attempts = 0
17
- end
18
-
19
- def info(message)
20
- super
21
- @retry_attempts += 1 if message.include?('Contentful API Rate Limit Hit! Retrying')
22
- end
23
- end
24
-
25
- describe 'Error Requests' do
26
- it 'will return 404 (Unauthorized) if resource not found' do
27
- expect_vcr('not found')do
28
- create_client.content_type 'not found'
29
- end.to raise_error(Contentful::NotFound)
30
- end
31
-
32
- it 'will return 400 (BadRequest) if invalid parameters have been passed' do
33
- expect_vcr('bad request')do
34
- create_client.entries(some: 'parameter')
35
- end.to raise_error(Contentful::BadRequest)
36
- end
37
-
38
- it 'will return 403 (AccessDenied) if ...' do
39
- skip
40
- end
41
-
42
- it 'will return 401 (Unauthorized) if wrong credentials are given' do
43
- client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')
44
-
45
- expect_vcr('unauthorized'){
46
- client.entry('nyancat')
47
- }.to raise_error(Contentful::Unauthorized)
48
- end
49
-
50
- it 'will return 500 (ServerError) if ...' do
51
- skip
52
- end
53
-
54
- it 'will return a 429 if the ratelimit is reached and is not set to retry' do
55
- client = Contentful::Client.new(space: 'wrong', access_token: 'credentials', max_rate_limit_retries: 0)
56
- expect_vcr('ratelimit') {
57
- client.entry('nyancat')
58
- }.to raise_error(Contentful::RateLimitExceeded)
59
- end
60
-
61
- it 'will retry on 429 by default' do
62
- logger = RetryLoggerMock.new(STDOUT)
63
- client = NonCachingClient.new(
64
- api_url: 'cdnorigin.flinkly.com',
65
- space: '164vhtp008kz',
66
- access_token: '7699b6c6f6cee9b6abaa216c71fbcb3eee56cb6f082f57b5e21b2b50f86bdea0',
67
- raise_errors: true,
68
- logger: logger
69
- )
70
-
71
- vcr('ratelimit_retry') {
72
- 3.times {
73
- client.assets
74
- }
75
- }
76
-
77
- expect(logger.retry_attempts).to eq 1
78
- end
79
-
80
- it 'will return 503 (ServiceUnavailable) when the service is unavailable' do
81
- client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')
82
-
83
- expect_vcr('unavailable'){
84
- client.entry('nyancat')
85
- }.to raise_error(Contentful::ServiceUnavailable)
86
- end
87
- end
data/spec/field_spec.rb DELETED
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Contentful::Field do
4
- let(:field) { vcr('field') { create_client.content_type('cat').fields.first } }
5
- let(:linkField) { vcr('linkField') {
6
- create_client.content_type('cat').fields.select { |f| f.id == 'image' }.first
7
- } }
8
- let(:arrayField) { vcr('arrayField') {
9
- Contentful::Client.new(
10
- space: 'wl1z0pal05vy',
11
- access_token: '9b76e1bbc29eb513611a66b9fc5fb7acd8d95e83b0f7d6bacfe7ec926c819806'
12
- ).content_type('2PqfXUJwE8qSYKuM0U6w8M').fields.select { |f| f.id == 'categories' }.first
13
- } }
14
-
15
- describe 'Properties' do
16
- it 'has #id' do
17
- expect(field.id).to eq 'name'
18
- end
19
-
20
- it 'has #name' do
21
- expect(field.name).to eq 'Name'
22
- end
23
-
24
- it 'has #type' do
25
- expect(field.type).to eq 'Text'
26
- end
27
-
28
- it 'could have #items' do
29
- expect(field).to respond_to :items
30
- end
31
-
32
- it 'has #required' do
33
- expect(field.required).to be_truthy
34
- end
35
-
36
- it 'has #localized' do
37
- expect(field.required).to be_truthy
38
- end
39
- end
40
-
41
- describe 'Link field properties' do
42
- it 'has #type' do
43
- expect(linkField.type).to eq 'Link'
44
- end
45
-
46
- it 'has #linkType' do
47
- expect(linkField.link_type).to eq 'Asset'
48
- end
49
- end
50
-
51
- describe 'Array field properties' do
52
- it 'has #type' do
53
- expect(arrayField.type).to eq 'Array'
54
- end
55
-
56
- it 'has #items' do
57
- expect(arrayField.items.type).to eq 'Link'
58
- expect(arrayField.items.link_type).to eq 'Entry'
59
- end
60
- end
61
-
62
- describe 'issues' do
63
- describe 'json field' do
64
- it 'can coerce properly when top level is not object' do
65
- coercion = Contentful::ObjectCoercion.new([{foo: 123}])
66
- expect(coercion.coerce).to eq [{foo: 123}]
67
-
68
- coercion = Contentful::ObjectCoercion.new('foobar')
69
- expect(coercion.coerce).to eq 'foobar'
70
-
71
- coercion = Contentful::ObjectCoercion.new(true)
72
- expect(coercion.coerce).to eq true
73
-
74
- coercion = Contentful::ObjectCoercion.new(123)
75
- expect(coercion.coerce).to eq 123
76
-
77
- coercion = Contentful::ObjectCoercion.new({foo: 123})
78
- expect(coercion.coerce).to eq(foo: 123)
79
- end
80
- end
81
-
82
- describe 'datetime field' do
83
- it 'can coerce properly when value is nil' do
84
- coercion = Contentful::DateCoercion.new(nil)
85
- expect(coercion.coerce).to eq(nil)
86
- end
87
-
88
- it 'can coerce properly when value is already datetime' do
89
- value = DateTime.new
90
- coercion = Contentful::DateCoercion.new(value)
91
- expect(coercion.coerce).to eq value
92
- end
93
- end
94
- end
95
- end