frodo 0.10.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.
Files changed (153) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +2 -0
  3. data/.circleci/config.yml +54 -0
  4. data/.gitignore +24 -0
  5. data/.gitlab-ci.yml +9 -0
  6. data/.rspec +2 -0
  7. data/.ruby-gemset +1 -0
  8. data/.ruby-version +1 -0
  9. data/.travis.yml +75 -0
  10. data/CHANGELOG.md +163 -0
  11. data/Gemfile +4 -0
  12. data/LICENSE.txt +23 -0
  13. data/README.md +479 -0
  14. data/Rakefile +7 -0
  15. data/TODO.md +55 -0
  16. data/frodo.gemspec +39 -0
  17. data/images/frodo.jpg +0 -0
  18. data/lib/frodo/abstract_client.rb +11 -0
  19. data/lib/frodo/client.rb +6 -0
  20. data/lib/frodo/concerns/api.rb +292 -0
  21. data/lib/frodo/concerns/authentication.rb +32 -0
  22. data/lib/frodo/concerns/base.rb +84 -0
  23. data/lib/frodo/concerns/caching.rb +26 -0
  24. data/lib/frodo/concerns/connection.rb +79 -0
  25. data/lib/frodo/concerns/verbs.rb +68 -0
  26. data/lib/frodo/config.rb +143 -0
  27. data/lib/frodo/entity.rb +335 -0
  28. data/lib/frodo/entity_container.rb +75 -0
  29. data/lib/frodo/entity_set.rb +131 -0
  30. data/lib/frodo/errors.rb +70 -0
  31. data/lib/frodo/middleware/authentication/token.rb +13 -0
  32. data/lib/frodo/middleware/authentication.rb +87 -0
  33. data/lib/frodo/middleware/authorization.rb +18 -0
  34. data/lib/frodo/middleware/caching.rb +30 -0
  35. data/lib/frodo/middleware/custom_headers.rb +14 -0
  36. data/lib/frodo/middleware/gzip.rb +33 -0
  37. data/lib/frodo/middleware/instance_url.rb +20 -0
  38. data/lib/frodo/middleware/logger.rb +42 -0
  39. data/lib/frodo/middleware/multipart.rb +64 -0
  40. data/lib/frodo/middleware/odata_headers.rb +13 -0
  41. data/lib/frodo/middleware/raise_error.rb +47 -0
  42. data/lib/frodo/middleware.rb +33 -0
  43. data/lib/frodo/navigation_property/proxy.rb +80 -0
  44. data/lib/frodo/navigation_property.rb +29 -0
  45. data/lib/frodo/properties/binary.rb +50 -0
  46. data/lib/frodo/properties/boolean.rb +37 -0
  47. data/lib/frodo/properties/collection.rb +50 -0
  48. data/lib/frodo/properties/complex.rb +114 -0
  49. data/lib/frodo/properties/date.rb +27 -0
  50. data/lib/frodo/properties/date_time.rb +83 -0
  51. data/lib/frodo/properties/date_time_offset.rb +17 -0
  52. data/lib/frodo/properties/decimal.rb +54 -0
  53. data/lib/frodo/properties/enum.rb +62 -0
  54. data/lib/frodo/properties/float.rb +67 -0
  55. data/lib/frodo/properties/geography/base.rb +162 -0
  56. data/lib/frodo/properties/geography/line_string.rb +33 -0
  57. data/lib/frodo/properties/geography/point.rb +31 -0
  58. data/lib/frodo/properties/geography/polygon.rb +38 -0
  59. data/lib/frodo/properties/geography.rb +13 -0
  60. data/lib/frodo/properties/guid.rb +17 -0
  61. data/lib/frodo/properties/integer.rb +107 -0
  62. data/lib/frodo/properties/number.rb +14 -0
  63. data/lib/frodo/properties/string.rb +72 -0
  64. data/lib/frodo/properties/time.rb +40 -0
  65. data/lib/frodo/properties/time_of_day.rb +27 -0
  66. data/lib/frodo/properties.rb +32 -0
  67. data/lib/frodo/property.rb +139 -0
  68. data/lib/frodo/property_registry.rb +41 -0
  69. data/lib/frodo/query/criteria/comparison_operators.rb +49 -0
  70. data/lib/frodo/query/criteria/date_functions.rb +61 -0
  71. data/lib/frodo/query/criteria/geography_functions.rb +21 -0
  72. data/lib/frodo/query/criteria/lambda_operators.rb +27 -0
  73. data/lib/frodo/query/criteria/string_functions.rb +40 -0
  74. data/lib/frodo/query/criteria.rb +92 -0
  75. data/lib/frodo/query/in_batches.rb +58 -0
  76. data/lib/frodo/query.rb +221 -0
  77. data/lib/frodo/railtie.rb +19 -0
  78. data/lib/frodo/schema/complex_type.rb +79 -0
  79. data/lib/frodo/schema/enum_type.rb +95 -0
  80. data/lib/frodo/schema.rb +164 -0
  81. data/lib/frodo/service.rb +199 -0
  82. data/lib/frodo/service_registry.rb +52 -0
  83. data/lib/frodo/version.rb +3 -0
  84. data/lib/frodo.rb +67 -0
  85. data/spec/fixtures/auth_success_response.json +11 -0
  86. data/spec/fixtures/error.json +11 -0
  87. data/spec/fixtures/files/entity_to_xml.xml +18 -0
  88. data/spec/fixtures/files/error.xml +5 -0
  89. data/spec/fixtures/files/metadata.xml +150 -0
  90. data/spec/fixtures/files/metadata_with_error.xml +157 -0
  91. data/spec/fixtures/files/product_0.json +10 -0
  92. data/spec/fixtures/files/product_0.xml +28 -0
  93. data/spec/fixtures/files/products.json +106 -0
  94. data/spec/fixtures/files/products.xml +308 -0
  95. data/spec/fixtures/files/supplier_0.json +26 -0
  96. data/spec/fixtures/files/supplier_0.xml +32 -0
  97. data/spec/fixtures/leads.json +923 -0
  98. data/spec/fixtures/refresh_error_response.json +8 -0
  99. data/spec/frodo/abstract_client_spec.rb +13 -0
  100. data/spec/frodo/client_spec.rb +57 -0
  101. data/spec/frodo/concerns/authentication_spec.rb +79 -0
  102. data/spec/frodo/concerns/base_spec.rb +68 -0
  103. data/spec/frodo/concerns/caching_spec.rb +40 -0
  104. data/spec/frodo/concerns/connection_spec.rb +65 -0
  105. data/spec/frodo/config_spec.rb +127 -0
  106. data/spec/frodo/entity/shared_examples.rb +83 -0
  107. data/spec/frodo/entity_container_spec.rb +38 -0
  108. data/spec/frodo/entity_set_spec.rb +169 -0
  109. data/spec/frodo/entity_spec.rb +153 -0
  110. data/spec/frodo/errors_spec.rb +48 -0
  111. data/spec/frodo/middleware/authentication/token_spec.rb +87 -0
  112. data/spec/frodo/middleware/authentication_spec.rb +83 -0
  113. data/spec/frodo/middleware/authorization_spec.rb +17 -0
  114. data/spec/frodo/middleware/custom_headers_spec.rb +21 -0
  115. data/spec/frodo/middleware/gzip_spec.rb +68 -0
  116. data/spec/frodo/middleware/instance_url_spec.rb +27 -0
  117. data/spec/frodo/middleware/logger_spec.rb +21 -0
  118. data/spec/frodo/middleware/odata_headers_spec.rb +15 -0
  119. data/spec/frodo/middleware/raise_error_spec.rb +66 -0
  120. data/spec/frodo/navigation_property/proxy_spec.rb +46 -0
  121. data/spec/frodo/navigation_property_spec.rb +55 -0
  122. data/spec/frodo/properties/binary_spec.rb +50 -0
  123. data/spec/frodo/properties/boolean_spec.rb +72 -0
  124. data/spec/frodo/properties/collection_spec.rb +44 -0
  125. data/spec/frodo/properties/date_spec.rb +23 -0
  126. data/spec/frodo/properties/date_time_offset_spec.rb +30 -0
  127. data/spec/frodo/properties/date_time_spec.rb +23 -0
  128. data/spec/frodo/properties/decimal_spec.rb +50 -0
  129. data/spec/frodo/properties/float_spec.rb +45 -0
  130. data/spec/frodo/properties/geography/line_string_spec.rb +33 -0
  131. data/spec/frodo/properties/geography/point_spec.rb +29 -0
  132. data/spec/frodo/properties/geography/polygon_spec.rb +55 -0
  133. data/spec/frodo/properties/geography/shared_examples.rb +72 -0
  134. data/spec/frodo/properties/guid_spec.rb +17 -0
  135. data/spec/frodo/properties/integer_spec.rb +58 -0
  136. data/spec/frodo/properties/string_spec.rb +46 -0
  137. data/spec/frodo/properties/time_of_day_spec.rb +23 -0
  138. data/spec/frodo/properties/time_spec.rb +15 -0
  139. data/spec/frodo/property_registry_spec.rb +16 -0
  140. data/spec/frodo/property_spec.rb +71 -0
  141. data/spec/frodo/query/criteria_spec.rb +229 -0
  142. data/spec/frodo/query_spec.rb +156 -0
  143. data/spec/frodo/schema/complex_type_spec.rb +97 -0
  144. data/spec/frodo/schema/enum_type_spec.rb +112 -0
  145. data/spec/frodo/schema_spec.rb +113 -0
  146. data/spec/frodo/service_registry_spec.rb +19 -0
  147. data/spec/frodo/service_spec.rb +153 -0
  148. data/spec/frodo/usage_example_spec.rb +161 -0
  149. data/spec/spec_helper.rb +35 -0
  150. data/spec/support/coverage.rb +2 -0
  151. data/spec/support/fixture_helpers.rb +14 -0
  152. data/spec/support/middleware.rb +19 -0
  153. metadata +479 -0
@@ -0,0 +1,72 @@
1
+ shared_examples 'a geographic property' do |type_name|
2
+ let(:subject) { klass.new(property_name, coordinates) }
3
+
4
+ describe '#type' do
5
+ it { expect(subject.type).to eq(type_name) }
6
+ end
7
+
8
+ describe '#srid' do
9
+ it { expect(subject.srid).to eq(srid) }
10
+ end
11
+
12
+ describe '#value' do
13
+ it { expect(subject.value).to eq(coordinates) }
14
+ end
15
+
16
+ describe '#value=' do
17
+ it { expect { subject.value = 'invalid' }.to raise_error(ArgumentError) }
18
+
19
+ it {
20
+ subject.value = new_value_as_text
21
+ expect(subject.value).to eq(new_value)
22
+ expect(subject.srid).to eq(0)
23
+ }
24
+
25
+ it {
26
+ subject.value = new_value
27
+ expect(subject.value).to eq(new_value)
28
+ expect(subject.srid).to eq(4326)
29
+ }
30
+ end
31
+
32
+ describe '#url_value' do
33
+ it { expect(subject.url_value).to eq(property_as_text) }
34
+ end
35
+
36
+ describe '#json_value' do
37
+ it 'renders property value as a hash' do
38
+ expect(subject.json_value).to eq(property_as_json)
39
+ end
40
+ end
41
+
42
+ describe '#to_xml' do
43
+ let(:builder) do
44
+ Nokogiri::XML::Builder.new do |xml|
45
+ xml.entry(Frodo::Entity::XML_NAMESPACES) do
46
+ subject.to_xml(xml)
47
+ end
48
+ end
49
+ end
50
+ let(:xml) { Nokogiri::XML(builder.to_xml) }
51
+ let(:property_xml) { xml.root.element_children.first.to_s }
52
+
53
+ it { expect(property_xml).to be_equivalent_to(property_as_xml) }
54
+ end
55
+
56
+ describe '.from_xml' do
57
+ let(:subject) { klass.from_xml(property_xml) }
58
+ let(:xml_doc) do
59
+ Nokogiri::XML::Builder.new do |xml|
60
+ xml.entry(Frodo::Entity::XML_NAMESPACES)
61
+ end.to_xml
62
+ end
63
+ let(:property_xml) do
64
+ document = Nokogiri::XML(xml_doc)
65
+ document.root << property_as_xml
66
+ document.remove_namespaces!.root.element_children.first
67
+ end
68
+
69
+ it { expect(subject.value).to eq(coordinates) }
70
+ it { expect(subject.srid).to eq(srid) }
71
+ end
72
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Frodo::Properties::Guid do
4
+ let(:guid) { SecureRandom.uuid }
5
+ let(:guid2) { SecureRandom.uuid }
6
+ let(:subject) { Frodo::Properties::Guid.new('Stringy', guid) }
7
+
8
+ it { expect(subject.type).to eq('Edm.Guid') }
9
+ it { expect(subject.value).to eq(guid)}
10
+
11
+ it { expect(lambda {
12
+ subject.value = guid2
13
+ subject.value
14
+ }.call).to eq(guid2) }
15
+
16
+ it { expect(subject.url_value).to eq("#{guid}") }
17
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Frodo::Properties::Integer do
4
+ let(:subject) { Frodo::Properties::Integer.new('Integer', '32') }
5
+ let(:subject16) { Frodo::Properties::Int16.new('Int16', '32') }
6
+ let(:subject32) { Frodo::Properties::Int32.new('Int32', '32') }
7
+ let(:subject64) { Frodo::Properties::Int64.new('Int64', '32') }
8
+ let(:subjectbyte) { Frodo::Properties::Byte.new('Byte', '32') }
9
+ let(:subjectsbyte) { Frodo::Properties::SByte.new('SByte', '32') }
10
+
11
+ it { expect(subject.type).to eq('Edm.Int64') }
12
+ it { expect(subject.value).to eq(32) }
13
+ it { expect {subject.value = (2**63)}.to raise_error(ArgumentError) }
14
+ it { expect {subject.value = (-(2**63) - 1)}.to raise_error(ArgumentError) }
15
+
16
+ it { expect(subject16.type).to eq('Edm.Int16') }
17
+ it { expect(subject16.value).to eq(32) }
18
+ it { expect {subject16.value = (2**15)}.to raise_error(ArgumentError) }
19
+ it { expect {subject16.value = (-(2**15) - 1)}.to raise_error(ArgumentError) }
20
+
21
+ it { expect(subject32.type).to eq('Edm.Int32') }
22
+ it { expect(subject32.value).to eq(32) }
23
+ it { expect {subject32.value = (2**31)}.to raise_error(ArgumentError) }
24
+ it { expect {subject32.value = (-(2**31) - 1)}.to raise_error(ArgumentError) }
25
+
26
+ it { expect(subject64.type).to eq('Edm.Int64') }
27
+ it { expect(subject64.value).to eq(32) }
28
+ it { expect {subject64.value = (2**63)}.to raise_error(ArgumentError) }
29
+ it { expect {subject64.value = (-(2**63) - 1)}.to raise_error(ArgumentError) }
30
+
31
+ it { expect(subjectbyte.type).to eq('Edm.Byte') }
32
+ it { expect(subjectbyte.value).to eq(32) }
33
+ it { expect {subjectbyte.value = 2**8}.to raise_error(ArgumentError) }
34
+ it { expect {subjectbyte.value = -1}.to raise_error(ArgumentError) }
35
+
36
+ it { expect(subjectsbyte.type).to eq('Edm.SByte') }
37
+ it { expect(subjectsbyte.value).to eq(32) }
38
+ it { expect {subjectsbyte.value = (2**7)}.to raise_error(ArgumentError) }
39
+ it { expect {subjectsbyte.value = (-(2**7) - 1)}.to raise_error(ArgumentError) }
40
+
41
+ describe '#value=' do
42
+ before(:example) do
43
+ subject.value = 128
44
+ subject16.value = 128
45
+ subject32.value = 128
46
+ subject64.value = 128
47
+ subjectbyte.value = 12
48
+ subjectsbyte.value = 12
49
+ end
50
+
51
+ it { expect(subject.value).to eq(128) }
52
+ it { expect(subject16.value).to eq(128) }
53
+ it { expect(subject32.value).to eq(128) }
54
+ it { expect(subject64.value).to eq(128) }
55
+ it { expect(subjectbyte.value).to eq(12) }
56
+ it { expect(subjectsbyte.value).to eq(12) }
57
+ end
58
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Frodo::Properties::String do
4
+ let(:subject) { Frodo::Properties::String.new('Stringy', 'This is an example') }
5
+
6
+ it { expect(subject).to respond_to(:is_unicode?) }
7
+ it { expect(subject).to respond_to(:has_default_value?) }
8
+ it { expect(subject).to respond_to(:default_value) }
9
+
10
+ it { expect(subject.type).to eq('Edm.String') }
11
+ it { expect(subject.value).to eq('This is an example')}
12
+
13
+ it { expect(lambda {
14
+ subject.value = 'Another example'
15
+ subject.value
16
+ }.call).to eq('Another example') }
17
+
18
+ it { expect(lambda {
19
+ subject.value = nil
20
+ subject.value
21
+ }.call).to eq(nil) }
22
+
23
+ describe '#is_unicode?' do
24
+ let(:not_unicode) { Frodo::Properties::String.new('Stringy', 'This is an example', unicode: false) }
25
+
26
+ it { expect(subject.is_unicode?).to eq(true) }
27
+ it { expect(not_unicode.is_unicode?).to eq(false) }
28
+
29
+ it { expect(subject.value.encoding).to eq(Encoding::UTF_8) }
30
+ it { expect(not_unicode.value.encoding).to eq(Encoding::ASCII) }
31
+ end
32
+
33
+ describe 'when #allows_nil? is false' do
34
+ let(:subject) { Frodo::Properties::String.new('Stringy', 'This is an example', allows_nil: false) }
35
+
36
+ it { expect {subject.value = nil}.to raise_error(ArgumentError) }
37
+ it { expect {subject.value = 'Test'}.not_to raise_error }
38
+ end
39
+
40
+ describe 'with default_value' do
41
+ let(:subject) { Frodo::Properties::String.new('Stringy', nil, default_value: 'Sample Text') }
42
+
43
+ it { expect(subject.has_default_value?).to eq(true) }
44
+ it { expect(subject.default_value).to eq('Sample Text') }
45
+ end
46
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Frodo::Properties::TimeOfDay do
4
+ let(:subject) { Frodo::Properties::TimeOfDay.new('TimeOfDay', '16:00:00.000') }
5
+ let(:new_time) { Time.strptime('14:32:00.000', '%H:%M:%S.%L') }
6
+
7
+ it { expect(subject.type).to eq('Edm.TimeOfDay') }
8
+ it { expect(subject.value).to eq(Time.parse('16:00:00.000')) }
9
+
10
+ it { expect(subject.url_value).to eq("16:00:00.000")}
11
+
12
+ it { expect {subject.value = 'bad'}.to raise_error(ArgumentError) }
13
+
14
+ it { expect(lambda {
15
+ subject.value = '14:32:00.000'
16
+ subject.value
17
+ }.call).to eq(new_time) }
18
+
19
+ it { expect(lambda {
20
+ subject.value = new_time
21
+ subject.value
22
+ }.call).to eq(new_time) }
23
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Frodo::Properties::Time do
4
+ let(:subject) { Frodo::Properties::Time.new('Timely', '21:00:00-08:00') }
5
+
6
+ it { expect(subject.type).to eq('Edm.Time') }
7
+ it { expect(subject.value).to eq(Time.strptime('21:00:00-08:00', '%H:%M:%S%:z')) }
8
+
9
+ it { expect {subject.value = 'bad'}.to raise_error(ArgumentError) }
10
+
11
+ it { expect(lambda {
12
+ subject.value = Time.strptime('13:22:12+04:00', '%H:%M:%S%:z')
13
+ subject.value
14
+ }.call).to eq(Time.strptime('13:22:12+04:00', '%H:%M:%S%:z'))}
15
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Frodo::PropertyRegistry do
4
+ let(:subject) { Frodo::PropertyRegistry }
5
+
6
+ it { expect(subject).to respond_to(:add) }
7
+ it { expect(subject).to respond_to(:[]) }
8
+
9
+ describe '#add' do
10
+ before(:each) do
11
+ subject.add('Edm.Guid', Frodo::Properties::Guid)
12
+ end
13
+
14
+ it { expect(subject['Edm.Guid']).to eq(Frodo::Properties::Guid) }
15
+ end
16
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ describe Frodo::Property do
4
+ let(:service) do
5
+ Frodo::Service.new('http://services.odata.org/V4/OData/OData.svc', metadata_file: metadata_file)
6
+ end
7
+ let(:metadata_file) { 'spec/fixtures/files/metadata.xml' }
8
+ let(:subject) { Frodo::Property.new('PropertyName', '1') }
9
+ let(:good_comparison) { Frodo::Property.new('GoodComparison', '1') }
10
+ let(:bad_comparison) { Frodo::Property.new('BadComparison', '2') }
11
+
12
+ describe '#name' do
13
+ it { expect(subject).to respond_to(:name) }
14
+ it { expect(subject.name).to eq('PropertyName') }
15
+ end
16
+
17
+ describe '#value' do
18
+ it { expect(subject).to respond_to(:value) }
19
+ it { expect(subject.value).to eq('1') }
20
+ end
21
+
22
+ describe '#xml_value' do
23
+ it { expect(subject).to respond_to(:xml_value) }
24
+ it { expect(subject.xml_value).to eq('1') }
25
+ end
26
+
27
+ describe '#url_value' do
28
+ it { expect(subject).to respond_to(:url_value) }
29
+ it { expect(subject.url_value).to eq('1') }
30
+ end
31
+
32
+ describe '#type' do
33
+ it { expect(subject).to respond_to(:type) }
34
+ it { expect(lambda {subject.type}).to raise_error(NotImplementedError) }
35
+ end
36
+
37
+ describe '#allows_nil?' do
38
+ it { expect(subject).to respond_to(:allows_nil?) }
39
+ it { expect(subject.allows_nil?).to eq(true) }
40
+ end
41
+
42
+ describe '#strict?' do
43
+ it { expect(subject).to respond_to(:strict?) }
44
+
45
+ it 'defaults to true' do
46
+ expect(subject.strict?).to eq(true)
47
+ end
48
+
49
+ it 'can be switched off via constructor option' do
50
+ subject = Frodo::Property.new('PropertyName', '1', strict: false)
51
+ expect(subject.strict?).to eq(false)
52
+ end
53
+
54
+ it 'can be switched off via service level option' do
55
+ service.options[:strict] = false
56
+ subject = Frodo::Property.new('PropertyName', '1', service: service)
57
+ expect(subject.strict?).to eq(false)
58
+ end
59
+ end
60
+
61
+ describe '#concurrency_mode' do
62
+ it { expect(subject).to respond_to(:concurrency_mode) }
63
+ it { expect(subject.concurrency_mode).to eq(:none) }
64
+ end
65
+
66
+ describe '#==' do
67
+ it { expect(subject).to respond_to(:==) }
68
+ it { expect(subject == good_comparison).to eq(true) }
69
+ it { expect(subject == bad_comparison).to eq(false) }
70
+ end
71
+ end
@@ -0,0 +1,229 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'an operator criterium' do |operator, value, to_s|
4
+ it { expect(criteria).to eq(subject) }
5
+ it { expect(criteria.operator).to eq(operator) }
6
+ it { expect(criteria.value).to eq(value) }
7
+ it { expect(criteria.to_s).to eq(to_s) }
8
+ end
9
+
10
+ shared_examples 'a function criterium' do |function, argument, to_s|
11
+ it { expect(criteria).to eq(subject) }
12
+ it { expect(criteria.function).to eq(function) }
13
+ it { expect(criteria.argument).to eq(argument) }
14
+ it { expect(criteria.to_s).to eq(to_s) }
15
+ end
16
+
17
+ shared_examples 'an operator-function criterium' do |function, operator, value, to_s|
18
+ it { expect(criteria).to eq(subject) }
19
+ it { expect(criteria.function).to eq(function) }
20
+ it { expect(criteria.operator).to eq(operator) }
21
+ it { expect(criteria.value).to eq(value) }
22
+ it { expect(criteria.to_s).to eq(to_s) }
23
+ end
24
+
25
+ describe Frodo::Query::Criteria do
26
+ let(:string_property) { Frodo::Properties::String.new(:Name, nil) }
27
+ let(:integer_property) { Frodo::Properties::Integer.new(:Age, nil) }
28
+ let(:datetime_property) { Frodo::Properties::DateTime.new(:BirthDate, nil) }
29
+ let(:geo_property) { Frodo::Properties::Geography::Point.new(:Position, nil) }
30
+ # TODO: use actual `NavigationProperty` class here
31
+ let(:navigation_property) { Frodo::Property.new(:Items, nil) }
32
+
33
+ let(:subject) { Frodo::Query::Criteria.new(property: string_property) }
34
+
35
+ it { expect(subject).to respond_to(:property) }
36
+ it { expect(subject.property).to eq(string_property)}
37
+
38
+ it { expect(subject).to respond_to(:operator) }
39
+ it { expect(subject).to respond_to(:value) }
40
+ it { expect(subject).to respond_to(:to_s) }
41
+
42
+ describe 'comparison operators' do
43
+ describe '#eq' do
44
+ let(:criteria) { subject.eq('Bread') }
45
+
46
+ it { expect(subject).to respond_to(:eq) }
47
+ it_behaves_like 'an operator criterium', :eq, 'Bread', "Name eq 'Bread'"
48
+ end
49
+
50
+ describe '#ne' do
51
+ let(:criteria) { subject.ne('Bread') }
52
+
53
+ it { expect(subject).to respond_to(:ne) }
54
+ it_behaves_like 'an operator criterium', :ne, 'Bread', "Name ne 'Bread'"
55
+ end
56
+
57
+ describe '#gt' do
58
+ let(:subject) { Frodo::Query::Criteria.new(property: integer_property) }
59
+ let(:criteria) { subject.gt(5) }
60
+
61
+ it { expect(subject).to respond_to(:gt) }
62
+ it_behaves_like 'an operator criterium', :gt, 5, "Age gt 5"
63
+ end
64
+
65
+ describe '#ge' do
66
+ let(:subject) { Frodo::Query::Criteria.new(property: integer_property) }
67
+ let(:criteria) { subject.ge(5) }
68
+
69
+ it { expect(subject).to respond_to(:ge) }
70
+ it_behaves_like 'an operator criterium', :ge, 5, 'Age ge 5'
71
+ end
72
+
73
+ describe '#lt' do
74
+ let(:subject) { Frodo::Query::Criteria.new(property: integer_property) }
75
+ let(:criteria) { subject.lt(5) }
76
+
77
+ it { expect(subject).to respond_to(:lt) }
78
+ it_behaves_like 'an operator criterium', :lt, 5, 'Age lt 5'
79
+ end
80
+
81
+ describe '#le' do
82
+ let(:subject) { Frodo::Query::Criteria.new(property: integer_property) }
83
+ let(:criteria) { subject.le(5) }
84
+
85
+ it { expect(subject).to respond_to(:le) }
86
+ it_behaves_like 'an operator criterium', :le, 5, 'Age le 5'
87
+ end
88
+ end
89
+
90
+ describe 'string functions' do
91
+ describe '#contains' do
92
+ let(:criteria) { subject.contains('freds') }
93
+
94
+ it { expect(subject).to respond_to(:contains) }
95
+ it_behaves_like 'a function criterium', :contains, 'freds', "contains(Name,'freds')"
96
+ end
97
+
98
+ describe '#startswith' do
99
+ let(:criteria) { subject.startswith('Alfreds') }
100
+
101
+ it { expect(subject).to respond_to(:startswith) }
102
+ it_behaves_like 'a function criterium', :startswith, 'Alfreds', "startswith(Name,'Alfreds')"
103
+ end
104
+
105
+ describe '#endswith' do
106
+ let(:criteria) { subject.endswith('Futterkiste') }
107
+
108
+ it { expect(subject).to respond_to(:endswith) }
109
+ it_behaves_like 'a function criterium', :endswith, 'Futterkiste', "endswith(Name,'Futterkiste')"
110
+ end
111
+
112
+ describe '#tolower' do
113
+ let(:criteria) { subject.tolower.eq('alfreds futterkiste') }
114
+
115
+ it { expect(subject).to respond_to(:tolower) }
116
+ it_behaves_like 'an operator-function criterium', :tolower, :eq, 'alfreds futterkiste', "tolower(Name) eq 'alfreds futterkiste'"
117
+ end
118
+
119
+ describe '#toupper' do
120
+ let(:criteria) { subject.toupper.eq('ALFREDS FUTTERKISTE') }
121
+
122
+ it { expect(subject).to respond_to(:toupper) }
123
+ it_behaves_like 'an operator-function criterium', :toupper, :eq, 'ALFREDS FUTTERKISTE', "toupper(Name) eq 'ALFREDS FUTTERKISTE'"
124
+ end
125
+ end
126
+
127
+ describe 'date functions' do
128
+ let(:subject) { Frodo::Query::Criteria.new(property: datetime_property) }
129
+
130
+ describe '#year' do
131
+ let(:criteria) { subject.year.eq(1981) }
132
+
133
+ it { expect(subject).to respond_to(:year) }
134
+ it_behaves_like 'an operator-function criterium', :year, :eq, 1981, 'year(BirthDate) eq 1981'
135
+ end
136
+
137
+ describe '#month' do
138
+ let(:criteria) { subject.month.eq(8) }
139
+
140
+ it { expect(subject).to respond_to(:month) }
141
+ it_behaves_like 'an operator-function criterium', :month, :eq, 8, 'month(BirthDate) eq 8'
142
+ end
143
+
144
+ describe '#day' do
145
+ let(:criteria) { subject.day.eq(27) }
146
+
147
+ it { expect(subject).to respond_to(:day) }
148
+ it_behaves_like 'an operator-function criterium', :day, :eq, 27, 'day(BirthDate) eq 27'
149
+ end
150
+
151
+ describe '#hour' do
152
+ let(:criteria) { subject.hour.eq(9) }
153
+
154
+ it { expect(subject).to respond_to(:hour) }
155
+ it_behaves_like 'an operator-function criterium', :hour, :eq, 9, 'hour(BirthDate) eq 9'
156
+ end
157
+
158
+ describe '#minute' do
159
+ let(:criteria) { subject.minute.eq(35) }
160
+
161
+ it { expect(subject).to respond_to(:minute) }
162
+ it_behaves_like 'an operator-function criterium', :minute, :eq, 35, 'minute(BirthDate) eq 35'
163
+ end
164
+
165
+ describe '#second' do
166
+ let(:criteria) { subject.second.eq(11) }
167
+
168
+ it { expect(subject).to respond_to(:second) }
169
+ it_behaves_like 'an operator-function criterium', :second, :eq, 11, 'second(BirthDate) eq 11'
170
+ end
171
+
172
+ describe '#fractionalseconds' do
173
+ let(:criteria) { subject.fractionalseconds.eq(0) }
174
+
175
+ it { expect(subject).to respond_to(:fractionalseconds) }
176
+ it_behaves_like 'an operator-function criterium', :fractionalseconds, :eq, 0, 'fractionalseconds(BirthDate) eq 0'
177
+ end
178
+
179
+ describe '#date' do
180
+ let(:criteria) { subject.date.ne('date(EndTime)') }
181
+
182
+ it { expect(subject).to respond_to(:date) }
183
+ it_behaves_like 'an operator-function criterium', :date, :ne, 'date(EndTime)', 'date(BirthDate) ne date(EndTime)'
184
+ end
185
+
186
+ describe '#time' do
187
+ let(:criteria) { subject.time.le('StartOfDay') }
188
+
189
+ it { expect(subject).to respond_to(:time) }
190
+ it_behaves_like 'an operator-function criterium', :time, :le, 'StartOfDay', 'time(BirthDate) le StartOfDay'
191
+ end
192
+ end
193
+
194
+ describe 'geospatial functions' do
195
+ let(:subject) { Frodo::Query::Criteria.new(property: geo_property) }
196
+
197
+ describe '#distance' do
198
+ let(:criteria) { subject.distance('TargetPosition').le(42) }
199
+
200
+ it { expect(subject).to respond_to(:distance) }
201
+ it_behaves_like 'an operator-function criterium', :'geo.distance', :le, 42, 'geo.distance(Position,TargetPosition) le 42'
202
+ end
203
+
204
+ describe '#intersects' do
205
+ let(:criteria) { subject.intersects('TargetArea') }
206
+
207
+ it { expect(subject).to respond_to(:intersects) }
208
+ it_behaves_like 'a function criterium', :'geo.intersects', 'TargetArea', 'geo.intersects(Position,TargetArea)'
209
+ end
210
+ end
211
+
212
+ describe 'lambda operators' do
213
+ let(:subject) { Frodo::Query::Criteria.new(property: navigation_property) }
214
+
215
+ describe '#any' do
216
+ let(:criteria) { subject.any('Quantity').gt(100) }
217
+
218
+ it { expect(subject).to respond_to(:any) }
219
+ it_behaves_like 'an operator-function criterium', :any, :gt, 100, 'Items/any(d:d/Quantity gt 100)'
220
+ end
221
+
222
+ describe '#all' do
223
+ let(:criteria) { subject.all('Quantity').gt(100) }
224
+
225
+ it { expect(subject).to respond_to(:all) }
226
+ it_behaves_like 'an operator-function criterium', :all, :gt, 100, 'Items/all(d:d/Quantity gt 100)'
227
+ end
228
+ end
229
+ end