odata 0.3.1 → 0.3.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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -13
- data/CHANGELOG.md +4 -0
- data/lib/odata.rb +2 -2
- data/lib/odata/entity.rb +64 -47
- data/lib/odata/entity_set.rb +17 -20
- data/lib/odata/properties/boolean.rb +5 -0
- data/lib/odata/properties/integer.rb +16 -24
- data/lib/odata/property.rb +22 -0
- data/lib/odata/query.rb +105 -41
- data/lib/odata/query/criteria.rb +54 -48
- data/lib/odata/service.rb +2 -2
- data/lib/odata/version.rb +1 -1
- data/odata.gemspec +1 -2
- data/spec/fixtures/vcr_cassettes/entity_set_specs.yml +952 -0
- data/spec/fixtures/vcr_cassettes/entity_set_specs/bad_entry.yml +220 -0
- data/spec/fixtures/vcr_cassettes/entity_set_specs/existing_entry.yml +313 -0
- data/spec/fixtures/vcr_cassettes/entity_set_specs/new_entry.yml +226 -0
- data/spec/fixtures/vcr_cassettes/entity_specs.yml +164 -0
- data/spec/fixtures/vcr_cassettes/query_specs.yml +164 -0
- data/spec/fixtures/vcr_cassettes/service_registry_specs.yml +164 -0
- data/spec/fixtures/vcr_cassettes/service_specs.yml +164 -0
- data/spec/odata/entity_set_spec.rb +22 -40
- data/spec/odata/entity_spec.rb +5 -5
- data/spec/odata/query/criteria_spec.rb +57 -24
- data/spec/odata/query_spec.rb +79 -40
- data/spec/odata/service_registry_spec.rb +1 -1
- data/spec/odata/service_spec.rb +1 -7
- data/spec/spec_helper.rb +9 -46
- metadata +21 -19
@@ -1,36 +1,69 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OData::Query::Criteria do
|
4
|
-
let(:subject) { OData::Query::Criteria.new(
|
5
|
-
let(:valid_operations) { [:filter, :order_by, :skip, :top, :select, :expand, :inline_count] }
|
4
|
+
let(:subject) { OData::Query::Criteria.new(property: :Name) }
|
6
5
|
|
7
|
-
it { expect(subject).to respond_to(:
|
8
|
-
it { expect(subject).to
|
6
|
+
it { expect(subject).to respond_to(:property) }
|
7
|
+
it { expect(subject.property).to eq(:Name)}
|
9
8
|
|
10
|
-
it { expect(subject
|
11
|
-
it { expect(subject
|
9
|
+
it { expect(subject).to respond_to(:operator) }
|
10
|
+
it { expect(subject).to respond_to(:value) }
|
11
|
+
it { expect(subject).to respond_to(:to_s) }
|
12
12
|
|
13
|
-
it
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
it { expect(subject).to respond_to(:eq) }
|
14
|
+
it { expect(subject).to respond_to(:ne) }
|
15
|
+
it { expect(subject).to respond_to(:gt) }
|
16
|
+
it { expect(subject).to respond_to(:ge) }
|
17
|
+
it { expect(subject).to respond_to(:lt) }
|
18
|
+
it { expect(subject).to respond_to(:le) }
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
describe 'operator method' do
|
21
|
+
it '#eq sets up criteria properly' do
|
22
|
+
criteria = subject.eq('Bread')
|
23
|
+
expect(criteria).to eq(subject)
|
24
|
+
expect(criteria.operator).to eq(:eq)
|
25
|
+
expect(criteria.value).to eq('Bread')
|
26
|
+
expect(criteria.to_s).to eq("Name eq 'Bread'")
|
27
|
+
end
|
28
|
+
|
29
|
+
it '#ne sets up criteria properly' do
|
30
|
+
criteria = subject.ne('Bread')
|
31
|
+
expect(criteria).to eq(subject)
|
32
|
+
expect(criteria.operator).to eq(:ne)
|
33
|
+
expect(criteria.value).to eq('Bread')
|
34
|
+
expect(criteria.to_s).to eq("Name ne 'Bread'")
|
35
|
+
end
|
24
36
|
|
25
|
-
|
26
|
-
|
27
|
-
expect
|
28
|
-
|
29
|
-
|
37
|
+
it '#gt sets up criteria properly' do
|
38
|
+
criteria = subject.gt(5)
|
39
|
+
expect(criteria).to eq(subject)
|
40
|
+
expect(criteria.operator).to eq(:gt)
|
41
|
+
expect(criteria.value).to eq(5)
|
42
|
+
expect(criteria.to_s).to eq('Name gt 5')
|
30
43
|
end
|
31
44
|
|
32
|
-
|
33
|
-
|
34
|
-
|
45
|
+
it '#ge sets up criteria properly' do
|
46
|
+
criteria = subject.ge(5)
|
47
|
+
expect(criteria).to eq(subject)
|
48
|
+
expect(criteria.operator).to eq(:ge)
|
49
|
+
expect(criteria.value).to eq(5)
|
50
|
+
expect(criteria.to_s).to eq('Name ge 5')
|
51
|
+
end
|
52
|
+
|
53
|
+
it '#lt sets up criteria properly' do
|
54
|
+
criteria = subject.lt(5)
|
55
|
+
expect(criteria).to eq(subject)
|
56
|
+
expect(criteria.operator).to eq(:lt)
|
57
|
+
expect(criteria.value).to eq(5)
|
58
|
+
expect(criteria.to_s).to eq('Name lt 5')
|
59
|
+
end
|
60
|
+
|
61
|
+
it '#le sets up criteria properly' do
|
62
|
+
criteria = subject.le(5)
|
63
|
+
expect(criteria).to eq(subject)
|
64
|
+
expect(criteria.operator).to eq(:le)
|
65
|
+
expect(criteria.value).to eq(5)
|
66
|
+
expect(criteria.to_s).to eq('Name le 5')
|
67
|
+
end
|
35
68
|
end
|
36
69
|
end
|
data/spec/odata/query_spec.rb
CHANGED
@@ -1,58 +1,97 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe OData::Query do
|
4
|
-
let(:subject) { OData::Query.new(
|
3
|
+
describe OData::Query, vcr: {cassette_name: 'query_specs'} do
|
4
|
+
let(:subject) { OData::Query.new(entity_set) }
|
5
|
+
let(:entity_set) { OData::EntitySet.new(options) }
|
6
|
+
let(:options) { {
|
7
|
+
container: 'DemoService', namespace: 'ODataDemo', name: 'Products',
|
8
|
+
type: 'Product'
|
9
|
+
} }
|
5
10
|
|
6
|
-
|
7
|
-
|
11
|
+
before(:example) do
|
12
|
+
OData::Service.open('http://services.odata.org/OData/OData.svc')
|
13
|
+
end
|
8
14
|
|
15
|
+
it { expect(subject).to respond_to(:to_s) }
|
9
16
|
it { expect(subject.to_s).to eq('Products')}
|
10
17
|
|
11
|
-
it
|
12
|
-
|
13
|
-
|
14
|
-
subject
|
15
|
-
subject << skip_criteria
|
16
|
-
expect(subject.to_s).to eq('Products?$skip=5&$top=5')
|
18
|
+
it { expect(subject).to respond_to(:[]) }
|
19
|
+
describe '#[]' do
|
20
|
+
it { expect(subject[:Name]).to be_a(OData::Query::Criteria) }
|
21
|
+
it { expect(subject[:Name].property).to eq(:Name) }
|
17
22
|
end
|
18
23
|
|
19
|
-
it
|
20
|
-
|
21
|
-
subject
|
22
|
-
|
24
|
+
it { expect(subject).to respond_to(:where) }
|
25
|
+
describe '#where' do
|
26
|
+
let(:criteria) { subject[:Name].eq('Bread') }
|
27
|
+
let(:query_string) { "Products?$filter=Name eq 'Bread'" }
|
28
|
+
|
29
|
+
it { expect(subject.where(criteria)).to eq(subject) }
|
30
|
+
it { expect(subject.where(criteria).to_s).to eq(query_string) }
|
31
|
+
end
|
32
|
+
|
33
|
+
#it { expect(subject).to respond_to(:and) }
|
34
|
+
describe '#and' do
|
35
|
+
it { pending; fail }
|
36
|
+
end
|
37
|
+
|
38
|
+
#it { expect(subject).to respond_to(:or) }
|
39
|
+
describe '#or' do
|
40
|
+
it { pending; fail }
|
41
|
+
end
|
42
|
+
|
43
|
+
it { expect(subject).to respond_to(:skip) }
|
44
|
+
describe '#skip' do
|
45
|
+
it { expect(subject.skip(5)).to eq(subject) }
|
46
|
+
it 'properly formats query with skip specified' do
|
47
|
+
subject.skip(5)
|
48
|
+
expect(subject.to_s).to eq('Products?$skip=5')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it { expect(subject).to respond_to(:limit) }
|
53
|
+
describe '#limit' do
|
54
|
+
|
55
|
+
it { expect(subject.limit(5)).to eq(subject) }
|
56
|
+
it 'properly formats query with limit specified' do
|
57
|
+
subject.limit(5)
|
58
|
+
expect(subject.to_s).to eq('Products?$top=5')
|
59
|
+
end
|
23
60
|
end
|
24
61
|
|
25
|
-
it
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
expect(subject.to_s).to eq('Products?$select=Name,Rating,Price')
|
62
|
+
it { expect(subject).to respond_to(:include_count) }
|
63
|
+
describe '#include_count' do
|
64
|
+
it { expect(subject.include_count).to eq(subject) }
|
65
|
+
it 'properly formats query with include_count specified' do
|
66
|
+
subject.include_count
|
67
|
+
expect(subject.to_s).to eq('Products?$inlinecount=allpages')
|
68
|
+
end
|
33
69
|
end
|
34
70
|
|
35
|
-
it
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
71
|
+
it { expect(subject).to respond_to(:select) }
|
72
|
+
describe '#select' do
|
73
|
+
it { expect(subject.select(:Name, :Price)).to eq(subject) }
|
74
|
+
it 'properly formats query with select operation specified' do
|
75
|
+
subject.select(:Name, :Price)
|
76
|
+
expect(subject.to_s).to eq('Products?$select=Name,Price')
|
77
|
+
end
|
41
78
|
end
|
42
79
|
|
43
|
-
it
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
80
|
+
it { expect(subject).to respond_to(:expand) }
|
81
|
+
describe '#expand' do
|
82
|
+
it { expect(subject.expand(:Supplier)).to eq(subject) }
|
83
|
+
it 'properly formats query with expand operation specified' do
|
84
|
+
subject.expand(:Supplier)
|
85
|
+
expect(subject.to_s).to eq('Products?$expand=Supplier')
|
86
|
+
end
|
49
87
|
end
|
50
88
|
|
51
|
-
it
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
89
|
+
it { expect(subject).to respond_to(:order_by) }
|
90
|
+
describe '#order_by' do
|
91
|
+
it { expect(subject.order_by(:Name, :Price)).to eq(subject) }
|
92
|
+
it 'properly formats query with orderby operation specified' do
|
93
|
+
subject.order_by(:Name, :Price)
|
94
|
+
expect(subject.to_s).to eq('Products?$orderby=Name,Price')
|
95
|
+
end
|
57
96
|
end
|
58
97
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe OData::ServiceRegistry do
|
3
|
+
describe OData::ServiceRegistry, vcr: {cassette_name: 'service_registry_specs'} do
|
4
4
|
let(:subject) { OData::ServiceRegistry }
|
5
5
|
let(:sample_service) { OData::Service.open('http://services.odata.org/OData/OData.svc') }
|
6
6
|
|
data/spec/odata/service_spec.rb
CHANGED
@@ -1,18 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe OData::Service do
|
3
|
+
describe OData::Service, vcr: {cassette_name: 'service_specs'} do
|
4
4
|
let(:subject) { OData::Service.open('http://services.odata.org/OData/OData.svc') }
|
5
5
|
let(:entity_types) { %w{Product FeaturedProduct ProductDetail Category Supplier Person Customer Employee PersonDetail Advertisement} }
|
6
6
|
let(:entity_sets) { %w{Products ProductDetails Categories Suppliers Persons PersonDetails Advertisements} }
|
7
7
|
let(:entity_set_types) { %w{Product ProductDetail Category Supplier Person PersonDetail Advertisement} }
|
8
8
|
let(:complex_types) { %w{Address} }
|
9
9
|
|
10
|
-
# We're calling this as a private method because there should not be any
|
11
|
-
# reasons to have to flush the service registry except in testing.
|
12
|
-
after :each do
|
13
|
-
OData::ServiceRegistry.instance.send(:flush)
|
14
|
-
end
|
15
|
-
|
16
10
|
describe '.open' do
|
17
11
|
it { expect(OData::Service).to respond_to(:open) }
|
18
12
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,14 +10,16 @@ end
|
|
10
10
|
|
11
11
|
require 'odata'
|
12
12
|
|
13
|
-
require '
|
14
|
-
if ENV['REAL_HTTP'] == 'true'
|
15
|
-
WebMock.allow_net_connect!
|
16
|
-
else
|
17
|
-
WebMock.disable_net_connect!(allow_localhost: true, allow: 'codeclimate.com')
|
18
|
-
end
|
19
|
-
|
13
|
+
require 'securerandom'
|
20
14
|
require 'timecop'
|
15
|
+
require 'vcr'
|
16
|
+
|
17
|
+
VCR.configure do |c|
|
18
|
+
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
19
|
+
c.hook_into :typhoeus
|
20
|
+
c.default_cassette_options = { record: :new_episodes, erb: true }
|
21
|
+
c.configure_rspec_metadata!
|
22
|
+
end
|
21
23
|
|
22
24
|
RSpec.configure do |config|
|
23
25
|
if config.files_to_run.one?
|
@@ -26,7 +28,6 @@ RSpec.configure do |config|
|
|
26
28
|
|
27
29
|
config.profile_examples = 3
|
28
30
|
config.order = :random
|
29
|
-
Kernel.srand config.seed
|
30
31
|
|
31
32
|
config.expect_with :rspec do |expectations|
|
32
33
|
expectations.syntax = :expect
|
@@ -37,47 +38,9 @@ RSpec.configure do |config|
|
|
37
38
|
mocks.verify_partial_doubles = true
|
38
39
|
end
|
39
40
|
|
40
|
-
config.before(:example) do
|
41
|
-
unless ENV['REAL_HTTP'] == 'true'
|
42
|
-
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/$metadata').
|
43
|
-
to_return(status: 200, body: File.open('spec/fixtures/sample_service/metadata.xml'))
|
44
|
-
|
45
|
-
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products').
|
46
|
-
to_return(status: 200, body: File.open('spec/fixtures/sample_service/products.xml'))
|
47
|
-
|
48
|
-
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products?$inlinecount=allpages&$skip=0&$top=5').
|
49
|
-
to_return(status: 200, body: File.open('spec/fixtures/sample_service/products_skip0_top5.xml'))
|
50
|
-
|
51
|
-
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products?$inlinecount=allpages&$skip=5&$top=5').
|
52
|
-
to_return(status: 200, body: File.open('spec/fixtures/sample_service/products_skip5_top5.xml'))
|
53
|
-
|
54
|
-
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products?$inlinecount=allpages&$skip=10&$top=5').
|
55
|
-
to_return(status: 200, body: File.open('spec/fixtures/sample_service/products_skip10_top5.xml'))
|
56
|
-
|
57
|
-
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products?$skip=0&$top=1').
|
58
|
-
to_return(status: 200, body: File.open('spec/fixtures/sample_service/first_product.xml'))
|
59
|
-
|
60
|
-
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products/$count').
|
61
|
-
to_return(status: 200, :body => '11')
|
62
|
-
|
63
|
-
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products(0)').
|
64
|
-
to_return(status: 200, body: File.open('spec/fixtures/sample_service/product_0.xml'))
|
65
|
-
|
66
|
-
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products(99)').
|
67
|
-
to_return(status: 404, body: File.open('spec/fixtures/sample_service/product_not_found.xml'))
|
68
|
-
|
69
|
-
WebMock.stub_request(:get, "http://services.odata.org/OData/OData.svc/Products?$filter=Name eq 'Bread'").
|
70
|
-
to_return(status: 200, body: File.open('spec/fixtures/sample_service/product_filter_one.xml'))
|
71
|
-
|
72
|
-
WebMock.stub_request(:get, 'http://services.odata.org/OData/OData.svc/Products?$filter=Rating%20eq%203').
|
73
|
-
to_return(status: 200, body: File.open('spec/fixtures/sample_service/product_filter_many.xml'))
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
41
|
config.after(:example) do
|
78
42
|
# We're calling this as a private method because there should not be any
|
79
43
|
# reasons to have to flush the service registry except in testing.
|
80
44
|
OData::ServiceRegistry.instance.send(:flush)
|
81
|
-
WebMock.reset!
|
82
45
|
end
|
83
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,19 +81,19 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.0.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: vcr
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 2.9.2
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 2.9.2
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: timecop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 0.7.1
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: backports
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 3.6.0
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 3.6.0
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: nokogiri
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,6 +186,14 @@ files:
|
|
200
186
|
- spec/fixtures/sample_service/products_skip0_top5.xml
|
201
187
|
- spec/fixtures/sample_service/products_skip10_top5.xml
|
202
188
|
- spec/fixtures/sample_service/products_skip5_top5.xml
|
189
|
+
- spec/fixtures/vcr_cassettes/entity_set_specs.yml
|
190
|
+
- spec/fixtures/vcr_cassettes/entity_set_specs/bad_entry.yml
|
191
|
+
- spec/fixtures/vcr_cassettes/entity_set_specs/existing_entry.yml
|
192
|
+
- spec/fixtures/vcr_cassettes/entity_set_specs/new_entry.yml
|
193
|
+
- spec/fixtures/vcr_cassettes/entity_specs.yml
|
194
|
+
- spec/fixtures/vcr_cassettes/query_specs.yml
|
195
|
+
- spec/fixtures/vcr_cassettes/service_registry_specs.yml
|
196
|
+
- spec/fixtures/vcr_cassettes/service_specs.yml
|
203
197
|
- spec/odata/entity_set_spec.rb
|
204
198
|
- spec/odata/entity_spec.rb
|
205
199
|
- spec/odata/properties/binary_spec.rb
|
@@ -254,6 +248,14 @@ test_files:
|
|
254
248
|
- spec/fixtures/sample_service/products_skip0_top5.xml
|
255
249
|
- spec/fixtures/sample_service/products_skip10_top5.xml
|
256
250
|
- spec/fixtures/sample_service/products_skip5_top5.xml
|
251
|
+
- spec/fixtures/vcr_cassettes/entity_set_specs.yml
|
252
|
+
- spec/fixtures/vcr_cassettes/entity_set_specs/bad_entry.yml
|
253
|
+
- spec/fixtures/vcr_cassettes/entity_set_specs/existing_entry.yml
|
254
|
+
- spec/fixtures/vcr_cassettes/entity_set_specs/new_entry.yml
|
255
|
+
- spec/fixtures/vcr_cassettes/entity_specs.yml
|
256
|
+
- spec/fixtures/vcr_cassettes/query_specs.yml
|
257
|
+
- spec/fixtures/vcr_cassettes/service_registry_specs.yml
|
258
|
+
- spec/fixtures/vcr_cassettes/service_specs.yml
|
257
259
|
- spec/odata/entity_set_spec.rb
|
258
260
|
- spec/odata/entity_spec.rb
|
259
261
|
- spec/odata/properties/binary_spec.rb
|