ruby_odata 0.1.3 → 0.1.4
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.
- data/.coveralls.yml +1 -0
- data/.gitignore +4 -0
- data/.simplecov +10 -0
- data/.travis.yml +10 -5
- data/CHANGELOG.md +21 -1
- data/Rakefile +19 -2
- data/features/step_definitions/service_steps.rb +2 -58
- data/features/support/env.rb +6 -1
- data/gemfiles/Gemfile.ruby187 +6 -0
- data/lib/ruby_odata.rb +1 -0
- data/lib/ruby_odata/class_builder.rb +14 -0
- data/lib/ruby_odata/service.rb +65 -35
- data/lib/ruby_odata/version.rb +1 -1
- data/ruby_odata.gemspec +4 -2
- data/spec/fixtures/ms_system_center/edmx_ms_system_center.xml +1645 -0
- data/spec/fixtures/ms_system_center/hardware_profiles.xml +61 -0
- data/spec/fixtures/ms_system_center/virtual_machines.xml +175 -0
- data/spec/fixtures/ms_system_center/vm_templates.xml +1193 -0
- data/spec/fixtures/nested_expands/edmx_northwind.xml +557 -0
- data/spec/fixtures/nested_expands/northwind_products_category_expands.xml +774 -0
- data/spec/service_spec.rb +147 -3
- data/spec/spec_helper.rb +3 -0
- metadata +55 -8
data/spec/service_spec.rb
CHANGED
@@ -756,9 +756,153 @@ module OData
|
|
756
756
|
end
|
757
757
|
end
|
758
758
|
|
759
|
-
describe "
|
760
|
-
|
759
|
+
describe "JSON serialization of objects" do
|
760
|
+
before(:each) do
|
761
|
+
# Required for the build_classes method
|
762
|
+
stub_request(:get, "http://blabla:@test.com/test.svc/$metadata").
|
763
|
+
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
|
764
|
+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/edmx_ms_system_center.xml", __FILE__)), :headers => {})
|
765
|
+
|
766
|
+
stub_request(:get, "http://blabla:@test.com/test.svc/VirtualMachines").
|
767
|
+
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
|
768
|
+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/virtual_machines.xml", __FILE__)), :headers => {})
|
769
|
+
svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
|
770
|
+
svc.VirtualMachines
|
771
|
+
results = svc.execute
|
772
|
+
@json = results.first.as_json
|
773
|
+
end
|
774
|
+
|
775
|
+
it "Should quote Edm.Int64 properties" do
|
776
|
+
@json["PerfDiskBytesWrite"].should be_a(String)
|
777
|
+
end
|
778
|
+
|
779
|
+
it "Should output collections with metadata" do
|
780
|
+
@json["VMNetworkAssignments"].should be_a(Hash)
|
781
|
+
@json["VMNetworkAssignments"].should have_key("__metadata")
|
782
|
+
@json["VMNetworkAssignments"]["__metadata"].should be_a(Hash)
|
783
|
+
@json["VMNetworkAssignments"]["__metadata"].should have_key("type")
|
784
|
+
@json["VMNetworkAssignments"]["__metadata"]["type"].should eq("Collection(VMM.VMNetworkAssignment)")
|
785
|
+
@json["VMNetworkAssignments"].should have_key("results")
|
786
|
+
@json["VMNetworkAssignments"]["results"].should be_a(Array)
|
787
|
+
@json["VMNetworkAssignments"]["results"].should eq([])
|
788
|
+
end
|
789
|
+
end
|
790
|
+
|
791
|
+
describe "handling of Microsoft System Center 2012" do
|
792
|
+
before(:each) do
|
793
|
+
# Required for the build_classes method
|
794
|
+
stub_request(:get, "http://blabla:@test.com/test.svc/$metadata").
|
795
|
+
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
|
796
|
+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/edmx_ms_system_center.xml", __FILE__)), :headers => {})
|
797
|
+
|
798
|
+
stub_request(:get, "http://blabla:@test.com/test.svc/VirtualMachines").
|
799
|
+
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
|
800
|
+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/virtual_machines.xml", __FILE__)), :headers => {})
|
801
|
+
|
802
|
+
stub_request(:get, "http://blabla:@test.com/test.svc/HardwareProfiles?$filter=Memory%20eq%203500").
|
803
|
+
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
|
804
|
+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/hardware_profiles.xml", __FILE__)), :headers => {})
|
805
|
+
|
806
|
+
stub_request(:get, "http://blabla:@test.com/test.svc/VMTemplates").
|
807
|
+
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
|
808
|
+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/ms_system_center/vm_templates.xml", __FILE__)), :headers => {})
|
809
|
+
|
810
|
+
end
|
811
|
+
|
812
|
+
it "should successfully parse null valued string properties" do
|
813
|
+
svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
|
814
|
+
svc.VirtualMachines
|
815
|
+
results = svc.execute
|
816
|
+
results.first.should be_a_kind_of(VMM::VirtualMachine)
|
817
|
+
results.first.CostCenter.should be_nil
|
818
|
+
end
|
819
|
+
|
820
|
+
it "should successfully return a virtual machine" do
|
821
|
+
svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
|
822
|
+
svc.VirtualMachines
|
823
|
+
results = svc.execute
|
824
|
+
results.first.should be_a_kind_of(VMM::VirtualMachine)
|
825
|
+
end
|
826
|
+
|
827
|
+
it "should successfully return a hardware profile for results that include a collection of complex types" do
|
828
|
+
svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
|
829
|
+
svc.HardwareProfiles.filter("Memory eq 3500")
|
830
|
+
results = svc.execute
|
831
|
+
results.first.should be_a_kind_of(VMM::HardwareProfile)
|
832
|
+
end
|
833
|
+
|
834
|
+
it "should successfully return a collection of complex types" do
|
835
|
+
svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
|
836
|
+
svc.HardwareProfiles.filter("Memory eq 3500")
|
837
|
+
results = svc.execute
|
838
|
+
granted_list = results.first.GrantedToList
|
839
|
+
granted_list.should be_a_kind_of(Array)
|
840
|
+
granted_list.first.should be_a_kind_of(VMM::UserAndRole)
|
841
|
+
granted_list.first.RoleName.should == "Important Tenant"
|
842
|
+
end
|
843
|
+
|
844
|
+
|
845
|
+
it "should successfully return results that include a collection of Edm types" do
|
846
|
+
svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
|
847
|
+
svc.VMTemplates
|
848
|
+
results = svc.execute
|
849
|
+
results.first.should be_a_kind_of(VMM::VMTemplate)
|
850
|
+
end
|
851
|
+
|
852
|
+
it "should successfully return a collection of Edm types" do
|
853
|
+
svc = OData::Service.new "http://test.com/test.svc/", { :username => "blabla", :password=> "", :verify_ssl => false, :namespace => "VMM" }
|
854
|
+
svc.VMTemplates
|
855
|
+
results = svc.execute
|
856
|
+
boot_order = results.first.BootOrder
|
857
|
+
boot_order.should be_a_kind_of(Array)
|
858
|
+
boot_order.first.should be_a_kind_of(String)
|
859
|
+
boot_order.should eq ['CD', 'IdeHardDrive', 'PxeBoot', 'Floppy']
|
860
|
+
end
|
861
|
+
end
|
862
|
+
|
863
|
+
describe "handling of nested expands" do
|
864
|
+
before(:each) do
|
865
|
+
stub_request(:get, "http://test.com/test.svc/$metadata").
|
866
|
+
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
|
867
|
+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/nested_expands/edmx_northwind.xml", __FILE__)), :headers => {})
|
868
|
+
|
869
|
+
stub_request(:get, "http://test.com/test.svc/Products?$expand=Category,Category/Products&$top=2").
|
870
|
+
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
|
871
|
+
to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/nested_expands/northwind_products_category_expands.xml", __FILE__)), :headers => {})
|
872
|
+
end
|
873
|
+
|
874
|
+
it "should successfully parse the results" do
|
875
|
+
svc = OData::Service.new "http://test.com/test.svc", { :namespace => "NW" }
|
876
|
+
svc.Products.expand('Category').expand('Category/Products').top(2)
|
877
|
+
lambda { svc.execute }.should_not raise_exception
|
878
|
+
end
|
879
|
+
|
880
|
+
it "should successfully parse a Category as a Category" do
|
881
|
+
svc = OData::Service.new "http://test.com/test.svc", { :namespace => "NW" }
|
882
|
+
svc.Products.expand('Category').expand('Category/Products').top(2)
|
883
|
+
products = svc.execute
|
884
|
+
products.first.Category.should be_a_kind_of(NW::Category)
|
885
|
+
end
|
886
|
+
|
887
|
+
it "should successfully parse the Category properties" do
|
888
|
+
svc = OData::Service.new "http://test.com/test.svc", { :namespace => "NW" }
|
889
|
+
svc.Products.expand('Category').expand('Category/Products').top(2)
|
890
|
+
products = svc.execute
|
891
|
+
products.first.Category.CategoryID.should eq 1
|
892
|
+
end
|
893
|
+
|
894
|
+
it "should successfully parse the Category children Products" do
|
895
|
+
svc = OData::Service.new "http://test.com/test.svc", { :namespace => "NW" }
|
896
|
+
svc.Products.expand('Category').expand('Category/Products').top(2)
|
897
|
+
products = svc.execute
|
898
|
+
products.first.Category.Products.length.should eq 12
|
899
|
+
end
|
761
900
|
|
901
|
+
it "should successfully parse the Category's child Product properties" do
|
902
|
+
svc = OData::Service.new "http://test.com/test.svc", { :namespace => "NW" }
|
903
|
+
svc.Products.expand('Category').expand('Category/Products').top(2)
|
904
|
+
products = svc.execute
|
905
|
+
products.first.Category.Products.first.ProductName.should eq "Chai"
|
762
906
|
end
|
763
907
|
end
|
764
908
|
end
|
@@ -776,7 +920,7 @@ module OData
|
|
776
920
|
# This date was returned in the Netflix OData service and failed with an ArgumentError: out of range using 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
|
777
921
|
svc = OData::Service.new "http://test.com/test.svc/"
|
778
922
|
element_to_parse = Nokogiri::XML.parse('<d:AvailableFrom m:type="Edm.DateTime">2100-01-01T00:00:00</d:AvailableFrom>').elements[0]
|
779
|
-
lambda { svc.
|
923
|
+
lambda { svc.parse_value_xml(element_to_parse) }.should_not raise_exception
|
780
924
|
end
|
781
925
|
end
|
782
926
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_odata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -194,7 +194,7 @@ dependencies:
|
|
194
194
|
requirements:
|
195
195
|
- - ~>
|
196
196
|
- !ruby/object:Gem::Version
|
197
|
-
version: 1.
|
197
|
+
version: 1.11.0
|
198
198
|
type: :development
|
199
199
|
prerelease: false
|
200
200
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -202,7 +202,7 @@ dependencies:
|
|
202
202
|
requirements:
|
203
203
|
- - ~>
|
204
204
|
- !ruby/object:Gem::Version
|
205
|
-
version: 1.
|
205
|
+
version: 1.11.0
|
206
206
|
- !ruby/object:Gem::Dependency
|
207
207
|
name: guard
|
208
208
|
requirement: !ruby/object:Gem::Requirement
|
@@ -258,7 +258,7 @@ dependencies:
|
|
258
258
|
requirements:
|
259
259
|
- - ~>
|
260
260
|
- !ruby/object:Gem::Version
|
261
|
-
version: 2.
|
261
|
+
version: 2.5.0
|
262
262
|
type: :development
|
263
263
|
prerelease: false
|
264
264
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -266,7 +266,39 @@ dependencies:
|
|
266
266
|
requirements:
|
267
267
|
- - ~>
|
268
268
|
- !ruby/object:Gem::Version
|
269
|
-
version: 2.
|
269
|
+
version: 2.5.0
|
270
|
+
- !ruby/object:Gem::Dependency
|
271
|
+
name: simplecov
|
272
|
+
requirement: !ruby/object:Gem::Requirement
|
273
|
+
none: false
|
274
|
+
requirements:
|
275
|
+
- - ~>
|
276
|
+
- !ruby/object:Gem::Version
|
277
|
+
version: 0.7.1
|
278
|
+
type: :development
|
279
|
+
prerelease: false
|
280
|
+
version_requirements: !ruby/object:Gem::Requirement
|
281
|
+
none: false
|
282
|
+
requirements:
|
283
|
+
- - ~>
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: 0.7.1
|
286
|
+
- !ruby/object:Gem::Dependency
|
287
|
+
name: coveralls
|
288
|
+
requirement: !ruby/object:Gem::Requirement
|
289
|
+
none: false
|
290
|
+
requirements:
|
291
|
+
- - ~>
|
292
|
+
- !ruby/object:Gem::Version
|
293
|
+
version: 0.6.7
|
294
|
+
type: :development
|
295
|
+
prerelease: false
|
296
|
+
version_requirements: !ruby/object:Gem::Requirement
|
297
|
+
none: false
|
298
|
+
requirements:
|
299
|
+
- - ~>
|
300
|
+
- !ruby/object:Gem::Version
|
301
|
+
version: 0.6.7
|
270
302
|
description: An OData Client Library for Ruby. Use this to interact with OData services
|
271
303
|
email:
|
272
304
|
- damien.white@visoftinc.com
|
@@ -274,8 +306,10 @@ executables: []
|
|
274
306
|
extensions: []
|
275
307
|
extra_rdoc_files: []
|
276
308
|
files:
|
309
|
+
- .coveralls.yml
|
277
310
|
- .gitignore
|
278
311
|
- .rspec
|
312
|
+
- .simplecov
|
279
313
|
- .travis.yml
|
280
314
|
- .yardopts
|
281
315
|
- CHANGELOG.md
|
@@ -322,6 +356,7 @@ files:
|
|
322
356
|
- features/support/pickle.rb
|
323
357
|
- features/support/vcr.rb
|
324
358
|
- features/type_conversion.feature
|
359
|
+
- gemfiles/Gemfile.ruby187
|
325
360
|
- lib/ruby_odata.rb
|
326
361
|
- lib/ruby_odata/association.rb
|
327
362
|
- lib/ruby_odata/class_builder.rb
|
@@ -343,6 +378,12 @@ files:
|
|
343
378
|
- spec/fixtures/inheritance/edmx_pluralsight.xml
|
344
379
|
- spec/fixtures/inheritance/result_pluralsight_courses.xml
|
345
380
|
- spec/fixtures/links/result_links_query.xml
|
381
|
+
- spec/fixtures/ms_system_center/edmx_ms_system_center.xml
|
382
|
+
- spec/fixtures/ms_system_center/hardware_profiles.xml
|
383
|
+
- spec/fixtures/ms_system_center/virtual_machines.xml
|
384
|
+
- spec/fixtures/ms_system_center/vm_templates.xml
|
385
|
+
- spec/fixtures/nested_expands/edmx_northwind.xml
|
386
|
+
- spec/fixtures/nested_expands/northwind_products_category_expands.xml
|
346
387
|
- spec/fixtures/partial/partial_feed_metadata.xml
|
347
388
|
- spec/fixtures/partial/partial_feed_part_1.xml
|
348
389
|
- spec/fixtures/partial/partial_feed_part_2.xml
|
@@ -488,7 +529,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
488
529
|
version: '0'
|
489
530
|
segments:
|
490
531
|
- 0
|
491
|
-
hash: -
|
532
|
+
hash: -4478862000814865211
|
492
533
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
493
534
|
none: false
|
494
535
|
requirements:
|
@@ -497,7 +538,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
497
538
|
version: '0'
|
498
539
|
segments:
|
499
540
|
- 0
|
500
|
-
hash: -
|
541
|
+
hash: -4478862000814865211
|
501
542
|
requirements: []
|
502
543
|
rubyforge_project: ruby-odata
|
503
544
|
rubygems_version: 1.8.25
|
@@ -552,6 +593,12 @@ test_files:
|
|
552
593
|
- spec/fixtures/inheritance/edmx_pluralsight.xml
|
553
594
|
- spec/fixtures/inheritance/result_pluralsight_courses.xml
|
554
595
|
- spec/fixtures/links/result_links_query.xml
|
596
|
+
- spec/fixtures/ms_system_center/edmx_ms_system_center.xml
|
597
|
+
- spec/fixtures/ms_system_center/hardware_profiles.xml
|
598
|
+
- spec/fixtures/ms_system_center/virtual_machines.xml
|
599
|
+
- spec/fixtures/ms_system_center/vm_templates.xml
|
600
|
+
- spec/fixtures/nested_expands/edmx_northwind.xml
|
601
|
+
- spec/fixtures/nested_expands/northwind_products_category_expands.xml
|
555
602
|
- spec/fixtures/partial/partial_feed_metadata.xml
|
556
603
|
- spec/fixtures/partial/partial_feed_part_1.xml
|
557
604
|
- spec/fixtures/partial/partial_feed_part_2.xml
|