osc_ruby 0.1.13 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -7
- data/README.md +117 -108
- data/lib/osc_ruby.rb +2 -1
- data/lib/osc_ruby/answer.rb +169 -0
- data/lib/osc_ruby/class_factory_module.rb +163 -0
- data/lib/osc_ruby/client.rb +10 -1
- data/lib/osc_ruby/configuration.rb +3 -1
- data/lib/osc_ruby/connect.rb +15 -7
- data/lib/osc_ruby/query_module.rb +45 -38
- data/lib/osc_ruby/service_product.rb +41 -213
- data/lib/osc_ruby/validations_module.rb +94 -0
- data/lib/osc_ruby/version.rb +1 -1
- data/osc_ruby.gemspec +22 -16
- data/spec/core/answer_spec.rb +496 -0
- data/spec/core/client_spec.rb +49 -10
- data/spec/core/connect_spec.rb +28 -33
- data/spec/core/service_product_spec.rb +77 -69
- data/spec/core/spec_helper.rb +24 -1
- metadata +81 -5
data/spec/core/client_spec.rb
CHANGED
@@ -36,23 +36,62 @@ describe OSCRuby::Client do
|
|
36
36
|
end.to raise_error("Password cannot be nil or blank")
|
37
37
|
end
|
38
38
|
|
39
|
-
it 'should
|
39
|
+
it 'should raise exception if no_ssl_verify not a TrueClass nor a FalseClass' do
|
40
40
|
expect do
|
41
|
-
|
41
|
+
OSCRuby::Client.new do |config|
|
42
42
|
config.interface = 'test'
|
43
43
|
config.username = 'test_username'
|
44
|
-
config.password = '
|
44
|
+
config.password = 'password'
|
45
|
+
config.no_ssl_verify = 'true'
|
45
46
|
end
|
47
|
+
end.to raise_error("The no SSL verification setting must be set to true or false")
|
48
|
+
end
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
it 'should raise exception if Connect Version is null' do
|
51
|
+
expect do
|
52
|
+
OSCRuby::Client.new do |config|
|
53
|
+
config.interface = 'test'
|
54
|
+
config.username = 'test_username'
|
55
|
+
config.password = 'password'
|
56
|
+
config.version = nil
|
57
|
+
end
|
58
|
+
end.to raise_error("Connect version cannot be null")
|
59
|
+
end
|
52
60
|
|
53
|
-
|
54
|
-
|
61
|
+
let(:client){
|
62
|
+
OSCRuby::Client.new do |config|
|
63
|
+
config.interface = 'test'
|
64
|
+
config.username = 'test_username'
|
65
|
+
config.password = 'test_password'
|
66
|
+
config.no_ssl_verify = true
|
55
67
|
end
|
68
|
+
}
|
69
|
+
|
70
|
+
it 'should create a configuration object' do
|
71
|
+
|
72
|
+
expect{client}.to_not raise_error
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should have interface set to "test" and not "test1"' do
|
77
|
+
expect(client.config.interface).to eq('test')
|
78
|
+
expect(client.config.interface).not_to eq('test1')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should have username set to "test_username" and not "test1_username"' do
|
82
|
+
expect(client.config.username).to eq('test_username')
|
83
|
+
expect(client.config.username).not_to eq('test1_username')
|
56
84
|
end
|
85
|
+
|
86
|
+
it 'should have password set to "test_password" and not "test1_password"' do
|
87
|
+
expect(client.config.password).to eq('test_password')
|
88
|
+
expect(client.config.password).not_to eq('test1_password')
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should have no_ssl set to true and not false' do
|
92
|
+
expect(client.config.no_ssl_verify).to eq(true)
|
93
|
+
expect(client.config.no_ssl_verify).not_to eq(false)
|
94
|
+
end
|
95
|
+
|
57
96
|
end
|
58
97
|
end
|
data/spec/core/connect_spec.rb
CHANGED
@@ -135,7 +135,7 @@ describe OSCRuby::Connect do
|
|
135
135
|
|
136
136
|
context '#post_or_patch' do
|
137
137
|
|
138
|
-
it 'should take at least a config parameter that is an instance of an OSCRuby::Client' do
|
138
|
+
it 'should take at least a config parameter that is an instance of an OSCRuby::Client', :vcr do
|
139
139
|
|
140
140
|
expect(client).to be_an(OSCRuby::Client)
|
141
141
|
|
@@ -178,7 +178,7 @@ describe OSCRuby::Connect do
|
|
178
178
|
|
179
179
|
end
|
180
180
|
|
181
|
-
it 'should produce a Net::HTTPResponse, should produce a 201 response code, and should produce a JSON Response form the response body' do
|
181
|
+
it 'should produce a Net::HTTPResponse, should produce a 201 response code, and should produce a JSON Response form the response body', :vcr do
|
182
182
|
|
183
183
|
names = []
|
184
184
|
|
@@ -213,15 +213,11 @@ describe OSCRuby::Connect do
|
|
213
213
|
|
214
214
|
end
|
215
215
|
|
216
|
-
end
|
217
|
-
|
218
|
-
let(:test){
|
219
|
-
OSCRuby::Connect.get(client)
|
220
|
-
}
|
216
|
+
end
|
221
217
|
|
222
218
|
context '#get' do
|
223
219
|
|
224
|
-
it 'should take at least a config parameter that is an instance of an OSCRuby::Client' do
|
220
|
+
it 'should take at least a config parameter that is an instance of an OSCRuby::Client', :vcr do
|
225
221
|
|
226
222
|
expect(client).to be_an(OSCRuby::Client)
|
227
223
|
|
@@ -245,19 +241,25 @@ describe OSCRuby::Connect do
|
|
245
241
|
|
246
242
|
end
|
247
243
|
|
248
|
-
it 'should produce a Net::HTTPResponse' do
|
244
|
+
it 'should produce a Net::HTTPResponse', :vcr do
|
245
|
+
|
246
|
+
test = OSCRuby::Connect.get(client)
|
249
247
|
|
250
248
|
expect(test).to be_an(Net::HTTPResponse)
|
251
249
|
|
252
250
|
end
|
253
251
|
|
254
|
-
it 'should produce a 200 response code' do
|
252
|
+
it 'should produce a 200 response code', :vcr do
|
253
|
+
|
254
|
+
test = OSCRuby::Connect.get(client)
|
255
255
|
|
256
256
|
expect(test.code).to eq("200")
|
257
257
|
|
258
258
|
end
|
259
259
|
|
260
|
-
it 'should produce a JSON Response from the response body' do
|
260
|
+
it 'should produce a JSON Response from the response body', :vcr do
|
261
|
+
|
262
|
+
test = OSCRuby::Connect.get(client)
|
261
263
|
|
262
264
|
expect(test.body).to be_an(String)
|
263
265
|
|
@@ -266,21 +268,18 @@ describe OSCRuby::Connect do
|
|
266
268
|
|
267
269
|
end
|
268
270
|
|
269
|
-
let(:product_test_id){
|
270
|
-
|
271
|
-
resource = URI.escape("queryResults/?query=select id from serviceproducts where lookupname = 'PRODUCT-TEST';")
|
272
271
|
|
273
|
-
|
272
|
+
context '#post_or_patch' do
|
274
273
|
|
275
|
-
|
274
|
+
it 'should take an optional parameter to allow PATCH request; it should produce a Net::HTTPResponse, should produce a 200 code', :vcr do
|
276
275
|
|
277
|
-
|
276
|
+
resource = URI.escape("queryResults/?query=select id from serviceproducts where lookupname = 'PRODUCT-TEST';")
|
278
277
|
|
279
|
-
|
278
|
+
product_test = OSCRuby::Connect.get(client,resource)
|
280
279
|
|
281
|
-
|
280
|
+
prod_json = JSON.parse(product_test.body).to_hash
|
282
281
|
|
283
|
-
|
282
|
+
product_test_id = prod_json['items'][0]['rows'][0][0].to_i
|
284
283
|
|
285
284
|
names = []
|
286
285
|
|
@@ -315,18 +314,6 @@ describe OSCRuby::Connect do
|
|
315
314
|
|
316
315
|
end
|
317
316
|
|
318
|
-
let(:product_test_updated_id){
|
319
|
-
|
320
|
-
resource = URI.escape("queryResults/?query=select id from serviceproducts where lookupname = 'PRODUCT-TEST-updated';")
|
321
|
-
|
322
|
-
product_test_updated = OSCRuby::Connect.get(client,resource)
|
323
|
-
|
324
|
-
prod_json = JSON.parse(product_test_updated.body).to_hash
|
325
|
-
|
326
|
-
prod_json['items'][0]['rows'][0][0].to_i
|
327
|
-
|
328
|
-
}
|
329
|
-
|
330
317
|
context '#delete' do
|
331
318
|
|
332
319
|
it 'should raise an error if client is nil' do
|
@@ -351,7 +338,15 @@ describe OSCRuby::Connect do
|
|
351
338
|
|
352
339
|
end
|
353
340
|
|
354
|
-
it 'it should produce a Net::HTTPResponse, should produce a 200 code' do
|
341
|
+
it 'it should produce a Net::HTTPResponse, should produce a 200 code', :vcr do
|
342
|
+
|
343
|
+
resource = URI.escape("queryResults/?query=select id from serviceproducts where lookupname = 'PRODUCT-TEST-updated';")
|
344
|
+
|
345
|
+
product_test_updated = OSCRuby::Connect.get(client,resource)
|
346
|
+
|
347
|
+
prod_json = JSON.parse(product_test_updated.body).to_hash
|
348
|
+
|
349
|
+
product_test_updated_id = prod_json['items'][0]['rows'][0][0].to_i
|
355
350
|
|
356
351
|
test = OSCRuby::Connect.delete(client,"serviceProducts/#{product_test_updated_id}")
|
357
352
|
|
@@ -35,60 +35,60 @@ describe OSCRuby::ServiceProduct do
|
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
|
-
let(:attributes){
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
}
|
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
48
|
|
49
|
-
context '#new_from_fetch' do
|
49
|
+
# context '#new_from_fetch' do
|
50
50
|
|
51
|
-
|
51
|
+
# it 'should accept an attributes as a hash' do
|
52
52
|
|
53
|
-
|
53
|
+
# expect do
|
54
54
|
|
55
|
-
|
55
|
+
# attributes = []
|
56
56
|
|
57
|
-
|
57
|
+
# OSCRuby::ServiceProduct.new_from_fetch(attributes)
|
58
58
|
|
59
|
-
|
59
|
+
# end.to raise_error("Attributes must be a hash; please use the appropriate data structure")
|
60
60
|
|
61
|
-
|
61
|
+
# expect do
|
62
62
|
|
63
|
-
|
63
|
+
# OSCRuby::ServiceProduct.new_from_fetch(attributes)
|
64
64
|
|
65
|
-
|
65
|
+
# end.not_to raise_error
|
66
66
|
|
67
|
-
|
67
|
+
# end
|
68
68
|
|
69
|
-
|
69
|
+
# it 'should instantiate an id, lookupName, createdTime, updatedTime, displayOrder, name, and parent with the correct values' do
|
70
70
|
|
71
|
-
|
71
|
+
# test = OSCRuby::ServiceProduct.new_from_fetch(attributes)
|
72
72
|
|
73
|
-
|
73
|
+
# expect(test.id).to eq(1)
|
74
74
|
|
75
|
-
|
75
|
+
# expect(test.lookupName).to eq('Test Product Lookup Name')
|
76
76
|
|
77
|
-
|
77
|
+
# expect(test.createdTime).to eq(nil)
|
78
78
|
|
79
|
-
|
79
|
+
# expect(test.updatedTime).to eq(nil)
|
80
80
|
|
81
|
-
|
81
|
+
# expect(test.displayOrder).to eq(1)
|
82
82
|
|
83
|
-
|
83
|
+
# expect(test.name).to eq('Test Product Lookup Name')
|
84
84
|
|
85
|
-
|
85
|
+
# expect(test.name).to eq(test.lookupName)
|
86
86
|
|
87
|
-
|
87
|
+
# expect(test.parent).to eq(nil)
|
88
88
|
|
89
|
-
|
89
|
+
# end
|
90
90
|
|
91
|
-
end
|
91
|
+
# end
|
92
92
|
|
93
93
|
let(:client) {
|
94
94
|
|
@@ -141,7 +141,7 @@ describe OSCRuby::ServiceProduct do
|
|
141
141
|
|
142
142
|
end
|
143
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)' do
|
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
145
|
|
146
146
|
new_service_product.names[0] = {"labelText" => "TEST-PRODUCT", "language" => {"id" => 1}}
|
147
147
|
new_service_product.names[1] = {"labelText" => "TEST-PRODUCT", "language" => {"id" => 11}}
|
@@ -165,7 +165,7 @@ describe OSCRuby::ServiceProduct do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
|
168
|
-
it 'should return the body object if the json_response param is set to true' do
|
168
|
+
it 'should return the body object if the json_response param is set to true', :vcr do
|
169
169
|
|
170
170
|
new_service_product.names[0] = {"labelText" => "TEST-PRODUCT", "language" => {"id" => 1}}
|
171
171
|
new_service_product.names[1] = {'labelText' => 'TEST-PRODUCT', 'language' => {'id' => 11}}
|
@@ -200,19 +200,16 @@ describe OSCRuby::ServiceProduct do
|
|
200
200
|
|
201
201
|
end
|
202
202
|
|
203
|
-
it 'should return a warning if empty/no instances of the object can be found' do
|
203
|
+
it 'should return a warning if empty/no instances of the object can be found', :vcr do
|
204
204
|
|
205
205
|
expect{OSCRuby::ServiceProduct.find(client, 1)}.to raise_error('There were no objects matching your query; please try again.')
|
206
206
|
|
207
207
|
end
|
208
208
|
|
209
209
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
it 'should return an instance of a new OSCRuby::ServiceProduct object with at least a name and displayOrder' do
|
210
|
+
it 'should return an instance of a new OSCRuby::ServiceProduct object with at least a name and displayOrder', :vcr do
|
211
|
+
|
212
|
+
known_working_product = OSCRuby::ServiceProduct.find(client, 100)
|
216
213
|
|
217
214
|
expect(known_working_product).to be_an(OSCRuby::ServiceProduct)
|
218
215
|
|
@@ -222,7 +219,7 @@ describe OSCRuby::ServiceProduct do
|
|
222
219
|
|
223
220
|
end
|
224
221
|
|
225
|
-
it 'should return the raw json response if the return_json parameter is set to true' do
|
222
|
+
it 'should return the raw json response if the return_json parameter is set to true', :vcr do
|
226
223
|
|
227
224
|
known_working_product_in_json = OSCRuby::ServiceProduct.find(client, 100, true)
|
228
225
|
|
@@ -244,7 +241,7 @@ describe OSCRuby::ServiceProduct do
|
|
244
241
|
|
245
242
|
end
|
246
243
|
|
247
|
-
it 'should return multiple instances of OSCRuby::ServiceProduct' do
|
244
|
+
it 'should return multiple instances of OSCRuby::ServiceProduct', :vcr do
|
248
245
|
|
249
246
|
products = OSCRuby::ServiceProduct.all(client)
|
250
247
|
|
@@ -266,7 +263,7 @@ describe OSCRuby::ServiceProduct do
|
|
266
263
|
|
267
264
|
end
|
268
265
|
|
269
|
-
it 'should just return JSON if the return_json parameter is set to true' do
|
266
|
+
it 'should just return JSON if the return_json parameter is set to true', :vcr do
|
270
267
|
|
271
268
|
expect(OSCRuby::ServiceProduct.all(client,true)).to be_a(String)
|
272
269
|
|
@@ -292,7 +289,7 @@ describe OSCRuby::ServiceProduct do
|
|
292
289
|
|
293
290
|
end
|
294
291
|
|
295
|
-
it 'should take a query and return results' do
|
292
|
+
it 'should take a query and return results', :vcr do
|
296
293
|
|
297
294
|
products_lvl_1 = OSCRuby::ServiceProduct.where(client,"parent is null and lookupname not like 'Unsure'")
|
298
295
|
|
@@ -312,13 +309,13 @@ describe OSCRuby::ServiceProduct do
|
|
312
309
|
|
313
310
|
end
|
314
311
|
|
315
|
-
it 'should raise an error if the query returns 0 results' do
|
312
|
+
it 'should raise an error if the query returns 0 results', :vcr do
|
316
313
|
|
317
314
|
expect{OSCRuby::ServiceProduct.where(client,"parent = 6546546546546")}.to raise_error('There were no objects matching your query; please try again.')
|
318
315
|
|
319
316
|
end
|
320
317
|
|
321
|
-
it 'should just return JSON if the return_json parameter is set to true' do
|
318
|
+
it 'should just return JSON if the return_json parameter is set to true', :vcr do
|
322
319
|
|
323
320
|
parents = OSCRuby::ServiceProduct.where(client,"parent is null and lookupname not like 'Unsure'",true)
|
324
321
|
|
@@ -330,13 +327,13 @@ describe OSCRuby::ServiceProduct do
|
|
330
327
|
|
331
328
|
end
|
332
329
|
|
333
|
-
|
334
|
-
OSCRuby::ServiceProduct.find(client, 100)
|
335
|
-
}
|
330
|
+
|
336
331
|
|
337
332
|
context '#update' do
|
338
333
|
|
339
|
-
it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
|
334
|
+
it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not', :vcr do
|
335
|
+
|
336
|
+
known_working_product = OSCRuby::ServiceProduct.find(client, 100)
|
340
337
|
|
341
338
|
expect(client).to be_an(OSCRuby::Client)
|
342
339
|
|
@@ -346,13 +343,17 @@ describe OSCRuby::ServiceProduct do
|
|
346
343
|
|
347
344
|
end
|
348
345
|
|
349
|
-
it 'should expect that the Service Product is an instance of a OSCRuby::ServiceProduct' do
|
346
|
+
it 'should expect that the Service Product is an instance of a OSCRuby::ServiceProduct', :vcr do
|
347
|
+
|
348
|
+
known_working_product = OSCRuby::ServiceProduct.find(client, 100)
|
350
349
|
|
351
350
|
expect(known_working_product).to be_an(OSCRuby::ServiceProduct)
|
352
351
|
|
353
352
|
end
|
354
353
|
|
355
|
-
it 'should expect that the product has an ID and spit out an error if it does not' do
|
354
|
+
it 'should expect that the product has an ID and spit out an error if it does not', :vcr do
|
355
|
+
|
356
|
+
known_working_product = OSCRuby::ServiceProduct.find(client, 100)
|
356
357
|
|
357
358
|
known_working_product.id = nil
|
358
359
|
|
@@ -360,20 +361,22 @@ describe OSCRuby::ServiceProduct do
|
|
360
361
|
|
361
362
|
end
|
362
363
|
|
363
|
-
it 'should update name when the names is updated' do
|
364
|
+
it 'should update name when the names is updated', :vcr do
|
364
365
|
|
365
|
-
test_prods = OSCRuby::ServiceProduct.where(client,"name like '
|
366
|
+
test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT'")
|
366
367
|
first_prod = test_prods[0]
|
367
368
|
|
368
|
-
first_prod.names[0] = {"labelText" => "
|
369
|
+
first_prod.names[0] = {"labelText" => "TEST-PRODUCT-UPDATED", "language" => {"id" => 1}}
|
369
370
|
|
370
371
|
first_prod.update(client)
|
371
372
|
|
372
|
-
expect(first_prod.name).to eq('
|
373
|
+
expect(first_prod.name).to eq('TEST-PRODUCT-UPDATED')
|
373
374
|
|
374
375
|
end
|
375
376
|
|
376
|
-
it 'should just return JSON if the return_json parameter is set to true' do
|
377
|
+
it 'should just return JSON if the return_json parameter is set to true', :vcr do
|
378
|
+
|
379
|
+
known_working_product = OSCRuby::ServiceProduct.find(client, 100)
|
377
380
|
|
378
381
|
test = known_working_product.update(client,true)
|
379
382
|
|
@@ -383,16 +386,12 @@ describe OSCRuby::ServiceProduct do
|
|
383
386
|
|
384
387
|
end
|
385
388
|
|
386
|
-
let(:product_to_delete){
|
387
|
-
|
388
|
-
test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT'")
|
389
|
-
test_prods[0]
|
390
|
-
|
391
|
-
}
|
392
|
-
|
393
389
|
context '#destroy' do
|
394
390
|
|
395
|
-
it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
|
391
|
+
it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not', :vcr do
|
392
|
+
|
393
|
+
test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT-UPDATED'")
|
394
|
+
product_to_delete = test_prods[0]
|
396
395
|
|
397
396
|
expect(client).to be_an(OSCRuby::Client)
|
398
397
|
|
@@ -402,13 +401,19 @@ describe OSCRuby::ServiceProduct do
|
|
402
401
|
|
403
402
|
end
|
404
403
|
|
405
|
-
it 'should expect that the Service Product is an instance of a OSCRuby::ServiceProduct' do
|
404
|
+
it 'should expect that the Service Product is an instance of a OSCRuby::ServiceProduct', :vcr do
|
405
|
+
|
406
|
+
test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT-UPDATED'")
|
407
|
+
product_to_delete = test_prods[0]
|
406
408
|
|
407
409
|
expect(product_to_delete).to be_an(OSCRuby::ServiceProduct)
|
408
410
|
|
409
411
|
end
|
410
412
|
|
411
|
-
it 'should expect that the product has an ID and spit out an error if it does not' do
|
413
|
+
it 'should expect that the product has an ID and spit out an error if it does not', :vcr do
|
414
|
+
|
415
|
+
test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT-UPDATED'")
|
416
|
+
product_to_delete = test_prods[0]
|
412
417
|
|
413
418
|
product_to_delete.id = nil
|
414
419
|
|
@@ -416,7 +421,10 @@ describe OSCRuby::ServiceProduct do
|
|
416
421
|
|
417
422
|
end
|
418
423
|
|
419
|
-
it 'should delete the product' do
|
424
|
+
it 'should delete the product', :vcr do
|
425
|
+
|
426
|
+
test_prods = OSCRuby::ServiceProduct.where(client,"name like 'TEST-PRODUCT-UPDATED'")
|
427
|
+
product_to_delete = test_prods[0]
|
420
428
|
|
421
429
|
id_to_find = product_to_delete.id
|
422
430
|
|