ruby_odata 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +3 -2
  2. data/.travis.yml +2 -1
  3. data/.yardopts +6 -0
  4. data/CHANGELOG.md +102 -0
  5. data/Guardfile +14 -0
  6. data/README.md +285 -0
  7. data/Rakefile +0 -7
  8. data/features/basic_auth.feature +3 -2
  9. data/features/batch_request.feature +7 -6
  10. data/features/cassettes/basic_auth_protected_resource.yml +57 -0
  11. data/features/cassettes/batch_request_additions.yml +69 -0
  12. data/features/cassettes/batch_request_deletes.yml +69 -0
  13. data/features/cassettes/batch_request_updates.yml +69 -0
  14. data/features/cassettes/clean_database_for_testing.yml +46 -0
  15. data/features/cassettes/cucumber_tags/basic_auth.yml +297 -0
  16. data/features/cassettes/cucumber_tags/batch_request.yml +1459 -0
  17. data/features/cassettes/cucumber_tags/complex_types.yml +326 -0
  18. data/features/cassettes/cucumber_tags/error_handling.yml +64 -0
  19. data/features/cassettes/cucumber_tags/query_builder.yml +2025 -0
  20. data/features/cassettes/cucumber_tags/service.yml +234 -0
  21. data/features/cassettes/cucumber_tags/service_manage.yml +937 -0
  22. data/features/cassettes/cucumber_tags/service_methods.yml +647 -0
  23. data/features/cassettes/cucumber_tags/ssl.yml +203 -0
  24. data/features/cassettes/cucumber_tags/type_conversion.yml +337 -0
  25. data/features/cassettes/service_manage_additions.yml +65 -0
  26. data/features/cassettes/service_manage_deletions.yml +58 -0
  27. data/features/cassettes/service_manage_deletions_2.yml +58 -0
  28. data/features/cassettes/unsecured_metadata.yml +89 -0
  29. data/features/complex_types.feature +4 -3
  30. data/features/error_handling.feature +14 -0
  31. data/features/query_builder.feature +30 -9
  32. data/features/service.feature +4 -3
  33. data/features/service_manage.feature +6 -5
  34. data/features/service_methods.feature +3 -2
  35. data/features/ssl.feature +8 -8
  36. data/features/step_definitions/service_steps.rb +38 -24
  37. data/features/support/env.rb +1 -3
  38. data/features/support/hooks.rb +3 -2
  39. data/features/support/pickle.rb +29 -18
  40. data/features/support/vcr.rb +24 -0
  41. data/features/type_conversion.feature +16 -17
  42. data/lib/ruby_odata/association.rb +7 -6
  43. data/lib/ruby_odata/class_builder.rb +6 -7
  44. data/lib/ruby_odata/exceptions.rb +4 -0
  45. data/lib/ruby_odata/helpers.rb +11 -0
  46. data/lib/ruby_odata/operation.rb +5 -6
  47. data/lib/ruby_odata/property_metadata.rb +4 -5
  48. data/lib/ruby_odata/query_builder.rb +98 -63
  49. data/lib/ruby_odata/service.rb +118 -103
  50. data/lib/ruby_odata/version.rb +3 -1
  51. data/lib/ruby_odata.rb +20 -18
  52. data/ruby_odata.gemspec +16 -12
  53. data/spec/query_builder_spec.rb +78 -14
  54. data/spec/service_spec.rb +83 -83
  55. data/spec/support/sample_service_matcher.rb +15 -0
  56. data/test/RubyODataService/RubyODataService/App_Data/.gitkeep +0 -0
  57. data/test/blueprints.rb +15 -9
  58. data/test/usage_samples/querying.rb +5 -1
  59. data/test/usage_samples/sample_data.rb +1 -3
  60. metadata +213 -39
  61. data/CHANGELOG.rdoc +0 -88
  62. data/README.rdoc +0 -259
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .yardoc
1
2
  .idea
2
3
  .idea/*
3
4
  rerun.txt
@@ -16,6 +17,6 @@ test/applicationhost.config
16
17
  *ReSharper*
17
18
  *.suo
18
19
  obj
19
- App_Data/
20
20
  *.pdb
21
- test/RubyODataService/RubyODataService/bin/*.xml
21
+ test/RubyODataService/RubyODataService/bin/*.xml
22
+ test/RubyODataService/RubyODataService/App_Data/*.sdf
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
- script: "bundle exec rake spec"
4
+ - 1.9.3
5
+ script: "bundle exec rake"
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --no-cache
2
+ --verbose
3
+ --markup markdown
4
+ --readme README.md
5
+ --hide-void-return
6
+ lib/**/*.rb
data/CHANGELOG.md ADDED
@@ -0,0 +1,102 @@
1
+ # ruby_odata Change Log
2
+
3
+ ### 0.0.1
4
+ * New Features
5
+ * Basic CRUD Operations
6
+ * Query Enhancement: Filters
7
+ * Query Enhancement: Expands
8
+
9
+ ### 0.0.2
10
+ * New Features
11
+ * Query Enhancement: Order By (both desc and asc)
12
+
13
+ ### 0.0.3
14
+ * Bug Fixes
15
+ * Rearranged code to match the gem name. Things were mismatched between odata_ruby and ruby_odata.
16
+
17
+ ### 0.0.4
18
+ * New Features
19
+ * Query Enhancement: skip
20
+ * Query Enhancement: top
21
+ * Ability to perform paging using skip and top together
22
+ * Updated README with examples for order_by, skip, and top
23
+
24
+ ### 0.0.5
25
+ * Bug Fixes
26
+ * Works with Ruby 1.9.1
27
+ * Works with ActiveSupport 3.0.0.beta4
28
+
29
+ ### 0.0.6
30
+ * New Features
31
+ * Ability to batch saves (Adds, Updates, Deletes); this will help save on network chatter
32
+
33
+ ### 0.0.7
34
+ * New Features
35
+ * Complex Types are now supported
36
+ * Support for Edm.Int16, Edm.Int32, Edm.Int64
37
+ * Support for Edm.Decimal
38
+ * Support for Edm.DateTime
39
+
40
+ ### 0.0.8
41
+ * New Features
42
+ * Basic HTTP Authentication (thanks J.D. Mullin)
43
+ * Modified cucumber tests to setup the test database so you no longer need to copy them yourself
44
+ * Support for nullable elements returned from the Data Service (m:null ="true")
45
+ * Bug Fixes
46
+ * ActiveSupport 2.3.x (tested 2.3.11) and 3.0.x (tested 3.0.4) are now supported
47
+ * Works with Ruby 1.9.2
48
+
49
+ ### 0.0.9
50
+ * New Features
51
+ * Support for self-signed SSL certificates (thanks J.D. Mullin)
52
+ * Refactored building classes/collections to only make one call to the service
53
+ * Added support for a WCF service with lowercase entities (reported by Klaus Rohe)
54
+ * Bug Fixes
55
+ * Fixed issue with passing a service URL with a trailing slash
56
+ * Other
57
+ * Cleaned up testing by adding a default task to the Rakefile that runs RSpec and Cucumber
58
+
59
+ ### 0.0.10
60
+ * New Features
61
+ * Added the ability to pass additional parameters that are appended to the query string for requests
62
+ * Added initial support for feed customizations (SyndicationTitle and SyndicationSummary)
63
+ * Enhanced ruby_odata's awareness of classes based on the metadata instead of relying on results that are returned
64
+ * Bug Fixes
65
+ * Fixed issues with nested collections (eager loading)
66
+ * Handled ArgumentError on the Time.parse for older versions of Ruby; used DateTime.parse instead if Time.parse fails
67
+ * Removed the camelize method call when building the root URL for collections (Reported by mkoegel, issue #3 on github)
68
+ * Handled building results (classes) where the category element is missing but there is a title element instead. (Reported by mkoegel, issue #3 on github in the comments)
69
+ * Other
70
+ * Change HTTP port to 8989 since 8888 conflicts with the Intel AppStore
71
+ * Refactored service step for HTTP calls where the service address is defined within the step making it easier to make changes in the future.
72
+
73
+ ### 0.1.0
74
+ * **BREAKING CHANGES**
75
+ * Previously the ruby_odata `Service.execute` and `Service.save_changes` used to return a single entity object if there was only one result returned. Now, the results are always an Enumerable (except in the case of boolean results like a delete), so if you just need one result, use the `first` method on the result set
76
+ * New Features
77
+ * Support for partial results (thanks arienmalec)
78
+ * Added support for single layer inheritance (thanks to [Scott](http://odetocode.com/Blogs/scott/archive/2010/07/11/odata-and-ruby.aspx))
79
+ * Added support for querying links (see [Issue 10](https://github.com/visoft/ruby_odata/issues/10))
80
+ * Added support for adding links between entities (add_link)
81
+ * Added support for lazy loading
82
+ * Added a convenience method (`first`) for accessing a single result by id
83
+ * Added basic reflection of the entity model via the ruby_odata service
84
+ * Added the ability to create ruby_odata models in a specified namespace to prevent conflicts with local models
85
+ * Added the ability to call function imports exposed by the WCF Data Service
86
+ * Other
87
+ * Changed the test project (for Cucumber integration tests) to use SQL Compact 4, Entity Framework 4.1, and WCF Data Services October 2011 CTP
88
+ * Added [Pickle](https://github.com/ianwhite/pickle) integration to simplify Cucumber step definitions
89
+
90
+ ### 0.1.1
91
+ * New Features
92
+ * Added the `count` method (to `QueryBuilder`) for returning a count from an OData service
93
+ * Added the `navigate` method (to `QueryBuilder`) in order to handle filtering of children
94
+
95
+ * Bug Fixes
96
+ * Escaped IDs in queries where the ID is a string with spaces
97
+
98
+ * Other
99
+ * Goodbye RDoc; Hello Markdown/YARD
100
+ * Refactored exceptions to use proper error classes
101
+ * Integrated [Guard](https://github.com/guard/guard) into the test suite for continuous testing
102
+ * Integrated [VCR](https://github.com/myronmarston/vcr) into test suite in order to run Cucumber steps without running the test server.
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/ruby_odata/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
10
+ guard 'cucumber', :all_after_pass => false, :all_on_start => false do
11
+ watch(%r{^features/.+\.feature$})
12
+ watch(%r{^features/support/.+$}) { 'features' }
13
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
14
+ end
data/README.md ADDED
@@ -0,0 +1,285 @@
1
+ # ruby_odata
2
+
3
+ The **Open Data Protocol** (OData) is a fantastic way to query and update data over standard Web technologies. The ruby_odata library acts as a consumer of OData services.
4
+
5
+ [![Build Status](https://secure.travis-ci.org/visoft/ruby_odata.png)](http://travis-ci.org/visoft/ruby_odata)
6
+
7
+ ## Resources
8
+
9
+ * Source Code (hosted on GitHub): http://github.com/visoft/ruby_odata
10
+ * Documentation (hosted on rdoc.info): http://rdoc.info/projects/visoft/ruby_odata
11
+ * Issue tracking (hosted on GitHub): https://github.com/visoft/ruby_odata/issues
12
+ * Wiki (hosted on GitHub): http://wiki.github.com/visoft/ruby_odata/
13
+ * Gem (hosted on Gemcutter): http://gemcutter.org/gems/ruby_odata
14
+ * Blog articles:
15
+ * [Introducing a Ruby OData Client Library](http://bit.ly/IntroRubyOData)
16
+ * [Ruby OData Update v0.0.7](http://bit.ly/ruby_odata007)
17
+ * [Ruby OData Update v0.0.8](http://bit.ly/ruby_odata008)
18
+ * [Ruby OData Update v0.0.10](http://bit.ly/ruby_odata0010)
19
+
20
+ ## Installation
21
+ You can install ruby_odata as a gem using:
22
+
23
+ gem install ruby_odata
24
+
25
+ ## Usage
26
+
27
+ ### Instantiating the Service
28
+ There are various options that you can pass when creating an instance of the service, these include:
29
+ * username: username for http basic auth
30
+ * password: password for http basic auth
31
+ * verify_ssl: false if no verification, otherwise mode (OpenSSL::SSL::VERIFY_PEER is default)
32
+ * additional_params: a hash of query string params that will be passed on all calls (query, new, update, delete, batch)
33
+ * namespace: a string based namespace to create your objects in. You can specify the namespace using periods as separators (like .NET, for example `VisoftInc.Sample.Models`) or using double colons as separators (like Ruby `VisoftInc::Sample::Models`). By providing a namespace you can prevent naming collisions in your applications.
34
+
35
+ ### Adding
36
+ When you point at a service, an AddTo<EntityName> method is created for you. This method takes in the new entity to create. To commit the change, you need to call the save_changes method on the service. To add a new category for example, you would simply do the following:
37
+
38
+ require 'ruby_odata'
39
+
40
+ svc = OData::Service.new "http://127.0.0.1:8989/SampleService/RubyOData.svc"
41
+ new_category = Category.new
42
+ new_category.Name = "Sample Category"
43
+ svc.AddToCategories(new_category)
44
+ category = svc.save_changes
45
+ puts category.to_json
46
+
47
+ ### Updating
48
+ To update an object, simply pass the modified object to the update_object method on the service. Updating, like adding requires you to call save_changes in order to persist the change. For example:
49
+
50
+ require 'ruby_odata'
51
+
52
+ svc = OData::Service.new "http://127.0.0.1:8989/SampleService/RubyOData.svc"
53
+ new_category = Category.new
54
+ new_category.Name = "Sample Category"
55
+ svc.AddToCategories(new_category)
56
+ category = svc.save_changes
57
+ puts category.to_json
58
+
59
+ category.Name = 'Updated Category'
60
+ svc.update_object(category)
61
+ result = svc.save_changes
62
+ puts "Was the category updated? #{result}"
63
+
64
+ ### Deleting
65
+ Deleting an object involves passing the tracked object to the delete_object method on the service. Deleting is another function that involves the save_changes method (to commit the change back to the server). In this example, we'll add a category and then delete it.
66
+
67
+ require 'ruby_odata'
68
+
69
+ svc = OData::Service.new "http://127.0.0.1:8989/SampleService/RubyOData.svc"
70
+ new_category = Category.new
71
+ new_category.Name = "Sample Category"
72
+ svc.AddToCategories(new_category)
73
+ category = svc.save_changes
74
+ puts category.to_json
75
+
76
+ svc.delete_object(category)
77
+ result = svc.save_changes
78
+ puts "Was the category deleted? #{result}"
79
+
80
+ ### Add Link
81
+ Adding a linkage between entities can now be performed outside of creation or modification of the objects. See the [OData documents](http://www.odata.org/developers/protocols/operations#CreatingLinksbetweenEntries) for more details.
82
+ To add a link between entities, simply call the `add_link` method on the Service passing the parent object, the name of the navigation property, and the child object. Like all save operations, you need to call `save_changes` to persist the changes.
83
+
84
+ svc.add_link(<Parent>, <Navigation Property Name>, <Child>)
85
+ svc.save_changes
86
+
87
+ ### Querying
88
+ Querying is easy, for example to pull all the categories from the SampleService, you simply can run:
89
+
90
+ require 'ruby_odata'
91
+
92
+ svc = OData::Service.new "http://127.0.0.1:8989/SampleService/RubyOData.svc"
93
+ svc.Categories
94
+ categories = svc.execute
95
+ puts categories.to_json
96
+
97
+ You can also expand, add filters, order, skip records, and take only the top X records to the query before executing it. For example:
98
+
99
+ ### Expanding
100
+ Expanding allows you to eagerly load other objects that are children of the root.
101
+ You can use more than one expand on a query.
102
+ For expanding grandchild and lower entities, you must pass in the full path from the root, for example `Products.expand('Orders').expand('Orders/LineItems')`
103
+
104
+ # Without expanding the query
105
+ svc.Products(1)
106
+ prod1 = svc.execute
107
+ puts "Without expanding the query"
108
+ puts "#{prod1.to_json}\n"
109
+
110
+ # With expanding the query
111
+ svc.Products(1).expand('Category')
112
+ prod1 = svc.execute
113
+ puts "With expanding the query"
114
+ puts "#{prod1.to_json}\n"
115
+
116
+ ### Lazy Loading
117
+ If you want to implement lazy loading, the ruby_odata `Service` allows you to perform this. You simply need to call the `load_property` method on the `Service` passing in the object and the navigation property to fill.
118
+
119
+ # Without expanding the query
120
+ svc.Products(1)
121
+ prod1 = svc.execute.first
122
+ puts "#{prod1.to_json}\n"
123
+
124
+ # Use load_property for lazy loading
125
+ svc.load_property(prod1, "Category")
126
+ puts "#{prod1.to_json}\n"
127
+
128
+ ### Filtering
129
+ The syntax for filtering can be found on the [OData Protocol URI Conventions](http://www.odata.org/developers/protocols/uri-conventions#FilterSystemQueryOption) page.
130
+ You can use more than one filter, if you call the filter method multiple times it will before an AND.
131
+
132
+ # You can access by ID (but that isn't is a filter)
133
+ # The syntax is just svc.ENTITYNAME(ID) which is shown in the expanding examples above
134
+
135
+ svc.Products.filter("Name eq 'Product 2'")
136
+ prod = svc.execute
137
+ puts "Filtering on Name eq 'Product 2'"
138
+ puts "#{prod.to_json}"
139
+
140
+ Note you can pass more than one filter in the string, for example (querying Netflix):
141
+
142
+ svc.Titles.filter("Rating eq 'PG' and ReleaseYear eq 1980")
143
+
144
+ Filters can also be chained, by doing this you will create an "and" filter (just like the last example) when it is passed to the server.
145
+
146
+ svc.Titles.filter("Rating eq 'PG'").filter("ReleaseYear eq 1980")
147
+
148
+
149
+ ### Combining Expanding and Filtering
150
+ The query operations follow a [fluent interface](http://en.wikipedia.org/wiki/Fluent_interface), although they can be added by themselves as well as chained
151
+
152
+ svc.Products.filter("Name eq 'Product 2'").expand("Category")
153
+ prod = svc.execute
154
+ puts "Filtering on Name eq 'Product 2' and expanding"
155
+ puts "#{prod.to_json}"
156
+
157
+ ### Order By
158
+ You can order the results by properties of your choice, either ascending or descending.
159
+ Order by are similar to `expands` in that you can use more than one of them on a query.
160
+ For expanding grandchild and lower entities, you must pass in the full path from the root like would do on an `expand`
161
+
162
+ svc.Products.order_by("Name")
163
+ products = svc.execute
164
+
165
+ # Specifically requesting descending
166
+ svc.Products.order_by("Name desc")
167
+ products = svc.execute
168
+
169
+ # Specifically requesting ascending
170
+ svc.Products.order_by("Name asc")
171
+ products = svc.execute
172
+
173
+ Like the fiter method, order_by statements can also be chained like so:
174
+
175
+ svc.Products.order_by("Name asc").order_by("Price desc")
176
+
177
+
178
+ ### Skip
179
+ Skip allows you to skip a number of records when querying. This is often used for paging along with `top`.
180
+
181
+ svc.Products.skip(5)
182
+ products = svc.execute # => skips the first 5 items
183
+
184
+ ### Top
185
+ Top allows you only retrieve the top X number of records when querying. This is often used for paging along with `skip`.
186
+
187
+ svc.Products.top(5)
188
+ products = svc.execute # => returns only the first 5 items
189
+
190
+ ### Navigation Property Links Only Query
191
+ OData allows you to [query navigation properties and only return the links for the entities](http://www.odata.org/developers/protocols/uri-conventions#AddressingLinksBetweenEntries) (instead of the data).
192
+ **Note**: You cannot use the `links` method and the `count` method in the same query
193
+
194
+ svc.Categories(1).links("Products")
195
+ product_links = svc.execute # => returns URIs for the products under the Category with an ID of 1
196
+
197
+ ### Advanced Navigation Property Functions
198
+ There are instances where you may need to navigate down a level in order to form the proper query.
199
+ Take for example [Netflix's OData Service](http://developer.netflix.com/docs/oData_Catalog/) and their `Genres` Entity Collection, where you can access a Navigation Property (in this case `Titles` through the `Genre` and filter on it:
200
+
201
+ http://odata.netflix.com/Catalog/Genres('Horror%20Movies')/Titles?$filter=Name%20eq'Halloween'
202
+
203
+ In order to do this within ruby_odata, you can use the `navigate` method of the `QueryBuilder` to drill-down into the Navigation Property. This will allow you to perform `filter`s, `skip`s, `orderby`s, etc. against the children.
204
+
205
+ svc = OData::Service.new("http://odata.netflix.com/Catalog")
206
+ svc.Genres("'Horror Movies'").navigate("Titles").filter("Name eq 'Halloween'")
207
+ movies = svc.execute
208
+ movies.each { |m| puts m.Name }
209
+
210
+ ### Count
211
+ Sometimes all you want to do is count records, for that, you can use the `count` method.
212
+ This method can be combined with other options, such as `filter` but cannot be combined with the `links` method.
213
+
214
+ svc.Products.count
215
+ puts svc.execute # => 2
216
+
217
+ ### Partial feeds
218
+ OData allows services to do server-side paging in Atom by defining a next link. The default behavior is to repeatedly consume partial feeds until the result set is complete.
219
+
220
+ svc.Partials
221
+ results = svc.execute # => retrieves all results in the Partials collection
222
+
223
+ If desired (e.g., because the result set is too large to fit in memory), explicit traversal of partial results can be requested via options:
224
+
225
+ svc = OData::Service.new "http://example.com/Example.svc", { :eager_partial => false }
226
+ svc.Partials
227
+ results = svc.execute # => retrieves the first set of results returned by the server
228
+ if svc.partial? # => true if the last result set was a partial result set (i.e., had a next link)
229
+ results.concat svc.next # => retrieves the next set of results
230
+ end
231
+ while svc.partial? # => to retrieve all partial result sets
232
+ results.concat svc.next
233
+ end
234
+
235
+ ### Authentication
236
+ Basic HTTP Authentication is supported via sending a username and password as service constructor arguments:
237
+
238
+ require 'ruby_odata'
239
+
240
+ svc = OData::Service.new "http://127.0.0.1:8989/SampleService/RubyOData.svc", { :username => "bob", :password=> "12345" }
241
+
242
+ ### SSL/https Certificate Verification
243
+ The certificate verification mode can be passed in the options hash via the :verify_ssl key. For example, to ignore verification in order to use a self-signed certificate:
244
+
245
+ require 'ruby_odata'
246
+
247
+ svc = OData::Service.new "https://127.0.0.1:44300/SampleService/RubyOData.svc", { :verify_ssl => false }
248
+
249
+ Or an OpenSSL integer constant can be passed as well:
250
+
251
+ require 'ruby_odata'
252
+
253
+ svc = OData::Service.new "https://127.0.0.1:44300/SampleService/RubyOData.svc", { :verify_ssl => OpenSSL::SSL::VERIFY_PEER }
254
+
255
+ Default verification is OpenSSL::SSL::VERIFY_PEER. Note due to the way Ruby's Request object implements certificate checking, you CAN NOT pass OpenSSL::SSL::VERIFY_NONE, you must instead pass a boolean false.
256
+
257
+ ## Function Imports / Custom Service Methods
258
+ Function Imports are custom service methods exposed by the WCF Data Service. Each function import will be created as a method on the ruby_odata Service. When you make a call to one of these, they return a result immediately without the need to call `execute` or `save_changes`.
259
+
260
+ ## Reflection
261
+ Instead of relying on looking at the EDMX directly, ruby_odata allows you to perform basic reflection on objects
262
+ ### Service Level Methods
263
+ * **Collections** - You can look at the collections exposed by a service by accessing the `collections` method, which is a hash. The key is the name of the collection and the value is the hash with `edmx_type`, which returns the name of the type from the EDMX and `:type`, which is the local type that is created for you
264
+ * **Classes** - To see the generated classes, you can utilize the `classes` method on the service. The return result is a hash where the key is the class name and the value is the class type.
265
+ * **Function Imports** - You can find any function import (custom service methods) exposed by the service by accessing the `function_imports` method. This is a hash where the key is the Function Import name and the value is metadata about the Function Import.
266
+
267
+ ### Class Level Methods
268
+ * **Properties** - You can call the class method `properties` on a generated class to see the method (properties) that were created. The returned result is a hash where the key is the property name and the value is metadata for the property like if it is nullable, the EDM Type, etc.
269
+
270
+ ## Tests
271
+ All of the tests are written using Cucumber going against a sample service (Found in test/RubyODataService/RubyODataService/*).
272
+ The SampleService is an ASP.NET Web Site running a SQL Compact 4 Database, which gets generated at runtime, as well as the ADO.NET Entity Framework 4.1 and WCF Data Services October 2011 CTP. The reason for the CTP is that WCF Data Services currently shipping with .NET 4 doesn't support Entity Framework 4.1's "Code First" approach (e.g. no EDMX, all POCOs)
273
+ In order to run the tests, you need to spin up IIS running a virtual directory of SampleService on port 8989 (http://localhost:8989/SampleService) and another instance running on port 44300.
274
+
275
+ **NOTE** The ports (8989 and 44300) and webserver (localhost by default) here are customizable thanks to `/features/contants.rb`. Take a look in there for the corresponding environment variables that you can set.
276
+
277
+ The SampleService requires IIS or IIS Express. IIS Express is a free download from Microsoft and the preferred approach to running the application. Once installed, there is a batch file found in /test called "iisExpress x64.bat" that will spin up the appropriate instances needed for the Cucumber tests. There is a also an "iisExpress x86.bat" file for those of you running a 32-bit machine. The only difference is the path to the Program Files directory. Once you run the batch file, the web server will spin up. To stop the server, use 'Q' and then enter or close the command window.
278
+
279
+ If you are testing on a Windows machine, you may encounter a problem with using Cucumber and Ruby 1.9.2. You will get a message when you fire up cucumber about missing msvcrt-ruby18.dll. The fix for this is to make sure you have the [RubyInstaller DevKit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit) installed, then do the following:
280
+
281
+ gem uninstall json
282
+ gem install json --platform=ruby -v 1.4.6
283
+
284
+ Once the SampleService is running, from the BASE ruby_odata directory, simply type `rake`, which will run the RSpec and Cucumber specs. You can also run them separately `rake spec` for RSpec and `rake features` for Cucumber.
285
+
data/Rakefile CHANGED
@@ -1,14 +1,7 @@
1
- require 'rake/rdoctask'
2
1
  require 'bundler'
3
2
  require 'rspec/core/rake_task'
4
3
  require 'cucumber/rake/task'
5
4
 
6
- Rake::RDocTask.new do |rd|
7
- rd.main = "README.rdoc"
8
- rd.rdoc_files.include("README.rdoc", "CHANGELOG.rdoc", "lib/**/*.rb")
9
- rd.rdoc_dir = 'doc'
10
- end
11
-
12
5
  desc "Run specs"
13
6
  RSpec::Core::RakeTask.new do |t|
14
7
  t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
@@ -1,5 +1,6 @@
1
+ @basic_auth
1
2
  Feature: Service Should Access Basic Auth Protected Resources
2
-
3
+
3
4
  Background:
4
5
  Given a HTTP BasicAuth ODataService exists using username "admin" and password "passwd"
5
6
  And blueprints exist for the service
@@ -11,7 +12,7 @@ Scenario: Entity should fill values on protected resource
11
12
  Given I call "AddToCategories" on the service with a new "Category" object with Name: "Auth Test Category"
12
13
  And I save changes
13
14
  And I call "Categories" on the service with args: "1"
14
- When I run the query
15
+ When I run the query within a cassette named "basic_auth_protected_resource"
15
16
  Then the method "Id" on the first result should equal: "1"
16
17
  And the method "Name" on the first result should equal: "Auth Test Category"
17
18
 
@@ -1,8 +1,9 @@
1
+ @batch_request
1
2
  Feature: Batch request
2
3
  In order to minimize network traffic
3
4
  As a user of the library
4
5
  I want to be able to batch changes (Add/Update/Delete) and persist the batch instead of one at a time
5
-
6
+
6
7
  Background:
7
8
  Given a HTTP ODataService exists
8
9
  And blueprints exist for the service
@@ -14,7 +15,7 @@ Scenario: Save Changes should allow for batch additions
14
15
  Then the save result should equal: "true"
15
16
  When I call "Products" on the service
16
17
  And I order by: "Name"
17
- And I run the query
18
+ And I run the query within a cassette named "batch_request_additions"
18
19
  Then the result should be:
19
20
  | Name |
20
21
  | Product 1 |
@@ -31,13 +32,13 @@ Scenario: Save Changes should allow for batch updates
31
32
  And I call "update_object" on the service with the first last query result
32
33
  When I call "Products" on the service
33
34
  And I filter the query with: "Name eq 'Product 2'"
34
- And I run the query
35
+ And I run the query
35
36
  And I set "Name" on the first result to "Product 2 - Updated"
36
37
  And I call "update_object" on the service with the first last query result
37
38
  When I save changes
38
39
  When I call "Products" on the service
39
40
  And I order by: "Name"
40
- And I run the query
41
+ And I run the query within a cassette named "batch_request_updates"
41
42
  Then the result should be:
42
43
  | Name |
43
44
  | Product 1 - Updated |
@@ -55,12 +56,12 @@ Scenario: Save Changes should allow for batch deletes
55
56
  And I call "delete_object" on the service with the first last query result
56
57
  When I call "Products" on the service
57
58
  And I filter the query with: "Name eq 'Product 3'"
58
- And I run the query
59
+ And I run the query
59
60
  And I call "delete_object" on the service with the first last query result
60
61
  When I save changes
61
62
  When I call "Products" on the service
62
63
  And I order by: "Name"
63
- And I run the query
64
+ And I run the query within a cassette named "batch_request_deletes"
64
65
  Then the result should be:
65
66
  | Name |
66
67
  | Product 1 |
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://admin:passwd@win7dev:8989/SampleService/BasicAuth/RubyOData.svc/Categories(1)
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Cache-Control:
22
+ - no-cache
23
+ Content-Length:
24
+ - '1270'
25
+ Content-Type:
26
+ - application/atom+xml;type=entry;charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/7.5
29
+ Set-Cookie:
30
+ - ASP.NET_SessionId=zpifmralioi4qiwd0lg0uqcq; path=/; HttpOnly
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ Dataserviceversion:
34
+ - 1.0;
35
+ X-Aspnet-Version:
36
+ - 4.0.30319
37
+ X-Powered-By:
38
+ - ASP.NET
39
+ Date:
40
+ - Sat, 11 Aug 2012 21:36:29 GMT
41
+ body:
42
+ encoding: US-ASCII
43
+ string: <?xml version="1.0" encoding="utf-8"?><entry xml:base="http://win7dev:8989/SampleService/BasicAuth/RubyOData.svc/"
44
+ xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
45
+ xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss"
46
+ xmlns:gml="http://www.opengis.net/gml"><id>http://win7dev:8989/SampleService/BasicAuth/RubyOData.svc/Categories(1)</id><category
47
+ term="RubyODataService.Category" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
48
+ /><link rel="edit" title="Category" href="Categories(1)" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products"
49
+ type="application/atom+xml;type=feed" title="Products" href="Categories(1)/Products"
50
+ /><title /><updated>2012-08-11T21:36:30Z</updated><author><name /></author><content
51
+ type="application/xml"><m:properties><d:Id m:type="Edm.Int32">1</d:Id><d:Name>Auth
52
+ Test Category</d:Name><d:AuditFields m:type="RubyODataService.AuditFields"><d:CreateDate
53
+ m:type="Edm.DateTime">2012-08-11T21:36:30.453</d:CreateDate><d:ModifiedDate
54
+ m:type="Edm.DateTime">2012-08-11T21:36:30.453</d:ModifiedDate><d:CreatedBy>Machinist</d:CreatedBy></d:AuditFields></m:properties></content></entry>
55
+ http_version: !!null
56
+ recorded_at: Sat, 11 Aug 2012 21:36:30 GMT
57
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,69 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://win7dev:8989/SampleService/RubyOData.svc/Products?$orderby=Name
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Cache-Control:
22
+ - no-cache
23
+ Content-Length:
24
+ - '2706'
25
+ Content-Type:
26
+ - application/atom+xml;type=feed;charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/7.5
29
+ Set-Cookie:
30
+ - ASP.NET_SessionId=f4m0q12lgd4twvpgowaich4j; path=/; HttpOnly
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ Dataserviceversion:
34
+ - 1.0;
35
+ X-Aspnet-Version:
36
+ - 4.0.30319
37
+ X-Powered-By:
38
+ - ASP.NET
39
+ Date:
40
+ - Tue, 07 Aug 2012 21:43:14 GMT
41
+ body:
42
+ encoding: US-ASCII
43
+ string: <?xml version="1.0" encoding="utf-8"?><feed xml:base="http://win7dev:8989/SampleService/RubyOData.svc/"
44
+ xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
45
+ xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss"
46
+ xmlns:gml="http://www.opengis.net/gml"><id>http://win7dev:8989/SampleService/RubyOData.svc/Products</id><title
47
+ type="text">Products</title><updated>2012-08-07T21:43:15Z</updated><link rel="self"
48
+ title="Products" href="Products" /><entry><id>http://win7dev:8989/SampleService/RubyOData.svc/Products(1)</id><category
49
+ term="RubyODataService.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
50
+ /><link rel="edit" title="Product" href="Products(1)" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Category"
51
+ type="application/atom+xml;type=entry" title="Category" href="Products(1)/Category"
52
+ /><title /><updated>2012-08-07T21:43:15Z</updated><author><name /></author><content
53
+ type="application/xml"><m:properties><d:Id m:type="Edm.Int32">1</d:Id><d:Name>Product
54
+ 1</d:Name><d:Description>Test Widget</d:Description><d:Price m:type="Edm.Decimal">50.00</d:Price><d:DiscontinuedDate
55
+ m:type="Edm.DateTime" m:null="true" /><d:CategoryId m:type="Edm.Int32">1</d:CategoryId><d:AuditFields
56
+ m:type="RubyODataService.AuditFields"><d:CreateDate m:type="Edm.DateTime">2012-08-07T21:43:14.983</d:CreateDate><d:ModifiedDate
57
+ m:type="Edm.DateTime">2012-08-07T21:43:14.983</d:ModifiedDate><d:CreatedBy>Machinist</d:CreatedBy></d:AuditFields></m:properties></content></entry><entry><id>http://win7dev:8989/SampleService/RubyOData.svc/Products(2)</id><category
58
+ term="RubyODataService.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
59
+ /><link rel="edit" title="Product" href="Products(2)" /><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Category"
60
+ type="application/atom+xml;type=entry" title="Category" href="Products(2)/Category"
61
+ /><title /><updated>2012-08-07T21:43:15Z</updated><author><name /></author><content
62
+ type="application/xml"><m:properties><d:Id m:type="Edm.Int32">2</d:Id><d:Name>Product
63
+ 2</d:Name><d:Description>Test Widget</d:Description><d:Price m:type="Edm.Decimal">25.00</d:Price><d:DiscontinuedDate
64
+ m:type="Edm.DateTime" m:null="true" /><d:CategoryId m:type="Edm.Int32">2</d:CategoryId><d:AuditFields
65
+ m:type="RubyODataService.AuditFields"><d:CreateDate m:type="Edm.DateTime">2012-08-07T21:43:14.983</d:CreateDate><d:ModifiedDate
66
+ m:type="Edm.DateTime">2012-08-07T21:43:14.983</d:ModifiedDate><d:CreatedBy>Machinist</d:CreatedBy></d:AuditFields></m:properties></content></entry></feed>
67
+ http_version: !!null
68
+ recorded_at: Tue, 07 Aug 2012 21:43:14 GMT
69
+ recorded_with: VCR 2.2.4