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,443 +0,0 @@
1
- require 'core/spec_helper'
2
- require 'json'
3
- require 'uri'
4
-
5
- describe OSCRuby::ServiceProduct do
6
-
7
- let(:service_product){
8
-
9
- OSCRuby::ServiceProduct.new
10
-
11
- }
12
-
13
- context '#initialize' do
14
-
15
- it 'should not throw an error when initialized' do
16
-
17
- expect{service_product}.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_product.names).to eq([])
25
-
26
- expect(service_product.parent).to eq({})
27
-
28
- expect(service_product.displayOrder).to eq(1)
29
-
30
- expect(service_product.adminVisibleInterfaces).to eq([])
31
-
32
- expect(service_product.endUserVisibleInterfaces).to eq([])
33
-
34
- end
35
-
36
- end
37
-
38
- # let(:attributes){
39
- # {'id' => 1,
40
- # 'lookupName' => 'Test Product 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::ServiceProduct.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::ServiceProduct.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::ServiceProduct.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_product){
107
- OSCRuby::ServiceProduct.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_product.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_product.create(client)}.to raise_error('ServiceProduct 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_product.names[0] = "new product name"
131
-
132
- expect{new_service_product.create(client)}.to raise_error('ServiceProduct 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_product.names[0] = {"labelText" => "QTH45-test"}
139
-
140
- expect{new_service_product.create(client)}.to raise_error('ServiceProduct should at least have one name set')
141
-
142
- end
143
-
144
- it 'should return an instance of an OSCRuby::ServiceProduct if the json_response param is set to false (which it is by default)', :vcr do
145
-
146
- new_service_product.names[0] = {"labelText" => "TEST-PRODUCT", "language" => {"id" => 1}}
147
- new_service_product.names[1] = {"labelText" => "TEST-PRODUCT", "language" => {"id" => 11}}
148
-
149
- new_service_product.parent = {'id' => 102}
150
-
151
- new_service_product.displayOrder = 4
152
-
153
- new_service_product.create(client)
154
-
155
- expect(new_service_product).to be_a(OSCRuby::ServiceProduct)
156
-
157
- expect(new_service_product.name).to eq("TEST-PRODUCT")
158
-
159
- expect(new_service_product.lookupName).to eq("TEST-PRODUCT")
160
-
161
- expect(new_service_product.displayOrder).to eq(4)
162
-
163
- expect(new_service_product.parent).to eq(102)
164
-
165
- expect(new_service_product.id).to_not eq(nil)
166
-
167
- end
168
-
169
-
170
- it 'should print the body object if the json_response param is set to true', :vcr do
171
-
172
- new_service_product.names[0] = {"labelText" => "TEST-PRODUCT", "language" => {"id" => 1}}
173
- new_service_product.names[1] = {'labelText' => 'TEST-PRODUCT', 'language' => {'id' => 11}}
174
-
175
- new_service_product.create(client,true)
176
-
177
- expect(new_service_product).to be_a(OSCRuby::ServiceProduct)
178
-
179
- end
180
-
181
- end
182
-
183
- context '#find' do
184
-
185
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
186
-
187
- expect(client).to be_an(OSCRuby::Client)
188
-
189
- client = nil
190
-
191
- expect{OSCRuby::ServiceProduct.find(client,100)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
192
-
193
- end
194
-
195
- it 'should raise an error if ID is undefined' do
196
-
197
- expect{OSCRuby::ServiceProduct.find(client)}.to raise_error('ID cannot be nil')
198
-
199
- end
200
-
201
- it 'should raise an error if ID is not an integer' do
202
-
203
- expect{OSCRuby::ServiceProduct.find(client, 'a')}.to raise_error('ID must be an integer')
204
-
205
- end
206
-
207
- it 'should return a warning if empty/no instances of the object can be found', :vcr do
208
-
209
- expect{OSCRuby::ServiceProduct.find(client, 1)}.to raise_error('There were no objects matching your query; please try again.')
210
-
211
- end
212
-
213
-
214
- it 'should return an instance of a new OSCRuby::ServiceProduct object with at least a name and displayOrder', :vcr do
215
-
216
- known_working_product = OSCRuby::ServiceProduct.find(client, 100)
217
-
218
- expect(known_working_product).to be_an(OSCRuby::ServiceProduct)
219
-
220
- expect(known_working_product.name).to eq('QR404')
221
-
222
- expect(known_working_product.displayOrder).to eq(3)
223
-
224
- end
225
-
226
- it 'should return the raw json response if the return_json parameter is set to true', :vcr do
227
-
228
- known_working_product_in_json = OSCRuby::ServiceProduct.find(client, 100, true)
229
-
230
- expect(known_working_product_in_json).to be_an(String)
231
-
232
- end
233
-
234
- end
235
-
236
- context '#all' do
237
-
238
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
239
-
240
- expect(client).to be_an(OSCRuby::Client)
241
-
242
- client = nil
243
-
244
- expect{OSCRuby::ServiceProduct.all(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
245
-
246
- end
247
-
248
- it 'should return multiple instances of OSCRuby::ServiceProduct', :vcr do
249
-
250
- products = OSCRuby::ServiceProduct.all(client)
251
-
252
- expect(products.size).to be > 0
253
-
254
- # puts "Checking if OSCRuby::ServiceProduct.all produces multiple instances of products"
255
-
256
- products.each_with_index do |p,i|
257
-
258
- if i < 10
259
-
260
- expect(p).to be_an(OSCRuby::ServiceProduct)
261
-
262
- # puts p.name
263
-
264
- end
265
-
266
- end
267
-
268
- end
269
-
270
- it 'should just return JSON if the return_json parameter is set to true', :vcr do
271
-
272
- expect(OSCRuby::ServiceProduct.all(client,true)).to be_a(String)
273
-
274
- end
275
-
276
- end
277
-
278
- context '#where' do
279
-
280
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
281
-
282
- expect(client).to be_an(OSCRuby::Client)
283
-
284
- client = nil
285
-
286
- expect{OSCRuby::ServiceProduct.where(client,'query')}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
287
-
288
- end
289
-
290
- it 'should raise an error if there is no query' do
291
-
292
- expect{OSCRuby::ServiceProduct.where(client)}.to raise_error("A query must be specified when using the 'where' method")
293
-
294
- end
295
-
296
- it 'should take a query and return results', :vcr do
297
-
298
- products_lvl_1 = OSCRuby::ServiceProduct.where(client,"parent is null and lookupname not like 'Unsure'")
299
-
300
- expect(products_lvl_1.count).to be > 0
301
-
302
- products_lvl_1.each_with_index do |p,i|
303
-
304
- if i < 10
305
-
306
- expect(p).to be_an(OSCRuby::ServiceProduct)
307
-
308
- # puts p.name
309
-
310
- end
311
-
312
- end
313
-
314
- end
315
-
316
- it 'should raise an error if the query returns 0 results', :vcr do
317
-
318
- expect{OSCRuby::ServiceProduct.where(client,"parent = 6546546546546")}.to raise_error('There were no objects matching your query; please try again.')
319
-
320
- end
321
-
322
- it 'should just return JSON if the return_json parameter is set to true', :vcr do
323
-
324
- parents = OSCRuby::ServiceProduct.where(client,"parent is null and lookupname not like 'Unsure'",true)
325
-
326
- expect(parents).to be_a(String)
327
-
328
- # puts parents
329
-
330
- end
331
-
332
- end
333
-
334
-
335
-
336
- context '#update' do
337
-
338
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not', :vcr do
339
-
340
- known_working_product = OSCRuby::ServiceProduct.find(client, 100)
341
-
342
- expect(client).to be_an(OSCRuby::Client)
343
-
344
- client = nil
345
-
346
- expect{known_working_product.update(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
347
-
348
- end
349
-
350
- it 'should expect that the Service Product is an instance of a OSCRuby::ServiceProduct', :vcr do
351
-
352
- known_working_product = OSCRuby::ServiceProduct.find(client, 100)
353
-
354
- expect(known_working_product).to be_an(OSCRuby::ServiceProduct)
355
-
356
- end
357
-
358
- it 'should expect that the product has an ID and spit out an error if it does not', :vcr do
359
-
360
- known_working_product = OSCRuby::ServiceProduct.find(client, 100)
361
-
362
- known_working_product.id = nil
363
-
364
- expect{known_working_product.destroy(client)}.to raise_error('OSCRuby::ServiceProduct must have a valid ID set')
365
-
366
- end
367
-
368
- it 'should update name when the names is updated', :vcr do
369
-
370
- test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT'")
371
- first_prod = test_prods[0]
372
-
373
- first_prod.names[0] = {"labelText" => "TEST-PRODUCT-UPDATED", "language" => {"id" => 1}}
374
-
375
- first_prod.update(client)
376
-
377
- expect(first_prod.name).to eq('TEST-PRODUCT-UPDATED')
378
-
379
- end
380
-
381
- it 'should just return JSON if the return_json parameter is set to true', :vcr do
382
-
383
- known_working_product = OSCRuby::ServiceProduct.find(client, 100)
384
-
385
- test = known_working_product.update(client,true)
386
-
387
- expect(test).to be_a(String)
388
-
389
- end
390
-
391
- end
392
-
393
- context '#destroy' do
394
-
395
- it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not', :vcr do
396
-
397
- test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT-UPDATED'")
398
- product_to_delete = test_prods[0]
399
-
400
- expect(client).to be_an(OSCRuby::Client)
401
-
402
- client = nil
403
-
404
- expect{product_to_delete.destroy(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
405
-
406
- end
407
-
408
- it 'should expect that the Service Product is an instance of a OSCRuby::ServiceProduct', :vcr do
409
-
410
- test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT-UPDATED'")
411
- product_to_delete = test_prods[0]
412
-
413
- expect(product_to_delete).to be_an(OSCRuby::ServiceProduct)
414
-
415
- end
416
-
417
- it 'should expect that the product has an ID and spit out an error if it does not', :vcr do
418
-
419
- test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT-UPDATED'")
420
- product_to_delete = test_prods[0]
421
-
422
- product_to_delete.id = nil
423
-
424
- expect{product_to_delete.destroy(client)}.to raise_error('OSCRuby::ServiceProduct must have a valid ID set')
425
-
426
- end
427
-
428
- it 'should delete the product', :vcr do
429
-
430
- test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT-UPDATED'")
431
- product_to_delete = test_prods[0]
432
-
433
- id_to_find = product_to_delete.id
434
-
435
- product_to_delete.destroy(client)
436
-
437
- expect{OSCRuby::ServiceProduct.find(client, id_to_find)}.to raise_error('There were no objects matching your query; please try again.')
438
-
439
- end
440
-
441
- end
442
-
443
- end