ruby_odata 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,61 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:gp="http://www.sap.com/Protocols/SAPData/GenericPlayer" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData">
3
+ <edmx:DataServices m:DataServiceVersion="2.0">
4
+ <Schema Namespace="DEMO_FLIGHT" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
5
+ <EntityType Name="flight_data" m:HasStream="false" sap:content-version="1">
6
+ <Key>
7
+ <PropertyRef Name="scheme_id"/>
8
+ <PropertyRef Name="value"/>
9
+ <PropertyRef Name="scheme_agency_id"/>
10
+ </Key>
11
+ <Property Name="scheme_id" Type="Edm.String" Nullable="false" MaxLength="30" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
12
+ <Property Name="airlineid" Type="Edm.String" MaxLength="3" sap:label="Airline" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
13
+ <Property Name="value" Type="Edm.String" Nullable="false" MaxLength="72" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
14
+ <Property Name="scheme_agency_id" Type="Edm.String" Nullable="false" MaxLength="16" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
15
+ </EntityType>
16
+ <EntityType Name="z_demo_flight" m:HasStream="false" sap:content-version="1">
17
+ <Key>
18
+ <PropertyRef Name="scheme_id"/>
19
+ <PropertyRef Name="scheme_agency_id"/>
20
+ <PropertyRef Name="value"/>
21
+ </Key>
22
+ <Property Name="cityto" Type="Edm.String" MaxLength="20" sap:label="Arrival city" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
23
+ <Property Name="scheme_id" Type="Edm.String" Nullable="false" MaxLength="30" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
24
+ <Property Name="curr" Type="Edm.String" MaxLength="5" sap:label="Airline local currency" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
25
+ <Property Name="businmax" Type="Edm.Int32" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
26
+ <Property Name="arrdate" Type="Edm.DateTime" Precision="8" sap:label="Arrival date" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
27
+ <Property Name="deptime" Type="Edm.Time" Precision="6" sap:label="Departure time" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
28
+ <Property Name="firstmax" Type="Edm.Int32" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
29
+ <Property Name="price" Type="Edm.Decimal" Precision="23" Scale="4" sap:label="Airfare" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
30
+ <Property Name="businfree" Type="Edm.Int32" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
31
+ <Property Name="scheme_agency_id" Type="Edm.String" Nullable="false" MaxLength="16" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
32
+ <Property Name="airline" Type="Edm.String" MaxLength="20" sap:label="Airline" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
33
+ <Property Name="economax" Type="Edm.Int32" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
34
+ <Property Name="cityfrom" Type="Edm.String" MaxLength="20" sap:label="Depart. city" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
35
+ <Property Name="airportfr" Type="Edm.String" MaxLength="3" sap:label="Departure airport" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
36
+ <Property Name="connectid" Type="Edm.String" MaxLength="4" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
37
+ <Property Name="firstfree" Type="Edm.Int32" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
38
+ <Property Name="econofree" Type="Edm.Int32" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
39
+ <Property Name="airlineid" Type="Edm.String" MaxLength="2" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
40
+ <Property Name="curr_iso" Type="Edm.String" MaxLength="3" sap:label="ISO code" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
41
+ <Property Name="value" Type="Edm.String" Nullable="false" MaxLength="72" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
42
+ <Property Name="flightdate" Type="Edm.DateTime" Nullable="true" Precision="0" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
43
+ <Property Name="airportto" Type="Edm.String" MaxLength="3" sap:label="Destination airport" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
44
+ <Property Name="arrtime" Type="Edm.Time" Precision="6" sap:label="Arrival Time" sap:creatable="false" sap:updatable="false" sap:filterable="false"/>
45
+ <NavigationProperty Name="flight_data_r" Relationship="DEMO_FLIGHT.flight_data_r" FromRole="FromRole_z_demo_flight_flight_data" ToRole="ToRole_flight_data_z_demo_flight"/>
46
+ </EntityType>
47
+ <Association Name="flight_data_r" sap:content-version="1">
48
+ <End Type="DEMO_FLIGHT.z_demo_flight" Multiplicity="0..1" Role="FromRole_z_demo_flight_flight_data"/>
49
+ <End Type="DEMO_FLIGHT.flight_data" Multiplicity="0..1" Role="ToRole_flight_data_z_demo_flight"/>
50
+ </Association>
51
+ <EntityContainer Name="DEMO_FLIGHT" m:IsDefaultEntityContainer="true">
52
+ <EntitySet Name="flight_dataCollection" EntityType="DEMO_FLIGHT.flight_data" sap:content-version="1" sap:creatable="false" sap:updatable="false" sap:deletable="false"/>
53
+ <EntitySet Name="z_demo_flightCollection" EntityType="DEMO_FLIGHT.z_demo_flight" sap:content-version="1" sap:creatable="false" sap:updatable="false" sap:deletable="false"/>
54
+ <AssociationSet Name="AssocSet_flight_data_r" Association="DEMO_FLIGHT.flight_data_r" sap:content-version="1" sap:creatable="false" sap:updatable="false" sap:deletable="false">
55
+ <End EntitySet="z_demo_flightCollection" Role="FromRole_z_demo_flight_flight_data"/>
56
+ <End EntitySet="flight_dataCollection" Role="ToRole_flight_data_z_demo_flight"/>
57
+ </AssociationSet>
58
+ </EntityContainer>
59
+ </Schema>
60
+ </edmx:DataServices>
61
+ </edmx:Edmx>
@@ -0,0 +1,81 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <atom:feed xml:base="HTTP://GW.ESWORKPLACE.SAP.COM:80/sap/opu/sdata/sap/DEMO_FLIGHT/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData">
3
+ <atom:id>HTTP://GW.ESWORKPLACE.SAP.COM:80/sap/opu/sdata/sap/DEMO_FLIGHT/z_demo_flightCollection</atom:id>
4
+ <atom:link href="z_demo_flightCollection" rel="self" type="application/atom+xml;type=feed"/>
5
+ <atom:title>zDemoFlightCollection</atom:title>
6
+ <atom:updated>2011-09-23T01:17:51Z</atom:updated>
7
+ <atom:entry>
8
+ <atom:content type="application/xml">
9
+ <m:properties>
10
+ <d:value>020408_AA001720081001</d:value>
11
+ <d:scheme_id>Z_DEMO_FLIGHT</d:scheme_id>
12
+ <d:scheme_agency_id>HU2_800</d:scheme_agency_id>
13
+ <d:cityto>SAN FRANCISCO</d:cityto>
14
+ <d:curr>USD</d:curr>
15
+ <d:businmax>0</d:businmax>
16
+ <d:arrdate m:Type="Edm.DateTime">2008-10-01T00:00:00</d:arrdate>
17
+ <d:deptime m:Type="Edm.Time">PT11H00M00S</d:deptime>
18
+ <d:firstmax>0</d:firstmax>
19
+ <d:price m:Type="Edm.Decimal">422.9400</d:price>
20
+ <d:businfree>0</d:businfree>
21
+ <d:airline>American Airlines</d:airline>
22
+ <d:economax>0</d:economax>
23
+ <d:cityfrom>NEW YORK</d:cityfrom>
24
+ <d:airportfr>JFK</d:airportfr>
25
+ <d:connectid>00000000</d:connectid>
26
+ <d:firstfree>0</d:firstfree>
27
+ <d:econofree>0</d:econofree>
28
+ <d:airlineid/>
29
+ <d:curr_iso>USD</d:curr_iso>
30
+ <d:flightdate m:Type="Edm.DateTime" m:null="true"/>
31
+ <d:airportto>SFO</d:airportto>
32
+ <d:arrtime m:Type="Edm.Time">PT14H01M00S</d:arrtime>
33
+ </m:properties>
34
+ </atom:content>
35
+ <atom:id>HTTP://GW.ESWORKPLACE.SAP.COM:80/sap/opu/sdata/sap/DEMO_FLIGHT/z_demo_flightCollection(value='020408_AA001720081001',scheme_id='Z_DEMO_FLIGHT',scheme_agency_id='HU2_800')</atom:id>
36
+ <atom:link href="z_demo_flightCollection(value='020408_AA001720081001',scheme_id='Z_DEMO_FLIGHT',scheme_agency_id='HU2_800')" rel="self" type="application/atom+xml;type=entry"/>
37
+ <atom:link gateway:abap_name="FLIGHT_DATA_R" href="z_demo_flightCollection(value='020408_AA001720081001',scheme_id='Z_DEMO_FLIGHT',scheme_agency_id='HU2_800')/flight_data_r" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/flight_data_r" type="application/atom+xml;type=entry" title="flight_data_r" xmlns:gateway="http://www.sap.com/Protocols/Gateway">
38
+ <sap:icon/>
39
+ </atom:link>
40
+ <atom:title>z_demo_flight</atom:title>
41
+ <atom:updated>2011-09-23T01:17:51Z</atom:updated>
42
+ <sap:icon/>
43
+ </atom:entry>
44
+ <atom:entry>
45
+ <atom:content type="application/xml">
46
+ <m:properties>
47
+ <d:value>020408_AA001720081029</d:value>
48
+ <d:scheme_id>Z_DEMO_FLIGHT</d:scheme_id>
49
+ <d:scheme_agency_id>HU2_800</d:scheme_agency_id>
50
+ <d:cityto>SAN FRANCISCO</d:cityto>
51
+ <d:curr>USD</d:curr>
52
+ <d:businmax>0</d:businmax>
53
+ <d:arrdate m:Type="Edm.DateTime">2008-10-29T00:00:00</d:arrdate>
54
+ <d:deptime m:Type="Edm.Time">PT11H00M00S</d:deptime>
55
+ <d:firstmax>0</d:firstmax>
56
+ <d:price m:Type="Edm.Decimal">422.9400</d:price>
57
+ <d:businfree>0</d:businfree>
58
+ <d:airline>American Airlines</d:airline>
59
+ <d:economax>0</d:economax>
60
+ <d:cityfrom>NEW YORK</d:cityfrom>
61
+ <d:airportfr>JFK</d:airportfr>
62
+ <d:connectid>00000000</d:connectid>
63
+ <d:firstfree>0</d:firstfree>
64
+ <d:econofree>0</d:econofree>
65
+ <d:airlineid/>
66
+ <d:curr_iso>USD</d:curr_iso>
67
+ <d:flightdate m:Type="Edm.DateTime" m:null="true"/>
68
+ <d:airportto>SFO</d:airportto>
69
+ <d:arrtime m:Type="Edm.Time">PT14H01M00S</d:arrtime>
70
+ </m:properties>
71
+ </atom:content>
72
+ <atom:id>HTTP://GW.ESWORKPLACE.SAP.COM:80/sap/opu/sdata/sap/DEMO_FLIGHT/z_demo_flightCollection(value='020408_AA001720081029',scheme_id='Z_DEMO_FLIGHT',scheme_agency_id='HU2_800')</atom:id>
73
+ <atom:link href="z_demo_flightCollection(value='020408_AA001720081029',scheme_id='Z_DEMO_FLIGHT',scheme_agency_id='HU2_800')" rel="self" type="application/atom+xml;type=entry"/>
74
+ <atom:link gateway:abap_name="FLIGHT_DATA_R" href="z_demo_flightCollection(value='020408_AA001720081029',scheme_id='Z_DEMO_FLIGHT',scheme_agency_id='HU2_800')/flight_data_r" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/flight_data_r" type="application/atom+xml;type=entry" title="flight_data_r" xmlns:gateway="http://www.sap.com/Protocols/Gateway">
75
+ <sap:icon/>
76
+ </atom:link>
77
+ <atom:title>z_demo_flight</atom:title>
78
+ <atom:updated>2011-09-23T01:17:51Z</atom:updated>
79
+ <sap:icon/>
80
+ </atom:entry>
81
+ </atom:feed>
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module OData
4
+ describe PropertyMetadata do
5
+ describe "#initialize" do
6
+ it "parses an EDMX property with the essentials (name, type, nullable)" do
7
+ property_element = RSpecSupport::ElementHelpers.string_to_element('<Property Name="Id" Type="Edm.String" Nullable="false" />')
8
+ property_metadata = PropertyMetadata.new property_element
9
+ property_metadata.name.should eq "Id"
10
+ property_metadata.type.should eq "Edm.String"
11
+ property_metadata.nullable.should eq false
12
+ end
13
+ it "parses an EDMX property where nullable is true" do
14
+ property_element = RSpecSupport::ElementHelpers.string_to_element('<Property Name="Id" Type="Edm.String" Nullable="true" />')
15
+ property_metadata = PropertyMetadata.new property_element
16
+ property_metadata.nullable.should eq true
17
+ end
18
+ it "parses an EDMX property with nil for missing attributes" do
19
+ property_element = RSpecSupport::ElementHelpers.string_to_element('<Property Name="Id" Type="Edm.String" Nullable="false" />')
20
+ property_metadata = PropertyMetadata.new property_element
21
+ property_metadata.fc_target_path.should be_nil
22
+ property_metadata.fc_keep_in_content.should be_nil
23
+ end
24
+ it "parses an EDMX property with false for missing Nullable attribute" do
25
+ property_element = RSpecSupport::ElementHelpers.string_to_element('<Property Name="Id" Type="Edm.String" />')
26
+ property_metadata = PropertyMetadata.new property_element
27
+ property_metadata.nullable.should eq false
28
+ end
29
+ it "parses an EDMX property with the fc_target_path and fc_keep_in_content attribute" do
30
+ property_element = RSpecSupport::ElementHelpers.string_to_element('<Property Name="Title" Type="Edm.String" Nullable="true" m:FC_TargetPath="SyndicationTitle" m:FC_ContentKind="text" m:FC_KeepInContent="false" />')
31
+ property_metadata = PropertyMetadata.new property_element
32
+ property_metadata.fc_target_path.should eq "SyndicationTitle"
33
+ property_metadata.fc_keep_in_content.should eq false
34
+ end
35
+ it "parses an EDMX property where fc_keep_in_content is true" do
36
+ property_element = RSpecSupport::ElementHelpers.string_to_element('<Property Name="Title" Type="Edm.String" Nullable="true" m:FC_TargetPath="SyndicationTitle" m:FC_ContentKind="text" m:FC_KeepInContent="true" />')
37
+ property_metadata = PropertyMetadata.new property_element
38
+ property_metadata.fc_keep_in_content.should eq true
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ module OData
4
+ describe QueryBuilder do
5
+ describe "#initialize" do
6
+ it "handles additional parameters" do
7
+ builder = QueryBuilder.new 'Products', { :x=>1, :y=>2 }
8
+ builder.query.should eq "Products?x=1&y=2"
9
+ end
10
+ it "handles empty additional parameters" do
11
+ builder = QueryBuilder.new 'Products'
12
+ builder.query.should eq "Products"
13
+ end
14
+ end
15
+ describe "#query" do
16
+ it "should append additional parameters to the end" do
17
+ builder = QueryBuilder.new 'Products', { :x=>1, :y=>2 }
18
+ builder.top(10)
19
+ builder.query.should eq "Products?$top=10&x=1&y=2"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -19,7 +19,71 @@ module OData
19
19
 
20
20
  lambda { OData::Service.new "http://test.com/test.svc" }.should_not raise_error
21
21
  end
22
+
23
+ describe "additional query string parameters" do
24
+ before(:each) do
25
+ # Required for the build_classes method
26
+ stub_request(:get, /http:\/\/test\.com\/test\.svc\/\$metadata(?:\?.+)?/).
27
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
28
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/edmx_empty.xml", __FILE__)), :headers => {})
29
+ end
30
+ it "should accept additional query string parameters" do
31
+ svc = OData::Service.new "http://test.com/test.svc/", { :additional_params => { :x=>1, :y=>2 } }
32
+ svc.options[:additional_params].should eq Hash[:x=>1, :y=>2]
33
+ end
34
+ it "should call the correct metadata uri when additional_params are passed in" do
35
+ svc = OData::Service.new "http://test.com/test.svc/", { :additional_params => { :x => 1, :y => 2 } }
36
+ a_request(:get, "http://test.com/test.svc/$metadata?x=1&y=2").should have_been_made
37
+ end
38
+ end
22
39
  end
40
+
41
+ describe "additional query string parameters" do
42
+ before(:each) do
43
+ # Required for the build_classes method
44
+ stub_request(:any, /http:\/\/test\.com\/test\.svc(?:.*)/).
45
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
46
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/sap/edmx_sap_demo_flight.xml", __FILE__)), :headers => {})
47
+ end
48
+ it "should pass the parameters as part of a query" do
49
+ svc = OData::Service.new "http://test.com/test.svc/", { :additional_params => { :x=>1, :y=>2 } }
50
+ svc.flight_dataCollection
51
+ svc.execute
52
+ a_request(:get, "http://test.com/test.svc/flight_dataCollection?x=1&y=2").should have_been_made
53
+ end
54
+ it "should pass the parameters as part of a save" do
55
+ svc = OData::Service.new "http://test.com/test.svc/", { :additional_params => { :x=>1, :y=>2 } }
56
+ new_flight = ZDemoFlight.new
57
+ svc.AddToflight_dataCollection(new_flight)
58
+ svc.save_changes
59
+ a_request(:post, "http://test.com/test.svc/flight_dataCollection?x=1&y=2").should have_been_made
60
+ end
61
+ it "should pass the parameters as part of an update" do
62
+ svc = OData::Service.new "http://test.com/test.svc/", { :additional_params => { :x=>1, :y=>2 } }
63
+ existing_flight = ZDemoFlight.new
64
+ existing_flight.__metadata = { :uri => "http://test.com/test.svc/flight_dataCollection/1" }
65
+ svc.update_object(existing_flight)
66
+ svc.save_changes
67
+ a_request(:put, "http://test.com/test.svc/flight_dataCollection/1?x=1&y=2").should have_been_made
68
+ end
69
+ it "should pass the parameters as part of a delete" do
70
+ svc = OData::Service.new "http://test.com/test.svc/", { :additional_params => { :x=>1, :y=>2 } }
71
+ existing_flight = ZDemoFlight.new
72
+ existing_flight.__metadata = { :uri => "http://test.com/test.svc/flight_dataCollection/1" }
73
+ svc.delete_object(existing_flight)
74
+ svc.save_changes
75
+ a_request(:delete, "http://test.com/test.svc/flight_dataCollection/1?x=1&y=2").should have_been_made
76
+ end
77
+ it "should pass the parameters as part of a batch save" do
78
+ svc = OData::Service.new "http://test.com/test.svc/", { :additional_params => { :x=>1, :y=>2 } }
79
+ new_flight = ZDemoFlight.new
80
+ svc.AddToflight_dataCollection(new_flight)
81
+ new_flight2 = ZDemoFlight.new
82
+ svc.AddToflight_dataCollection(new_flight2)
83
+ svc.save_changes
84
+ a_request(:post, "http://test.com/test.svc/$batch?x=1&y=2").should have_been_made
85
+ end
86
+ end
23
87
 
24
88
  describe "lowercase collections" do
25
89
  before(:each) do
@@ -39,5 +103,165 @@ module OData
39
103
  lambda { svc.send('acronyms') }.should_not raise_error
40
104
  end
41
105
  end
106
+
107
+ describe "handling of SAP results" do
108
+ before(:each) do
109
+ # Required for the build_classes method
110
+ stub_request(:get, "http://test.com/test.svc/$metadata").
111
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
112
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/sap/edmx_sap_demo_flight.xml", __FILE__)), :headers => {})
113
+
114
+ stub_request(:get, "http://test.com/test.svc/z_demo_flightCollection").
115
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
116
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/sap/result_sap_demo_flight_missing_category.xml", __FILE__)), :headers => {})
117
+ end
118
+
119
+ it "should handle entities without a category element" do
120
+ svc = OData::Service.new "http://test.com/test.svc/"
121
+ svc.z_demo_flightCollection
122
+ results = svc.execute
123
+ results.first.should be_a_kind_of(ZDemoFlight)
124
+ end
125
+ end
126
+
127
+ describe "collections, objects, etc" do
128
+ before(:each) do
129
+ # Metadata
130
+ stub_request(:get, "http://test.com/test.svc/$metadata").
131
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
132
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/feed_customization/edmx_feed_customization.xml", __FILE__)), :headers => {})
133
+
134
+ # Content - Products
135
+ stub_request(:get, /http:\/\/test\.com\/test\.svc\/Products(?:.*)/).
136
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
137
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/feed_customization/result_feed_customization_products_expand.xml", __FILE__)), :headers => {})
138
+
139
+ # Content - Categories expanded Products
140
+ stub_request(:get, /http:\/\/test\.com\/test\.svc\/Categories(?:.*)/).
141
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
142
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/feed_customization/result_feed_customization_categories_expand.xml", __FILE__)), :headers => {})
143
+ end
144
+ after(:each) do
145
+ Object.send(:remove_const, 'Product')
146
+ Object.send(:remove_const, 'Category')
147
+ end
148
+ describe "handling feed customizations" do
149
+ describe "property metadata" do
150
+ it "should fill the class_metadata hash" do
151
+ svc = OData::Service.new "http://test.com/test.svc/"
152
+ svc.class_metadata.should_not be_empty
153
+ end
154
+ it "should add a key (based on the name) for each property class_metadata hash" do
155
+ svc = OData::Service.new "http://test.com/test.svc/"
156
+ svc.class_metadata['Product'].should have_key 'ID'
157
+ svc.class_metadata['Product'].should have_key 'Name'
158
+ svc.class_metadata['Product'].should have_key 'Description'
159
+ end
160
+ it "should have a PropertyMetadata object for each property class_metadata hash" do
161
+ svc = OData::Service.new "http://test.com/test.svc/"
162
+ svc.class_metadata['Product']['ID'].should be_a OData::PropertyMetadata
163
+ svc.class_metadata['Product']['Name'].should be_a OData::PropertyMetadata
164
+ svc.class_metadata['Product']['Description'].should be_a OData::PropertyMetadata
165
+ end
166
+ it "should have the correct PropertyMetadata object for Id" do
167
+ svc = OData::Service.new "http://test.com/test.svc/"
168
+ meta = svc.class_metadata['Product']['ID']
169
+ meta.name.should eq 'ID'
170
+ meta.type.should eq 'Edm.Int32'
171
+ meta.nullable.should eq false
172
+ meta.fc_target_path.should be_nil
173
+ meta.fc_keep_in_content.should be_nil
174
+ end
175
+ it "should have the correct PropertyMetadata object for Name" do
176
+ svc = OData::Service.new "http://test.com/test.svc/"
177
+ meta = svc.class_metadata['Product']['Name']
178
+ meta.name.should eq 'Name'
179
+ meta.type.should eq 'Edm.String'
180
+ meta.nullable.should eq true
181
+ meta.fc_target_path.should eq "SyndicationTitle"
182
+ meta.fc_keep_in_content.should eq false
183
+ end
184
+ it "should have the correct PropertyMetadata object for Description" do
185
+ svc = OData::Service.new "http://test.com/test.svc/"
186
+ meta = svc.class_metadata['Product']['Description']
187
+ meta.name.should eq 'Description'
188
+ meta.type.should eq 'Edm.String'
189
+ meta.nullable.should eq true
190
+ meta.fc_target_path.should eq "SyndicationSummary"
191
+ meta.fc_keep_in_content.should eq false
192
+ end
193
+ end
194
+
195
+ describe "single class" do
196
+ it "should handle properties where a property is represented in the syndication title instead of the properties collection" do
197
+ svc = OData::Service.new "http://test.com/test.svc/"
198
+ svc.Products
199
+ results = svc.execute
200
+ results.first.Name.should eq "Bread"
201
+ end
202
+ it "should handle properties where a property is represented in the syndication summary instead of the properties collection" do
203
+ svc = OData::Service.new "http://test.com/test.svc/"
204
+ svc.Products
205
+ results = svc.execute
206
+ results.first.Description.should eq "Whole grain bread"
207
+ end
208
+ end
209
+
210
+ describe "expanded inline class" do
211
+ it "should handle properties where a property is represented in the syndication title instead of the properties collection" do
212
+ svc = OData::Service.new "http://test.com/test.svc/"
213
+ svc.Categories
214
+ results = svc.execute
215
+
216
+ beverages = results[1]
217
+
218
+ milk = beverages.Products.first
219
+ milk.Name.should eq "Milk"
220
+ milk.Description.should eq "Low fat milk"
221
+
222
+ lemonade = beverages.Products.last
223
+ lemonade.Name.should eq "Pink Lemonade"
224
+ lemonade.Description.should eq "36 Ounce Cans (Pack of 3)"
225
+ end
226
+ end
227
+ end
228
+
229
+ describe "handling inline collections/properties" do
230
+ it "should make plural named properties arrays and not a single class" do
231
+ svc = OData::Service.new "http://test.com/test.svc/"
232
+ svc.Categories
233
+ results = svc.execute
234
+ food = results[0]
235
+
236
+ food.Products.should be_an Array
237
+ end
238
+
239
+ it "should not make an array if the navigation property name is singular" do
240
+ svc = OData::Service.new "http://test.com/test.svc/"
241
+ svc.Products
242
+ results = svc.execute
243
+ product = results.first
244
+ product.Category.should_not be_an Array
245
+ end
246
+ end
247
+ end
248
+ end
249
+
250
+ describe_private OData::Service do
251
+ describe "parse value" do
252
+ before(:each) do
253
+ # Required for the build_classes method
254
+ stub_request(:get, "http://test.com/test.svc/$metadata").
255
+ with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).
256
+ to_return(:status => 200, :body => File.new(File.expand_path("../fixtures/edmx_empty.xml", __FILE__)), :headers => {})
257
+ end
258
+
259
+ it "should not error on an 'out of range' date" do
260
+ # 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]
261
+ svc = OData::Service.new "http://test.com/test.svc/"
262
+ element_to_parse = Nokogiri::XML.parse('<d:AvailableFrom m:type="Edm.DateTime">2100-01-01T00:00:00</d:AvailableFrom>').elements[0]
263
+ lambda { svc.parse_value(element_to_parse) }.should_not raise_exception
264
+ end
265
+ end
42
266
  end
43
267
  end
@@ -1,2 +1,4 @@
1
1
  require 'ruby_odata'
2
- require 'webmock/rspec'
2
+ require 'webmock/rspec'
3
+
4
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }