odata 0.6.15 → 0.6.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e83d2a763bb4cd6d4213ce5e9be23d0f6e7f02b
4
- data.tar.gz: 1f45cb9c32597e22a6b2e701534d369e6c65fc05
3
+ metadata.gz: 6ccdad87a366a6ec1b89037adaa0e3d818014942
4
+ data.tar.gz: 0331230ef4c1399ada4fb696e660a896d4a74a62
5
5
  SHA512:
6
- metadata.gz: fde18385c775b9cd4abaed0a9cdca0407cf929fb628f9869fe6ae824ee669a2a7133b5459c9f753fe6b93127f0dd501717fd40b19503cb330f9ebad49d4b4233
7
- data.tar.gz: 69002bdb927450f5355555f86910e35b1b8df34b984cf87daab0f150dd235e80a894f28c7dcdaa9dc2374a3a99f6eba3e9cb41f82c37ea4ed3a4bc5cdcb992a1
6
+ metadata.gz: b4a3bcc7df1affa0c87459d24776a5df71a3fc8159907a39c17f7f8154dc35958125e58236d9f4fa2c9174c3a04e35f676a8ec59ce8868525902759c32fb73e4
7
+ data.tar.gz: b3a9decd9248f552b04990cb4a9d403df6367cd67346951856adc651e0f39f7d4ece9286063050e7f95bb70df9f93a1c1a60bb2557f8ec2861e90f397a15323f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.6.16
4
+
5
+ * Implemented OData::Query#empty? and fixed OData::Query#count.
6
+
3
7
  ## 0.6.15
4
8
 
5
9
  * Fixed minor bug in last release.
data/lib/odata/query.rb CHANGED
@@ -100,7 +100,14 @@ module OData
100
100
  # Executes the query to get a count of entities.
101
101
  # @return [Integer]
102
102
  def count
103
- entity_set.service.execute("#{self.to_s}/$count").body.to_i
103
+ url_chunk = "#{entity_set.name}/$count?#{assemble_criteria}"
104
+ entity_set.service.execute(url_chunk).body.to_i
105
+ end
106
+
107
+ # Checks whether a query will return any results by calling #count
108
+ # @return [Boolean]
109
+ def empty?
110
+ self.count == 0
104
111
  end
105
112
 
106
113
  # The EntitySet for this query.
data/lib/odata/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OData
2
- VERSION = '0.6.15'
2
+ VERSION = '0.6.16'
3
3
  end
@@ -1,5 +1,56 @@
1
1
  ---
2
2
  http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://services.odata.org/OData/OData.svc/Products/$count?
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Typhoeus - https://github.com/typhoeus/typhoeus
12
+ DataServiceVersion:
13
+ - '3.0'
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Cache-Control:
20
+ - no-cache
21
+ Content-Length:
22
+ - '2'
23
+ Content-Type:
24
+ - text/plain;charset=utf-8
25
+ Server:
26
+ - Microsoft-IIS/8.0
27
+ X-Content-Type-Options:
28
+ - nosniff
29
+ DataServiceVersion:
30
+ - 2.0;
31
+ X-AspNet-Version:
32
+ - 4.0.30319
33
+ X-Powered-By:
34
+ - ASP.NET
35
+ Access-Control-Allow-Origin:
36
+ - "*"
37
+ Access-Control-Allow-Methods:
38
+ - GET
39
+ Access-Control-Allow-Headers:
40
+ - Accept, Origin, Content-Type, MaxDataServiceVersion
41
+ Access-Control-Expose-Headers:
42
+ - DataServiceVersion
43
+ Set-Cookie:
44
+ - ARRAffinity=f52a868fbb9bda30202dea2c82bfa2f9350871e50836757efd92afab45cf9549;Path=/;Domain=services.odata.org
45
+ Date:
46
+ - Fri, 10 Oct 2014 20:17:49 GMT
47
+ body:
48
+ encoding: UTF-8
49
+ string: '11'
50
+ http_version: '1.1'
51
+ adapter_metadata:
52
+ effective_url: http://services.odata.org/OData/OData.svc/Products/$count?
53
+ recorded_at: Fri, 10 Oct 2014 20:17:49 GMT
3
54
  - request:
4
55
  method: get
5
56
  uri: http://services.odata.org/OData/OData.svc/$metadata
@@ -41,9 +92,9 @@ http_interactions:
41
92
  Access-Control-Expose-Headers:
42
93
  - DataServiceVersion
43
94
  Set-Cookie:
44
- - ARRAffinity=cb44902b614a02a3a0dc1bccc3de360d89b180ff17e14b11fd9b289a8de75827;Path=/;Domain=services.odata.org
95
+ - ARRAffinity=f52a868fbb9bda30202dea2c82bfa2f9350871e50836757efd92afab45cf9549;Path=/;Domain=services.odata.org
45
96
  Date:
46
- - Mon, 29 Sep 2014 04:25:33 GMT
97
+ - Fri, 10 Oct 2014 20:17:49 GMT
47
98
  body:
48
99
  encoding: UTF-8
49
100
  string: <?xml version="1.0" encoding="utf-8"?><edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"><edmx:DataServices
@@ -162,7 +213,7 @@ http_interactions:
162
213
  http_version: '1.1'
163
214
  adapter_metadata:
164
215
  effective_url: http://services.odata.org/OData/OData.svc/$metadata
165
- recorded_at: Mon, 29 Sep 2014 04:25:33 GMT
216
+ recorded_at: Fri, 10 Oct 2014 20:17:49 GMT
166
217
  - request:
167
218
  method: get
168
219
  uri: http://services.odata.org/OData/OData.svc/Products
@@ -204,16 +255,16 @@ http_interactions:
204
255
  Access-Control-Expose-Headers:
205
256
  - DataServiceVersion
206
257
  Set-Cookie:
207
- - ARRAffinity=cb44902b614a02a3a0dc1bccc3de360d89b180ff17e14b11fd9b289a8de75827;Path=/;Domain=services.odata.org
258
+ - ARRAffinity=f52a868fbb9bda30202dea2c82bfa2f9350871e50836757efd92afab45cf9549;Path=/;Domain=services.odata.org
208
259
  Date:
209
- - Mon, 29 Sep 2014 04:25:33 GMT
260
+ - Fri, 10 Oct 2014 20:17:49 GMT
210
261
  body:
211
262
  encoding: UTF-8
212
263
  string: <?xml version="1.0" encoding="utf-8"?><feed xml:base="http://services.odata.org/OData/OData.svc/"
213
264
  xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
214
265
  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss"
215
266
  xmlns:gml="http://www.opengis.net/gml"><id>http://services.odata.org/OData/OData.svc/Products</id><title
216
- type="text">Products</title><updated>2014-09-29T04:25:33Z</updated><link rel="self"
267
+ type="text">Products</title><updated>2014-10-10T20:17:49Z</updated><link rel="self"
217
268
  title="Products" href="Products" /><entry><id>http://services.odata.org/OData/OData.svc/Products(0)</id><category
218
269
  term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
219
270
  /><link rel="edit" title="Product" href="Products(0)" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories"
@@ -222,7 +273,7 @@ http_interactions:
222
273
  type="application/atom+xml;type=entry" title="Supplier" href="Products(0)/Supplier"
223
274
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
224
275
  type="application/atom+xml;type=entry" title="ProductDetail" href="Products(0)/ProductDetail"
225
- /><title type="text">Bread</title><summary type="text">Whole grain bread</summary><updated>2014-09-29T04:25:33Z</updated><author><name
276
+ /><title type="text">Bread</title><summary type="text">Whole grain bread</summary><updated>2014-10-10T20:17:49Z</updated><author><name
226
277
  /></author><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
227
278
  type="application/xml" title="Categories" href="Products(0)/$links/Categories"
228
279
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -239,7 +290,7 @@ http_interactions:
239
290
  type="application/atom+xml;type=entry" title="Supplier" href="Products(1)/Supplier"
240
291
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
241
292
  type="application/atom+xml;type=entry" title="ProductDetail" href="Products(1)/ProductDetail"
242
- /><title type="text">Milk</title><summary type="text">Low fat milk</summary><updated>2014-09-29T04:25:33Z</updated><author><name
293
+ /><title type="text">Milk</title><summary type="text">Low fat milk</summary><updated>2014-10-10T20:17:49Z</updated><author><name
243
294
  /></author><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
244
295
  type="application/xml" title="Categories" href="Products(1)/$links/Categories"
245
296
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -257,7 +308,7 @@ http_interactions:
257
308
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
258
309
  type="application/atom+xml;type=entry" title="ProductDetail" href="Products(2)/ProductDetail"
259
310
  /><title type="text">Vint soda</title><summary type="text">Americana Variety
260
- - Mix of 6 flavors</summary><updated>2014-09-29T04:25:33Z</updated><author><name
311
+ - Mix of 6 flavors</summary><updated>2014-10-10T20:17:49Z</updated><author><name
261
312
  /></author><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
262
313
  type="application/xml" title="Categories" href="Products(2)/$links/Categories"
263
314
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -275,7 +326,7 @@ http_interactions:
275
326
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
276
327
  type="application/atom+xml;type=entry" title="ProductDetail" href="Products(3)/ProductDetail"
277
328
  /><title type="text">Havina Cola</title><summary type="text">The Original
278
- Key Lime Cola</summary><updated>2014-09-29T04:25:33Z</updated><author><name
329
+ Key Lime Cola</summary><updated>2014-10-10T20:17:49Z</updated><author><name
279
330
  /></author><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
280
331
  type="application/xml" title="Categories" href="Products(3)/$links/Categories"
281
332
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -294,7 +345,7 @@ http_interactions:
294
345
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
295
346
  type="application/atom+xml;type=entry" title="ProductDetail" href="Products(4)/ProductDetail"
296
347
  /><title type="text">Fruit Punch</title><summary type="text">Mango flavor,
297
- 8.3 Ounce Cans (Pack of 24)</summary><updated>2014-09-29T04:25:33Z</updated><author><name
348
+ 8.3 Ounce Cans (Pack of 24)</summary><updated>2014-10-10T20:17:49Z</updated><author><name
298
349
  /></author><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
299
350
  type="application/xml" title="Categories" href="Products(4)/$links/Categories"
300
351
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -312,7 +363,7 @@ http_interactions:
312
363
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
313
364
  type="application/atom+xml;type=entry" title="ProductDetail" href="Products(5)/ProductDetail"
314
365
  /><title type="text">Cranberry Juice</title><summary type="text">16-Ounce
315
- Plastic Bottles (Pack of 12)</summary><updated>2014-09-29T04:25:33Z</updated><author><name
366
+ Plastic Bottles (Pack of 12)</summary><updated>2014-10-10T20:17:49Z</updated><author><name
316
367
  /></author><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
317
368
  type="application/xml" title="Categories" href="Products(5)/$links/Categories"
318
369
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -330,7 +381,7 @@ http_interactions:
330
381
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
331
382
  type="application/atom+xml;type=entry" title="ProductDetail" href="Products(6)/ProductDetail"
332
383
  /><title type="text">Pink Lemonade</title><summary type="text">36 Ounce Cans
333
- (Pack of 3)</summary><updated>2014-09-29T04:25:33Z</updated><author><name
384
+ (Pack of 3)</summary><updated>2014-10-10T20:17:49Z</updated><author><name
334
385
  /></author><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
335
386
  type="application/xml" title="Categories" href="Products(6)/$links/Categories"
336
387
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -348,7 +399,7 @@ http_interactions:
348
399
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
349
400
  type="application/atom+xml;type=entry" title="ProductDetail" href="Products(7)/ProductDetail"
350
401
  /><title type="text">DVD Player</title><summary type="text">1080P Upconversion
351
- DVD Player</summary><updated>2014-09-29T04:25:33Z</updated><author><name /></author><link
402
+ DVD Player</summary><updated>2014-10-10T20:17:49Z</updated><author><name /></author><link
352
403
  rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
353
404
  type="application/xml" title="Categories" href="Products(7)/$links/Categories"
354
405
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -366,7 +417,7 @@ http_interactions:
366
417
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail"
367
418
  type="application/atom+xml;type=entry" title="ProductDetail" href="Products(8)/ProductDetail"
368
419
  /><title type="text">LCD HDTV</title><summary type="text">42 inch 1080p LCD
369
- with Built-in Blu-ray Disc Player</summary><updated>2014-09-29T04:25:33Z</updated><author><name
420
+ with Built-in Blu-ray Disc Player</summary><updated>2014-10-10T20:17:49Z</updated><author><name
370
421
  /></author><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
371
422
  type="application/xml" title="Categories" href="Products(8)/$links/Categories"
372
423
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -387,7 +438,7 @@ http_interactions:
387
438
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Advertisement"
388
439
  type="application/atom+xml;type=entry" title="Advertisement" href="Products(9)/ODataDemo.FeaturedProduct/Advertisement"
389
440
  /><title type="text">Lemonade</title><summary type="text">Classic, refreshing
390
- lemonade (Single bottle)</summary><updated>2014-09-29T04:25:33Z</updated><author><name
441
+ lemonade (Single bottle)</summary><updated>2014-10-10T20:17:49Z</updated><author><name
391
442
  /></author><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
392
443
  type="application/xml" title="Categories" href="Products(9)/ODataDemo.FeaturedProduct/$links/Categories"
393
444
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -410,7 +461,7 @@ http_interactions:
410
461
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Advertisement"
411
462
  type="application/atom+xml;type=entry" title="Advertisement" href="Products(10)/ODataDemo.FeaturedProduct/Advertisement"
412
463
  /><title type="text">Coffee</title><summary type="text">Bulk size can of instant
413
- coffee</summary><updated>2014-09-29T04:25:33Z</updated><author><name /></author><link
464
+ coffee</summary><updated>2014-10-10T20:17:49Z</updated><author><name /></author><link
414
465
  rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories"
415
466
  type="application/xml" title="Categories" href="Products(10)/ODataDemo.FeaturedProduct/$links/Categories"
416
467
  /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier"
@@ -425,10 +476,10 @@ http_interactions:
425
476
  http_version: '1.1'
426
477
  adapter_metadata:
427
478
  effective_url: http://services.odata.org/OData/OData.svc/Products
428
- recorded_at: Mon, 29 Sep 2014 04:25:33 GMT
479
+ recorded_at: Fri, 10 Oct 2014 20:17:49 GMT
429
480
  - request:
430
481
  method: get
431
- uri: http://services.odata.org/OData/OData.svc/Products/$count
482
+ uri: http://services.odata.org/OData/OData.svc/Products/$count?$filter=Name%20eq%20'Bread'
432
483
  body:
433
484
  encoding: US-ASCII
434
485
  string: ''
@@ -445,7 +496,7 @@ http_interactions:
445
496
  Cache-Control:
446
497
  - no-cache
447
498
  Content-Length:
448
- - '2'
499
+ - '1'
449
500
  Content-Type:
450
501
  - text/plain;charset=utf-8
451
502
  Server:
@@ -467,14 +518,65 @@ http_interactions:
467
518
  Access-Control-Expose-Headers:
468
519
  - DataServiceVersion
469
520
  Set-Cookie:
470
- - ARRAffinity=cb44902b614a02a3a0dc1bccc3de360d89b180ff17e14b11fd9b289a8de75827;Path=/;Domain=services.odata.org
521
+ - ARRAffinity=f52a868fbb9bda30202dea2c82bfa2f9350871e50836757efd92afab45cf9549;Path=/;Domain=services.odata.org
471
522
  Date:
472
- - Mon, 29 Sep 2014 20:25:02 GMT
523
+ - Fri, 10 Oct 2014 20:20:16 GMT
473
524
  body:
474
525
  encoding: UTF-8
475
- string: '11'
526
+ string: '1'
527
+ http_version: '1.1'
528
+ adapter_metadata:
529
+ effective_url: http://services.odata.org/OData/OData.svc/Products/$count?$filter=Name%20eq%20'Bread'
530
+ recorded_at: Fri, 10 Oct 2014 20:20:15 GMT
531
+ - request:
532
+ method: get
533
+ uri: http://services.odata.org/OData/OData.svc/Products/$count?$filter=Name%20eq%20'NonExistent'
534
+ body:
535
+ encoding: US-ASCII
536
+ string: ''
537
+ headers:
538
+ User-Agent:
539
+ - Typhoeus - https://github.com/typhoeus/typhoeus
540
+ DataServiceVersion:
541
+ - '3.0'
542
+ response:
543
+ status:
544
+ code: 200
545
+ message: OK
546
+ headers:
547
+ Cache-Control:
548
+ - no-cache
549
+ Content-Length:
550
+ - '1'
551
+ Content-Type:
552
+ - text/plain;charset=utf-8
553
+ Server:
554
+ - Microsoft-IIS/8.0
555
+ X-Content-Type-Options:
556
+ - nosniff
557
+ DataServiceVersion:
558
+ - 2.0;
559
+ X-AspNet-Version:
560
+ - 4.0.30319
561
+ X-Powered-By:
562
+ - ASP.NET
563
+ Access-Control-Allow-Origin:
564
+ - "*"
565
+ Access-Control-Allow-Methods:
566
+ - GET
567
+ Access-Control-Allow-Headers:
568
+ - Accept, Origin, Content-Type, MaxDataServiceVersion
569
+ Access-Control-Expose-Headers:
570
+ - DataServiceVersion
571
+ Set-Cookie:
572
+ - ARRAffinity=f52a868fbb9bda30202dea2c82bfa2f9350871e50836757efd92afab45cf9549;Path=/;Domain=services.odata.org
573
+ Date:
574
+ - Fri, 10 Oct 2014 20:21:36 GMT
575
+ body:
576
+ encoding: UTF-8
577
+ string: '0'
476
578
  http_version: '1.1'
477
579
  adapter_metadata:
478
- effective_url: http://services.odata.org/OData/OData.svc/Products/$count
479
- recorded_at: Mon, 29 Sep 2014 20:25:03 GMT
580
+ effective_url: http://services.odata.org/OData/OData.svc/Products/$count?$filter=Name%20eq%20'NonExistent'
581
+ recorded_at: Fri, 10 Oct 2014 20:21:36 GMT
480
582
  recorded_with: VCR 2.9.2
@@ -95,13 +95,33 @@ describe OData::Query, vcr: {cassette_name: 'query_specs'} do
95
95
  end
96
96
  end
97
97
 
98
- it { expect(subject).to respond_to(:execute) }
99
98
  describe '#execute' do
99
+ it { expect(subject).to respond_to(:execute) }
100
100
  it { expect(subject.execute).to be_a(OData::Query::Result) }
101
101
  end
102
102
 
103
- it { expect(subject).to respond_to(:count) }
104
103
  describe '#count' do
104
+ it { expect(subject).to respond_to(:count) }
105
105
  it { expect(subject.count).to be_a(Integer) }
106
+ it { expect(subject.count).to eq(11) }
107
+
108
+ context 'with filters' do
109
+ let(:criteria) { subject[:Name].eq('Bread') }
110
+
111
+ it { expect(subject.where(criteria).count).to eq(1) }
112
+ end
113
+ end
114
+
115
+ describe '#empty?' do
116
+ it { expect(subject).to respond_to(:empty?) }
117
+ it { expect(subject.empty?).to eq(false) }
118
+
119
+ context 'with filters' do
120
+ let(:non_empty_criteria) { subject[:Name].eq('Bread') }
121
+ let(:empty_criteria) { subject[:Name].eq('NonExistent') }
122
+
123
+ it { expect(subject.where(non_empty_criteria).empty?).to eq(false) }
124
+ it { expect(subject.where(empty_criteria).empty?).to eq(true) }
125
+ end
106
126
  end
107
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.15
4
+ version: 0.6.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Thompson