osc_ruby 0.7.1 → 1.0.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +25 -25
  3. data/.gitignore +15 -15
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +1156 -1156
  6. data/.travis.yml +9 -9
  7. data/Gemfile +3 -3
  8. data/License.txt +21 -0
  9. data/README.md +95 -242
  10. data/Rakefile +2 -2
  11. data/lib/ext/string.rb +18 -18
  12. data/lib/osc_ruby/classes/query_results.rb +40 -60
  13. data/lib/osc_ruby/client.rb +40 -40
  14. data/lib/osc_ruby/configuration.rb +14 -13
  15. data/lib/osc_ruby/connect.rb +218 -209
  16. data/lib/osc_ruby/modules/normalize_module.rb +121 -121
  17. data/lib/osc_ruby/modules/query_module.rb +69 -69
  18. data/lib/osc_ruby/modules/validations_module.rb +168 -168
  19. data/lib/osc_ruby/version.rb +2 -2
  20. data/lib/osc_ruby.rb +4 -10
  21. data/osc_ruby.gemspec +28 -29
  22. data/spec/core/client_spec.rb +96 -96
  23. data/spec/core/configuration_spec.rb +4 -4
  24. data/spec/core/connect_spec.rb +366 -364
  25. data/spec/core/query_results_spec.rb +107 -133
  26. data/spec/core/spec_helper.rb +25 -25
  27. data/tasks/rspec.rake +2 -2
  28. metadata +23 -22
  29. data/LICENSE.txt +0 -22
  30. data/lib/osc_ruby/classes/account.rb +0 -75
  31. data/lib/osc_ruby/classes/answer.rb +0 -117
  32. data/lib/osc_ruby/classes/incident.rb +0 -13
  33. data/lib/osc_ruby/classes/product_category_shared.rb +0 -118
  34. data/lib/osc_ruby/classes/service_category.rb +0 -6
  35. data/lib/osc_ruby/classes/service_class.rb +0 -66
  36. data/lib/osc_ruby/classes/service_product.rb +0 -6
  37. data/lib/osc_ruby/modules/class_factory_module.rb +0 -165
  38. data/lib/osc_ruby/modules/nested_resource_module.rb +0 -10
  39. data/spec/core/account_spec.rb +0 -497
  40. data/spec/core/answer_spec.rb +0 -545
  41. data/spec/core/service_category_spec.rb +0 -445
  42. data/spec/core/service_product_spec.rb +0 -443
@@ -1,445 +0,0 @@
1
- require 'core/spec_helper'
2
- require 'json'
3
- require 'uri'
4
-
5
- describe OSCRuby::ServiceCategory do
6
-
7
- let(:service_category){
8
-
9
- OSCRuby::ServiceCategory.new
10
-
11
- }
12
-
13
- context '#initialize' do
14
-
15
- it 'should not throw an error when initialized' do
16
-
17
- expect{service_category}.not_to raise_error
18
-
19
- end
20
-
21
- it 'should initialize with names being an array; parent is an empty hash;
22
- displayOrder is 1; adminVisibleInterfaces is an empty array; and endUserVisibleInterfaces is an empty array' do
23
-
24
- expect(service_category.names).to eq([])
25
-
26
- expect(service_category.parent).to eq({})
27
-
28
- expect(service_category.displayOrder).to eq(1)
29
-
30
- expect(service_category.adminVisibleInterfaces).to eq([])
31
-
32
- expect(service_category.endUserVisibleInterfaces).to eq([])
33
-
34
- end
35
-
36
- end
37
-
38
- # let(:attributes){
39
- # {'id' => 1,
40
- # 'lookupName' => 'Test category Lookup Name',
41
- # 'createdTime'=>nil,
42
- # 'updatedTime'=>nil,
43
- # 'displayOrder'=>1,
44
- # 'name'=>'Test Product Lookup Name',
45
- # 'parent' => nil
46
- # }
47
- # }
48
-
49
- # context '#new_from_fetch' do
50
-
51
- # it 'should accept an attributes as a hash' do
52
-
53
- # expect do
54
-
55
- # attributes = []
56
-
57
- # OSCRuby::ServiceCategory.new_from_fetch(attributes)
58
-
59
- # end.to raise_error("Attributes must be a hash; please use the appropriate data structure")
60
-
61
- # expect do
62
-
63
- # OSCRuby::ServiceCategory.new_from_fetch(attributes)
64
-
65
- # end.not_to raise_error
66
-
67
- # end
68
-
69
- # it 'should instantiate an id, lookupName, createdTime, updatedTime, displayOrder, name, and parent with the correct values' do
70
-
71
- # test = OSCRuby::ServiceCategory.new_from_fetch(attributes)
72
-
73
- # expect(test.id).to eq(1)
74
-
75
- # expect(test.lookupName).to eq('Test Product Lookup Name')
76
-
77
- # expect(test.createdTime).to eq(nil)
78
-
79
- # expect(test.updatedTime).to eq(nil)
80
-
81
- # expect(test.displayOrder).to eq(1)
82
-
83
- # expect(test.name).to eq('Test Product Lookup Name')
84
-
85
- # expect(test.name).to eq(test.lookupName)
86
-
87
- # expect(test.parent).to eq(nil)
88
-
89
- # end
90
-
91
- # end
92
-
93
- let(:client) {
94
-
95
- OSCRuby::Client.new do |config|
96
-
97
- config.interface = ENV['OSC_TEST1_SITE']
98
-
99
- config.username = ENV['OSC_ADMIN']
100
-
101
- config.password = ENV['OSC_PASSWORD']
102
-
103
- end
104
- }
105
-
106
- let(:new_service_category){
107
- OSCRuby::ServiceCategory.new
108
- }
109
-
110
- context '#create' do
111
-
112
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
113
-
114
- expect(client).to be_an(OSCRuby::Client)
115
-
116
- client = nil
117
-
118
- expect{new_service_category.create(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
119
-
120
- end
121
-
122
- it 'should check the object and make sure that it at least has a name set' do
123
-
124
- expect{new_service_category.create(client)}.to raise_error('ServiceCategory should at least have one name set')
125
-
126
- end
127
-
128
- it 'should expect the name in a hash as the value of the labelText key' do
129
-
130
- new_service_category.names[0] = "new category name"
131
-
132
- expect{new_service_category.create(client)}.to raise_error('ServiceCategory should at least have one name set')
133
-
134
- end
135
-
136
- it 'should expect a language => id key pair within the hash' do
137
-
138
- new_service_category.names[0] = {"labelText" => "New Category"}
139
-
140
- expect{new_service_category.create(client)}.to raise_error('ServiceCategory should at least have one name set')
141
-
142
- end
143
-
144
- it 'should return an instance of an OSCRuby::ServiceCategory if the json_response param is set to false (which it is by default)', :vcr do
145
-
146
- new_service_category.names[0] = {"labelText" => "TEST-CATEGORY", "language" => {"id" => 1}}
147
- new_service_category.names[1] = {"labelText" => "TEST-CATEGORY", "language" => {"id" => 11}}
148
-
149
- new_service_category.parent = {'id' => 6}
150
-
151
- new_service_category.displayOrder = 1
152
-
153
- new_service_category.create(client)
154
-
155
- expect(new_service_category).to be_a(OSCRuby::ServiceCategory)
156
-
157
- expect(new_service_category.name).to eq("TEST-CATEGORY")
158
-
159
- expect(new_service_category.lookupName).to eq("TEST-CATEGORY")
160
-
161
- expect(new_service_category.displayOrder).to eq(1)
162
-
163
- expect(new_service_category.id).to_not eq(nil)
164
-
165
- end
166
-
167
-
168
- it 'should print the body object if the json_response param is set to true', :vcr do
169
-
170
- new_service_category.displayOrder = 11
171
-
172
- new_service_category.parent = {'id' => 6}
173
-
174
- new_service_category.names[0] = {"labelText" => "TEST-CATEGORY", "language" => {"id" => 1}}
175
- new_service_category.names[1] = {'labelText' => 'TEST-CATEGORY', 'language' => {'id' => 11}}
176
-
177
- new_service_category.create(client,true)
178
-
179
- expect(new_service_category).to be_a(OSCRuby::ServiceCategory)
180
-
181
- end
182
-
183
- end
184
-
185
- context '#find' do
186
-
187
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
188
-
189
- expect(client).to be_an(OSCRuby::Client)
190
-
191
- client = nil
192
-
193
- expect{OSCRuby::ServiceCategory.find(client,6)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
194
-
195
- end
196
-
197
- it 'should raise an error if ID is undefined' do
198
-
199
- expect{OSCRuby::ServiceCategory.find(client)}.to raise_error('ID cannot be nil')
200
-
201
- end
202
-
203
- it 'should raise an error if ID is not an integer' do
204
-
205
- expect{OSCRuby::ServiceCategory.find(client, 'a')}.to raise_error('ID must be an integer')
206
-
207
- end
208
-
209
- it 'should return a warning if empty/no instances of the object can be found', :vcr do
210
-
211
- expect{OSCRuby::ServiceCategory.find(client, 1)}.to raise_error('There were no objects matching your query; please try again.')
212
-
213
- end
214
-
215
-
216
- it 'should return an instance of a new OSCRuby::ServiceCategory object with at least a name and displayOrder', :vcr do
217
-
218
- known_working_category = OSCRuby::ServiceCategory.find(client, 6)
219
-
220
- expect(known_working_category).to be_an(OSCRuby::ServiceCategory)
221
-
222
- expect(known_working_category.name).to eq('Manuals and Guides')
223
-
224
- expect(known_working_category.displayOrder).to eq(1)
225
-
226
- end
227
-
228
- it 'should return the raw json response if the return_json parameter is set to true', :vcr do
229
-
230
- known_working_category_in_json = OSCRuby::ServiceCategory.find(client, 6, true)
231
-
232
- expect(known_working_category_in_json).to be_an(String)
233
-
234
- end
235
-
236
- end
237
-
238
- context '#all' do
239
-
240
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
241
-
242
- expect(client).to be_an(OSCRuby::Client)
243
-
244
- client = nil
245
-
246
- expect{OSCRuby::ServiceCategory.all(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
247
-
248
- end
249
-
250
- it 'should return multiple instances of OSCRuby::ServiceCategory', :vcr do
251
-
252
- categories = OSCRuby::ServiceCategory.all(client)
253
-
254
- expect(categories.size).to be > 0
255
-
256
- # puts "Checking if OSCRuby::ServiceCategory.all produces multiple instances of categories"
257
-
258
- categories.each_with_index do |p,i|
259
-
260
- if i < 10
261
-
262
- expect(p).to be_an(OSCRuby::ServiceCategory)
263
-
264
- # puts p.name
265
-
266
- end
267
-
268
- end
269
-
270
- end
271
-
272
- it 'should just return JSON if the return_json parameter is set to true', :vcr do
273
-
274
- expect(OSCRuby::ServiceCategory.all(client,true)).to be_a(String)
275
-
276
- end
277
-
278
- end
279
-
280
- context '#where' do
281
-
282
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
283
-
284
- expect(client).to be_an(OSCRuby::Client)
285
-
286
- client = nil
287
-
288
- expect{OSCRuby::ServiceCategory.where(client,'query')}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
289
-
290
- end
291
-
292
- it 'should raise an error if there is no query' do
293
-
294
- expect{OSCRuby::ServiceCategory.where(client)}.to raise_error("A query must be specified when using the 'where' method")
295
-
296
- end
297
-
298
- it 'should take a query and return results', :vcr do
299
-
300
- categories_lvl_1 = OSCRuby::ServiceCategory.where(client,"parent is null and lookupname not like 'Unsure'")
301
-
302
- expect(categories_lvl_1.count).to be > 0
303
-
304
- categories_lvl_1.each_with_index do |p,i|
305
-
306
- if i < 10
307
-
308
- expect(p).to be_an(OSCRuby::ServiceCategory)
309
-
310
- # puts p.name
311
-
312
- end
313
-
314
- end
315
-
316
- end
317
-
318
- it 'should raise an error if the query returns 0 results', :vcr do
319
-
320
- expect{OSCRuby::ServiceCategory.where(client,"parent = 6546546546546")}.to raise_error('There were no objects matching your query; please try again.')
321
-
322
- end
323
-
324
- it 'should just return JSON if the return_json parameter is set to true', :vcr do
325
-
326
- parents = OSCRuby::ServiceCategory.where(client,"parent is null and lookupname not like 'Unsure'",true)
327
-
328
- expect(parents).to be_a(String)
329
-
330
- # puts parents
331
-
332
- end
333
-
334
- end
335
-
336
-
337
-
338
- context '#update' do
339
-
340
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not', :vcr do
341
-
342
- known_working_category = OSCRuby::ServiceCategory.find(client, 6)
343
-
344
- expect(client).to be_an(OSCRuby::Client)
345
-
346
- client = nil
347
-
348
- expect{known_working_category.update(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
349
-
350
- end
351
-
352
- it 'should expect that the Service Category is an instance of a OSCRuby::ServiceCategory', :vcr do
353
-
354
- known_working_category = OSCRuby::ServiceCategory.find(client, 6)
355
-
356
- expect(known_working_category).to be_an(OSCRuby::ServiceCategory)
357
-
358
- end
359
-
360
- it 'should expect that the category has an ID and spit out an error if it does not', :vcr do
361
-
362
- known_working_category = OSCRuby::ServiceCategory.find(client, 6)
363
-
364
- known_working_category.id = nil
365
-
366
- expect{known_working_category.destroy(client)}.to raise_error('OSCRuby::ServiceCategory must have a valid ID set')
367
-
368
- end
369
-
370
- it 'should update name when the names is updated', :vcr do
371
-
372
- test_prods = OSCRuby::ServiceCategory.where(client,"name like 'TEST-CATEGORY'")
373
- first_prod = test_prods[0]
374
-
375
- first_prod.names[0] = {"labelText" => "TEST-CATEGORY-UPDATED", "language" => {"id" => 1}}
376
-
377
- first_prod.update(client)
378
-
379
- expect(first_prod.name).to eq('TEST-CATEGORY-UPDATED')
380
-
381
- end
382
-
383
- it 'should just return JSON if the return_json parameter is set to true', :vcr do
384
-
385
- known_working_category = OSCRuby::ServiceCategory.find(client, 6)
386
-
387
- test = known_working_category.update(client,true)
388
-
389
- expect(test).to be_a(String)
390
-
391
- end
392
-
393
- end
394
-
395
- context '#destroy' do
396
-
397
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not', :vcr do
398
-
399
- test_prods = OSCRuby::ServiceCategory.where(client,"name like 'TEST-CATEGORY-UPDATED'")
400
- category_to_delete = test_prods[0]
401
-
402
- expect(client).to be_an(OSCRuby::Client)
403
-
404
- client = nil
405
-
406
- expect{category_to_delete.destroy(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
407
-
408
- end
409
-
410
- it 'should expect that the Service Category is an instance of a OSCRuby::ServiceCategory', :vcr do
411
-
412
- test_prods = OSCRuby::ServiceCategory.where(client,"name like 'TEST-CATEGORY-UPDATED'")
413
- category_to_delete = test_prods[0]
414
-
415
- expect(category_to_delete).to be_an(OSCRuby::ServiceCategory)
416
-
417
- end
418
-
419
- it 'should expect that the category has an ID and spit out an error if it does not', :vcr do
420
-
421
- test_prods = OSCRuby::ServiceCategory.where(client,"name like 'TEST-CATEGORY-UPDATED'")
422
- category_to_delete = test_prods[0]
423
-
424
- category_to_delete.id = nil
425
-
426
- expect{category_to_delete.destroy(client)}.to raise_error('OSCRuby::ServiceCategory must have a valid ID set')
427
-
428
- end
429
-
430
- it 'should delete the category', :vcr do
431
-
432
- test_prods = OSCRuby::ServiceCategory.where(client,"name like 'TEST-CATEGORY-UPDATED'")
433
- category_to_delete = test_prods[0]
434
-
435
- id_to_find = category_to_delete.id
436
-
437
- category_to_delete.destroy(client)
438
-
439
- expect{OSCRuby::ServiceCategory.find(client, id_to_find)}.to raise_error('There were no objects matching your query; please try again.')
440
-
441
- end
442
-
443
- end
444
-
445
- end