frodata 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +2 -0
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +75 -0
- data/CHANGELOG.md +150 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +427 -0
- data/Rakefile +7 -0
- data/TODO.md +55 -0
- data/frodata.gemspec +34 -0
- data/lib/frodata.rb +36 -0
- data/lib/frodata/entity.rb +332 -0
- data/lib/frodata/entity_container.rb +75 -0
- data/lib/frodata/entity_set.rb +161 -0
- data/lib/frodata/errors.rb +68 -0
- data/lib/frodata/navigation_property.rb +29 -0
- data/lib/frodata/navigation_property/proxy.rb +80 -0
- data/lib/frodata/properties.rb +32 -0
- data/lib/frodata/properties/binary.rb +50 -0
- data/lib/frodata/properties/boolean.rb +37 -0
- data/lib/frodata/properties/collection.rb +50 -0
- data/lib/frodata/properties/complex.rb +114 -0
- data/lib/frodata/properties/date.rb +27 -0
- data/lib/frodata/properties/date_time.rb +83 -0
- data/lib/frodata/properties/date_time_offset.rb +17 -0
- data/lib/frodata/properties/decimal.rb +50 -0
- data/lib/frodata/properties/enum.rb +62 -0
- data/lib/frodata/properties/float.rb +67 -0
- data/lib/frodata/properties/geography.rb +13 -0
- data/lib/frodata/properties/geography/base.rb +162 -0
- data/lib/frodata/properties/geography/line_string.rb +33 -0
- data/lib/frodata/properties/geography/point.rb +31 -0
- data/lib/frodata/properties/geography/polygon.rb +38 -0
- data/lib/frodata/properties/guid.rb +17 -0
- data/lib/frodata/properties/integer.rb +107 -0
- data/lib/frodata/properties/number.rb +14 -0
- data/lib/frodata/properties/string.rb +72 -0
- data/lib/frodata/properties/time.rb +40 -0
- data/lib/frodata/properties/time_of_day.rb +27 -0
- data/lib/frodata/property.rb +139 -0
- data/lib/frodata/property_registry.rb +41 -0
- data/lib/frodata/query.rb +233 -0
- data/lib/frodata/query/criteria.rb +92 -0
- data/lib/frodata/query/criteria/comparison_operators.rb +49 -0
- data/lib/frodata/query/criteria/date_functions.rb +61 -0
- data/lib/frodata/query/criteria/geography_functions.rb +21 -0
- data/lib/frodata/query/criteria/lambda_operators.rb +27 -0
- data/lib/frodata/query/criteria/string_functions.rb +40 -0
- data/lib/frodata/query/in_batches.rb +58 -0
- data/lib/frodata/railtie.rb +19 -0
- data/lib/frodata/schema.rb +155 -0
- data/lib/frodata/schema/complex_type.rb +79 -0
- data/lib/frodata/schema/enum_type.rb +95 -0
- data/lib/frodata/service.rb +254 -0
- data/lib/frodata/service/request.rb +85 -0
- data/lib/frodata/service/response.rb +162 -0
- data/lib/frodata/service/response/atom.rb +40 -0
- data/lib/frodata/service/response/json.rb +41 -0
- data/lib/frodata/service/response/plain.rb +36 -0
- data/lib/frodata/service/response/xml.rb +40 -0
- data/lib/frodata/service_registry.rb +52 -0
- data/lib/frodata/version.rb +3 -0
- data/spec/fixtures/files/entity_to_xml.xml +17 -0
- data/spec/fixtures/files/error.xml +5 -0
- data/spec/fixtures/files/metadata.xml +150 -0
- data/spec/fixtures/files/product_0.json +10 -0
- data/spec/fixtures/files/product_0.xml +28 -0
- data/spec/fixtures/files/products.json +106 -0
- data/spec/fixtures/files/products.xml +308 -0
- data/spec/fixtures/files/supplier_0.json +26 -0
- data/spec/fixtures/files/supplier_0.xml +32 -0
- data/spec/fixtures/vcr_cassettes/entity_set_specs.yml +1635 -0
- data/spec/fixtures/vcr_cassettes/entity_set_specs/bad_entry.yml +183 -0
- data/spec/fixtures/vcr_cassettes/entity_set_specs/existing_entry.yml +256 -0
- data/spec/fixtures/vcr_cassettes/entity_set_specs/new_entry.yml +185 -0
- data/spec/fixtures/vcr_cassettes/entity_specs.yml +285 -0
- data/spec/fixtures/vcr_cassettes/navigation_property_proxy_specs.yml +346 -0
- data/spec/fixtures/vcr_cassettes/query/result_specs.yml +189 -0
- data/spec/fixtures/vcr_cassettes/query_specs.yml +1060 -0
- data/spec/fixtures/vcr_cassettes/schema/complex_type_specs.yml +127 -0
- data/spec/fixtures/vcr_cassettes/service/request_specs.yml +193 -0
- data/spec/fixtures/vcr_cassettes/service_registry_specs.yml +129 -0
- data/spec/fixtures/vcr_cassettes/service_specs.yml +127 -0
- data/spec/fixtures/vcr_cassettes/usage_example_specs.yml +1330 -0
- data/spec/frodata/entity/shared_examples.rb +82 -0
- data/spec/frodata/entity_container_spec.rb +38 -0
- data/spec/frodata/entity_set_spec.rb +168 -0
- data/spec/frodata/entity_spec.rb +151 -0
- data/spec/frodata/errors_spec.rb +48 -0
- data/spec/frodata/navigation_property/proxy_spec.rb +44 -0
- data/spec/frodata/navigation_property_spec.rb +55 -0
- data/spec/frodata/properties/binary_spec.rb +50 -0
- data/spec/frodata/properties/boolean_spec.rb +72 -0
- data/spec/frodata/properties/collection_spec.rb +44 -0
- data/spec/frodata/properties/date_spec.rb +23 -0
- data/spec/frodata/properties/date_time_offset_spec.rb +30 -0
- data/spec/frodata/properties/date_time_spec.rb +23 -0
- data/spec/frodata/properties/decimal_spec.rb +51 -0
- data/spec/frodata/properties/float_spec.rb +45 -0
- data/spec/frodata/properties/geography/line_string_spec.rb +33 -0
- data/spec/frodata/properties/geography/point_spec.rb +29 -0
- data/spec/frodata/properties/geography/polygon_spec.rb +55 -0
- data/spec/frodata/properties/geography/shared_examples.rb +72 -0
- data/spec/frodata/properties/guid_spec.rb +17 -0
- data/spec/frodata/properties/integer_spec.rb +58 -0
- data/spec/frodata/properties/string_spec.rb +46 -0
- data/spec/frodata/properties/time_of_day_spec.rb +23 -0
- data/spec/frodata/properties/time_spec.rb +15 -0
- data/spec/frodata/property_registry_spec.rb +16 -0
- data/spec/frodata/property_spec.rb +71 -0
- data/spec/frodata/query/criteria_spec.rb +229 -0
- data/spec/frodata/query_spec.rb +199 -0
- data/spec/frodata/schema/complex_type_spec.rb +96 -0
- data/spec/frodata/schema/enum_type_spec.rb +112 -0
- data/spec/frodata/schema_spec.rb +97 -0
- data/spec/frodata/service/request_spec.rb +49 -0
- data/spec/frodata/service/response_spec.rb +85 -0
- data/spec/frodata/service_registry_spec.rb +18 -0
- data/spec/frodata/service_spec.rb +191 -0
- data/spec/frodata/usage_example_spec.rb +188 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/coverage.rb +2 -0
- data/spec/support/vcr.rb +9 -0
- metadata +401 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrOData::NavigationProperty::Proxy, vcr: {cassette_name: 'navigation_property_proxy_specs'} do
|
4
|
+
before :each do
|
5
|
+
FrOData::Service.new('http://services.odata.org/V4/OData/OData.svc', name: 'ODataDemo')
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:entity) { FrOData::ServiceRegistry['ODataDemo']['Products'][1] }
|
9
|
+
|
10
|
+
let(:categories_proxy) { FrOData::NavigationProperty::Proxy.new(entity, 'Categories') }
|
11
|
+
let(:detail_proxy) { FrOData::NavigationProperty::Proxy.new(entity, 'ProductDetail') }
|
12
|
+
let(:supplier_proxy) { FrOData::NavigationProperty::Proxy.new(entity, 'Supplier') }
|
13
|
+
|
14
|
+
describe 'value' do
|
15
|
+
it { expect(categories_proxy.value).to be_a(Enumerable) }
|
16
|
+
it { expect(supplier_proxy.value).to be_a(FrOData::Entity) }
|
17
|
+
it { expect(detail_proxy.value).to be_a(FrOData::Entity) }
|
18
|
+
|
19
|
+
context 'when value was explicitly set' do
|
20
|
+
let(:supplier) { double('supplier') }
|
21
|
+
|
22
|
+
it 'returns the set value' do
|
23
|
+
supplier_proxy.value = supplier
|
24
|
+
expect(supplier_proxy.value).to eq(supplier)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when no links exist for an entity' do
|
29
|
+
before(:each) do
|
30
|
+
expect(entity).to receive(:links) do
|
31
|
+
{ 'Categories' => nil, 'Supplier' => nil }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'for a many NavigationProperty' do
|
36
|
+
it { expect(categories_proxy.value).to eq([]) }
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'for a singular NavigationProperty' do
|
40
|
+
it { expect(supplier_proxy.value).to eq(nil) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrOData::NavigationProperty do
|
4
|
+
let(:options) { {
|
5
|
+
name: 'Categories',
|
6
|
+
type: 'Collection(ODataDemo.Category)',
|
7
|
+
partner: 'Products',
|
8
|
+
} }
|
9
|
+
let(:subject) do
|
10
|
+
FrOData::NavigationProperty.new(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
it { expect(subject).to respond_to(:name) }
|
14
|
+
it { expect(subject.name).to eq('Categories') }
|
15
|
+
|
16
|
+
it { expect(subject).to respond_to(:type) }
|
17
|
+
it { expect(subject.type).to eq('Collection(ODataDemo.Category)') }
|
18
|
+
|
19
|
+
it { expect(subject).to respond_to(:nav_type) }
|
20
|
+
it { expect(subject.nav_type).to eq(:collection) }
|
21
|
+
|
22
|
+
it { expect(subject).to respond_to(:nullable) }
|
23
|
+
|
24
|
+
it { expect(subject).to respond_to(:partner) }
|
25
|
+
it { expect(subject.partner).to eq('Products') }
|
26
|
+
|
27
|
+
describe '.new' do
|
28
|
+
it 'requires name' do
|
29
|
+
expect {
|
30
|
+
FrOData::NavigationProperty.new(type: 'Collection(ODataDemo.Category)')
|
31
|
+
}.to raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'requires type' do
|
35
|
+
expect {
|
36
|
+
FrOData::NavigationProperty.new(name: 'Categories')
|
37
|
+
}.to raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#build' do
|
42
|
+
let(:metadata_file) { File.read 'spec/fixtures/files/metadata.xml' }
|
43
|
+
let(:metadata_xml) { Nokogiri::XML(metadata_file).remove_namespaces! }
|
44
|
+
let(:navigation_properties) { metadata_xml.xpath('//NavigationProperty') }
|
45
|
+
let(:subject) {
|
46
|
+
FrOData::NavigationProperty.build(navigation_properties.first)
|
47
|
+
}
|
48
|
+
|
49
|
+
it { expect(subject.name).to eq('Categories') }
|
50
|
+
it { expect(subject.type).to eq('Collection(ODataDemo.Category)') }
|
51
|
+
it { expect(subject.partner).to eq('Products') }
|
52
|
+
it { expect(subject.nullable).to eq(true) }
|
53
|
+
it { expect(subject.nav_type).to eq(:collection) }
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrOData::Properties::Binary do
|
4
|
+
let(:subject) { FrOData::Properties::Binary.new('On', '1') }
|
5
|
+
|
6
|
+
it { expect(subject.type).to eq('Edm.Binary') }
|
7
|
+
it { expect(subject.value).to eq(1) }
|
8
|
+
|
9
|
+
it { expect {subject.value = 'bad'}.to raise_error(ArgumentError) }
|
10
|
+
|
11
|
+
it { expect(subject.url_value).to eq("binary'1'") }
|
12
|
+
|
13
|
+
describe 'setting to 0' do
|
14
|
+
it { expect(lambda {
|
15
|
+
subject.value = 0
|
16
|
+
subject.value
|
17
|
+
}.call).to eq(0) }
|
18
|
+
|
19
|
+
it { expect(lambda {
|
20
|
+
subject.value = false
|
21
|
+
subject.value
|
22
|
+
}.call).to eq(0) }
|
23
|
+
|
24
|
+
it { expect(lambda {
|
25
|
+
subject.value = '0'
|
26
|
+
subject.value
|
27
|
+
}.call).to eq(0) }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'setting to 1' do
|
31
|
+
let(:subject) { FrOData::Properties::Binary.new('On', '0') }
|
32
|
+
|
33
|
+
it { expect(subject.value).to eq(0) }
|
34
|
+
|
35
|
+
it { expect(lambda {
|
36
|
+
subject.value = 1
|
37
|
+
subject.value
|
38
|
+
}.call).to eq(1) }
|
39
|
+
|
40
|
+
it { expect(lambda {
|
41
|
+
subject.value = true
|
42
|
+
subject.value
|
43
|
+
}.call).to eq(1) }
|
44
|
+
|
45
|
+
it { expect(lambda {
|
46
|
+
subject.value = '1'
|
47
|
+
subject.value
|
48
|
+
}.call).to eq(1) }
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrOData::Properties::Boolean do
|
4
|
+
let(:truthy1) { FrOData::Properties::Boolean.new('Truthy', 'true') }
|
5
|
+
let(:truthy2) { FrOData::Properties::Boolean.new('Truthy', '1') }
|
6
|
+
let(:falsey1) { FrOData::Properties::Boolean.new('Falsey', 'false') }
|
7
|
+
let(:falsey2) { FrOData::Properties::Boolean.new('Falsey', '0') }
|
8
|
+
let(:nily) { FrOData::Properties::Boolean.new('Nily', nil) }
|
9
|
+
|
10
|
+
it { expect(truthy1.type).to eq('Edm.Boolean') }
|
11
|
+
it { expect(truthy1.value).to eq(true) }
|
12
|
+
it { expect(truthy2.value).to eq(true) }
|
13
|
+
|
14
|
+
it { expect(falsey1.value).to eq(false) }
|
15
|
+
it { expect(falsey2.value).to eq(false) }
|
16
|
+
|
17
|
+
it { expect(nily.value).to eq(nil) }
|
18
|
+
|
19
|
+
it { expect {truthy1.value = 'bad'}.to raise_error(ArgumentError) }
|
20
|
+
|
21
|
+
describe 'setting to false' do
|
22
|
+
let(:subject) { FrOData::Properties::Boolean.new('Truthy', 'true') }
|
23
|
+
|
24
|
+
it { expect(subject.value).to eq(true) }
|
25
|
+
|
26
|
+
it { expect(lambda {
|
27
|
+
subject.value = false
|
28
|
+
subject.value
|
29
|
+
}.call).to eq(false) }
|
30
|
+
|
31
|
+
it { expect(lambda {
|
32
|
+
subject.value = 'false'
|
33
|
+
subject.value
|
34
|
+
}.call).to eq(false) }
|
35
|
+
|
36
|
+
it { expect(lambda {
|
37
|
+
subject.value = '0'
|
38
|
+
subject.value
|
39
|
+
}.call).to eq(false) }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'setting to true' do
|
43
|
+
let(:subject) { FrOData::Properties::Boolean.new('Falsey', 'false') }
|
44
|
+
|
45
|
+
it { expect(subject.value).to eq(false) }
|
46
|
+
|
47
|
+
it { expect(lambda {
|
48
|
+
subject.value = true
|
49
|
+
subject.value
|
50
|
+
}.call).to eq(true) }
|
51
|
+
|
52
|
+
it { expect(lambda {
|
53
|
+
subject.value = 'true'
|
54
|
+
subject.value
|
55
|
+
}.call).to eq(true) }
|
56
|
+
|
57
|
+
it { expect(lambda {
|
58
|
+
subject.value = '1'
|
59
|
+
subject.value
|
60
|
+
}.call).to eq(true) }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'setting to null' do
|
64
|
+
let(:subject) { FrOData::Properties::Boolean.new('Truthy', 'true') }
|
65
|
+
|
66
|
+
it { expect(subject.allows_nil?).to eq(true) }
|
67
|
+
it { expect(lambda {
|
68
|
+
subject.value = nil
|
69
|
+
subject.value
|
70
|
+
}.call).to eq(nil) }
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrOData::Properties::Collection do
|
4
|
+
let(:subject) { FrOData::Properties::Collection.new('Names', names) }
|
5
|
+
let(:names) { %w[Dan Greg Jon] }
|
6
|
+
let(:new_names) { %w[Andrew Doug Paul] }
|
7
|
+
|
8
|
+
it { expect(subject.type).to eq('Collection(Edm.String)') }
|
9
|
+
it { expect(subject.value).to eq(['Dan', 'Greg', 'Jon']) }
|
10
|
+
it { expect(subject.url_value).to eq("['Dan','Greg','Jon']") }
|
11
|
+
|
12
|
+
describe '#value=' do
|
13
|
+
it 'allows an array of string values to be set' do
|
14
|
+
subject.value = new_names
|
15
|
+
expect(subject.value).to eq(new_names)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# TODO: Make collection type work properly with data types other than string
|
20
|
+
xcontext 'with value type other than Edm.String' do
|
21
|
+
let(:subject) { FrOData::Properties::Collection.new('Bits', [1, 0, 1], value_type: 'Edm.Binary') }
|
22
|
+
|
23
|
+
it { expect(subject.type).to eq('Collection(Edm.Int32)') }
|
24
|
+
it { expect(subject.value).to eq([1, 0, 1]) }
|
25
|
+
it { expect(subject.url_value).to eq('[1,0,1]') }
|
26
|
+
|
27
|
+
it 'does not allow other property types to be set' do
|
28
|
+
expect {
|
29
|
+
subject.value = names
|
30
|
+
}.to raise_error(ArgumentError)
|
31
|
+
end
|
32
|
+
|
33
|
+
xdescribe 'lenient validation' do
|
34
|
+
let(:subject) do
|
35
|
+
FrOData::Properties::Collection.new('Names', names, value_type: 'Edm.String', strict: false)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'ignores invalid values' do
|
39
|
+
subject.value = [1, 2, 3]
|
40
|
+
expect(subject.value).to eq([])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrOData::Properties::Date do
|
4
|
+
let(:subject) { FrOData::Properties::Date.new('Date', '2000-01-01') }
|
5
|
+
let(:new_date) { Date.strptime('2004-05-01', '%Y-%m-%d') }
|
6
|
+
|
7
|
+
it { expect(subject.type).to eq('Edm.Date') }
|
8
|
+
it { expect(subject.value).to eq(Date.parse('2000-01-01')) }
|
9
|
+
|
10
|
+
it { expect(subject.url_value).to eq("2000-01-01")}
|
11
|
+
|
12
|
+
it { expect {subject.value = 'bad'}.to raise_error(ArgumentError) }
|
13
|
+
|
14
|
+
it { expect(lambda {
|
15
|
+
subject.value = '2004-05-01'
|
16
|
+
subject.value
|
17
|
+
}.call).to eq(new_date) }
|
18
|
+
|
19
|
+
it { expect(lambda {
|
20
|
+
subject.value = new_date
|
21
|
+
subject.value
|
22
|
+
}.call).to eq(new_date) }
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrOData::Properties::DateTimeOffset do
|
4
|
+
let(:subject) { FrOData::Properties::DateTimeOffset.new('DateTime', '2000-01-01T16:00:00-09:00') }
|
5
|
+
let(:new_datetime) { DateTime.strptime('2004-05-01T14:32:00+02:00', '%Y-%m-%dT%H:%M:%S%:z') }
|
6
|
+
|
7
|
+
it { expect(subject.type).to eq('Edm.DateTimeOffset') }
|
8
|
+
it { expect(subject.value).to eq(DateTime.strptime('2000-01-01T16:00:00-09:00', '%Y-%m-%dT%H:%M:%S%:z')) }
|
9
|
+
|
10
|
+
it { expect(subject.url_value).to eq("2000-01-01T16:00:00-09:00")}
|
11
|
+
|
12
|
+
it { expect {subject.value = 'bad'}.to raise_error(ArgumentError) }
|
13
|
+
|
14
|
+
it { expect(lambda {
|
15
|
+
subject.value = new_datetime
|
16
|
+
subject.value
|
17
|
+
}.call).to eq(new_datetime) }
|
18
|
+
|
19
|
+
it { expect(lambda {
|
20
|
+
subject.value = nil
|
21
|
+
}).not_to raise_error }
|
22
|
+
|
23
|
+
context 'with allows_nil option set to false' do
|
24
|
+
let(:subject) { FrOData::Properties::DateTimeOffset.new('DateTime', '2000-01-01T16:00:00Z-09:00', allows_nil: false) }
|
25
|
+
|
26
|
+
it { expect(lambda {
|
27
|
+
subject.value = nil
|
28
|
+
}).to raise_error(ArgumentError) }
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrOData::Properties::DateTime do
|
4
|
+
let(:subject) { FrOData::Properties::DateTime.new('DateTime', '2000-01-01T16:00:00.000') }
|
5
|
+
let(:new_datetime) { DateTime.strptime('2004-05-01T14:32:00.000', '%Y-%m-%dT%H:%M:%S.%L') }
|
6
|
+
|
7
|
+
it { expect(subject.type).to eq('Edm.DateTime') }
|
8
|
+
it { expect(subject.value).to eq(DateTime.parse('2000-01-01T16:00:00.000')) }
|
9
|
+
|
10
|
+
it { expect(subject.url_value).to eq("2000-01-01T16:00:00.000")}
|
11
|
+
|
12
|
+
it { expect {subject.value = 'bad'}.to raise_error(ArgumentError) }
|
13
|
+
|
14
|
+
it { expect(lambda {
|
15
|
+
subject.value = '2004-05-01T14:32:00.000'
|
16
|
+
subject.value
|
17
|
+
}.call).to eq(new_datetime) }
|
18
|
+
|
19
|
+
it { expect(lambda {
|
20
|
+
subject.value = new_datetime
|
21
|
+
subject.value
|
22
|
+
}.call).to eq(new_datetime) }
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrOData::Properties::Decimal do
|
4
|
+
let(:subject) { FrOData::Properties::Decimal.new('Decimal', '678.90325') }
|
5
|
+
|
6
|
+
it { expect(subject.type).to eq('Edm.Decimal') }
|
7
|
+
it { expect(subject.value).to eq(BigDecimal('678.90325')) }
|
8
|
+
|
9
|
+
it { expect(subject.url_value).to eq('678.90325') }
|
10
|
+
|
11
|
+
it { expect { subject.value = BigDecimal((7.9 * (10**28)), 2) + 1 }.to raise_error(ArgumentError) }
|
12
|
+
it { expect { subject.value = BigDecimal((-7.9 * (10**28)), 2) - 1 }.to raise_error(ArgumentError) }
|
13
|
+
it { expect { subject.value = BigDecimal((3.4 * (10**-28)), 2) * 3.14151 + 5 }.to raise_error(ArgumentError) }
|
14
|
+
|
15
|
+
describe '#value=' do
|
16
|
+
it 'allows BigDecimal to be set' do
|
17
|
+
subject.value = BigDecimal('19.89043256')
|
18
|
+
expect(subject.value).to eq(BigDecimal('19.89043256'))
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'allows string value to be set' do
|
22
|
+
subject.value = '19.89043256'
|
23
|
+
expect(subject.value).to eq(BigDecimal('19.89043256'))
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'ignores invalid characters' do
|
27
|
+
subject.value = '123.4-foobar-5'
|
28
|
+
expect(subject.value).to eq(BigDecimal('123.4'))
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'inteprets anything that is not a number as 0' do
|
32
|
+
subject.value = 'foobar'
|
33
|
+
expect(subject.value).to eq(BigDecimal(0))
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'does not allow values outside a certain range' do
|
37
|
+
expect { subject.value = 'Infinity' }.to raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'lenient validation' do
|
41
|
+
let(:subject) do
|
42
|
+
FrOData::Properties::Decimal.new('Decimal', '678.90325', strict: false)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'ignores invalid values' do
|
46
|
+
subject.value = 'Infinity'
|
47
|
+
expect(subject.value).to eq(BigDecimal('Infinity'))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrOData::Properties::Float do
|
4
|
+
describe 'double precision' do
|
5
|
+
let(:subject) { FrOData::Properties::Double.new('Float', '678.90325') }
|
6
|
+
|
7
|
+
it { expect(subject.type).to eq('Edm.Double') }
|
8
|
+
it { expect(subject.value).to eq(678.90325) }
|
9
|
+
|
10
|
+
it { expect { subject.value = (1.7 * (10**308) * 2) }.to raise_error(ArgumentError) }
|
11
|
+
it { expect { subject.value = (-1.7 * (10**308) * 2) }.to raise_error(ArgumentError) }
|
12
|
+
|
13
|
+
it { expect(lambda {
|
14
|
+
subject.value = '19.89043256'
|
15
|
+
subject.value
|
16
|
+
}.call).to eq(19.89043256) }
|
17
|
+
|
18
|
+
it { expect(lambda {
|
19
|
+
subject.value = 19.89043256
|
20
|
+
subject.value
|
21
|
+
}.call).to eq(19.89043256) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'single precision' do
|
25
|
+
let(:subject) { FrOData::Properties::Single.new('Float', '678.90325') }
|
26
|
+
|
27
|
+
it { expect(subject.type).to eq('Edm.Single') }
|
28
|
+
it { expect(subject.value).to eq(678.90325) }
|
29
|
+
|
30
|
+
it { expect(subject.url_value).to eq('678.90325F') }
|
31
|
+
|
32
|
+
it { expect { subject.value = (3.4 * (10**38) * 2) }.to raise_error(ArgumentError) }
|
33
|
+
it { expect { subject.value = (-3.4 * (10**38) * 2) }.to raise_error(ArgumentError) }
|
34
|
+
|
35
|
+
it { expect(lambda {
|
36
|
+
subject.value = '19.89043256'
|
37
|
+
subject.value
|
38
|
+
}.call).to eq(19.89043256) }
|
39
|
+
|
40
|
+
it { expect(lambda {
|
41
|
+
subject.value = 19.89043256
|
42
|
+
subject.value
|
43
|
+
}.call).to eq(19.89043256) }
|
44
|
+
end
|
45
|
+
end
|