ruby_odata 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -1
- data/CHANGELOG.rdoc +46 -38
- data/Gemfile +4 -0
- data/LICENSE +24 -24
- data/README.rdoc +179 -153
- data/Rakefile +10 -28
- data/features/basic_auth.feature +24 -0
- data/features/batch_request.feature +94 -94
- data/features/complex_types.feature +52 -52
- data/features/query_builder.feature +153 -153
- data/features/service.feature +49 -49
- data/features/service_manage.feature +54 -44
- data/features/step_definitions/service_steps.rb +255 -243
- data/features/support/env.rb +14 -4
- data/features/support/hooks.rb +3 -3
- data/features/type_conversion.feature +53 -45
- data/lib/ruby_odata.rb +17 -17
- data/lib/ruby_odata/class_builder.rb +117 -109
- data/lib/ruby_odata/operation.rb +17 -17
- data/lib/ruby_odata/query_builder.rb +106 -106
- data/lib/ruby_odata/service.rb +359 -339
- data/lib/ruby_odata/version.rb +3 -0
- data/ruby_odata.gemspec +24 -78
- data/test/SampleService/App_Code/Entities.cs +105 -2
- data/test/SampleService/App_Code/Model.Designer.cs +24 -0
- data/test/SampleService/App_Code/Model.edmx +3 -0
- data/test/SampleService/App_Data/_TestDB.mdf +0 -0
- data/test/SampleService/App_Data/_TestDB_Log.ldf +0 -0
- data/test/SampleService/BasicAuth/Entities.svc +1 -0
- data/test/SampleService/web.config +11 -1
- data/test/blueprints.rb +20 -20
- data/test/iisExpress x64.bat +1 -0
- data/test/iisExpress x86.bat +1 -0
- metadata +88 -14
- data/VERSION +0 -1
data/features/service.feature
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
Feature: Service Should Generate a Proxy
|
2
|
-
In order to consume the OData
|
3
|
-
As a user
|
4
|
-
I want to be able to access data
|
5
|
-
|
6
|
-
Background:
|
7
|
-
Given an ODataService exists with uri: "http://localhost:8888/SampleService/Entities.svc"
|
8
|
-
And blueprints exist for the service
|
9
|
-
|
10
|
-
Scenario: Service should respond to valid collections
|
11
|
-
Then I should be able to call "Categories" on the service
|
12
|
-
|
13
|
-
Scenario: Service should not respond to an invalid collection
|
14
|
-
Then I should not be able to call "X" on the service
|
15
|
-
|
16
|
-
Scenario: Service should respond to accessing a single entity by ID
|
17
|
-
Then I should be able to call "Categories" on the service with args: "1"
|
18
|
-
|
19
|
-
Scenario: Access an entity by ID should return the entity type
|
20
|
-
Given I call "AddToCategories" on the service with a new "Category" object with Name: "Test Category"
|
21
|
-
And I save changes
|
22
|
-
And I call "Categories" on the service with args: "1"
|
23
|
-
When I run the query
|
24
|
-
Then the result should be of type "Category"
|
25
|
-
|
26
|
-
Scenario: Entity should have the correct accessors
|
27
|
-
Given I call "AddToCategories" on the service with a new "Category" object with Name: "Test Category"
|
28
|
-
And I save changes
|
29
|
-
And I call "Categories" on the service with args: "1"
|
30
|
-
When I run the query
|
31
|
-
Then the result should have a method: "Id"
|
32
|
-
And the result should have a method: "Name"
|
33
|
-
|
34
|
-
Scenario: Entity should fill values
|
35
|
-
Given I call "AddToCategories" on the service with a new "Category" object with Name: "Test Category"
|
36
|
-
And I save changes
|
37
|
-
And I call "Categories" on the service with args: "1"
|
38
|
-
When I run the query
|
39
|
-
Then the method "Id" on the result should equal: "1"
|
40
|
-
And the method "Name" on the result should equal: "Test Category"
|
41
|
-
|
42
|
-
Scenario: Navigation Properties should be included in results
|
43
|
-
Given I call "AddToProducts" on the service with a new "Product" object
|
44
|
-
And I save changes
|
45
|
-
And I call "Products" on the service with args: "1"
|
46
|
-
When I run the query
|
47
|
-
Then the result should have a method: "Category"
|
48
|
-
And the method "Category" on the result should be nil
|
49
|
-
|
1
|
+
Feature: Service Should Generate a Proxy
|
2
|
+
In order to consume the OData
|
3
|
+
As a user
|
4
|
+
I want to be able to access data
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given an ODataService exists with uri: "http://localhost:8888/SampleService/Entities.svc"
|
8
|
+
And blueprints exist for the service
|
9
|
+
|
10
|
+
Scenario: Service should respond to valid collections
|
11
|
+
Then I should be able to call "Categories" on the service
|
12
|
+
|
13
|
+
Scenario: Service should not respond to an invalid collection
|
14
|
+
Then I should not be able to call "X" on the service
|
15
|
+
|
16
|
+
Scenario: Service should respond to accessing a single entity by ID
|
17
|
+
Then I should be able to call "Categories" on the service with args: "1"
|
18
|
+
|
19
|
+
Scenario: Access an entity by ID should return the entity type
|
20
|
+
Given I call "AddToCategories" on the service with a new "Category" object with Name: "Test Category"
|
21
|
+
And I save changes
|
22
|
+
And I call "Categories" on the service with args: "1"
|
23
|
+
When I run the query
|
24
|
+
Then the result should be of type "Category"
|
25
|
+
|
26
|
+
Scenario: Entity should have the correct accessors
|
27
|
+
Given I call "AddToCategories" on the service with a new "Category" object with Name: "Test Category"
|
28
|
+
And I save changes
|
29
|
+
And I call "Categories" on the service with args: "1"
|
30
|
+
When I run the query
|
31
|
+
Then the result should have a method: "Id"
|
32
|
+
And the result should have a method: "Name"
|
33
|
+
|
34
|
+
Scenario: Entity should fill values
|
35
|
+
Given I call "AddToCategories" on the service with a new "Category" object with Name: "Test Category"
|
36
|
+
And I save changes
|
37
|
+
And I call "Categories" on the service with args: "1"
|
38
|
+
When I run the query
|
39
|
+
Then the method "Id" on the result should equal: "1"
|
40
|
+
And the method "Name" on the result should equal: "Test Category"
|
41
|
+
|
42
|
+
Scenario: Navigation Properties should be included in results
|
43
|
+
Given I call "AddToProducts" on the service with a new "Product" object
|
44
|
+
And I save changes
|
45
|
+
And I call "Products" on the service with args: "1"
|
46
|
+
When I run the query
|
47
|
+
Then the result should have a method: "Category"
|
48
|
+
And the method "Category" on the result should be nil
|
49
|
+
|
@@ -1,44 +1,54 @@
|
|
1
|
-
Feature: Service management
|
2
|
-
In order to manage entities
|
3
|
-
As a admin
|
4
|
-
I want to be able to add, edit, and delete entities
|
5
|
-
|
6
|
-
Background:
|
7
|
-
Given an ODataService exists with uri: "http://localhost:8888/SampleService/Entities.svc"
|
8
|
-
|
9
|
-
|
10
|
-
Scenario: Service should respond to AddToEntityName for adding objects
|
11
|
-
Given I call "AddToProducts" on the service with a new "Product" object with Name: "Sample Product"
|
12
|
-
When I save changes
|
13
|
-
Then the save result should be of type "Product"
|
14
|
-
|
15
|
-
|
16
|
-
Scenario: Service should allow for deletes
|
17
|
-
Given I call "AddToProducts" on the service with a new "Product" object
|
18
|
-
When I save changes
|
19
|
-
Then the save result should be of type "Product"
|
20
|
-
When I call "delete_object" on the service with the last save result
|
21
|
-
And I save changes
|
22
|
-
Then the save result should equal: "true"
|
23
|
-
And no "Products" should exist
|
24
|
-
|
25
|
-
Scenario: Untracked entities shouldn't be able to be deleted
|
26
|
-
|
27
|
-
|
28
|
-
Scenario: Entities should be able to be updated
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
And I run the query
|
33
|
-
Then the method "Name" on the result should equal: "Test Product"
|
34
|
-
When I set "Name" on the result to "Changed Test Product"
|
35
|
-
Then the method "Name" on the result should equal: "Changed Test Product"
|
36
|
-
And I call "update_object" on the service with the last query result
|
37
|
-
And I save changes
|
38
|
-
Then the save result should equal: "true"
|
39
|
-
When I call "Products" on the service with args: "1"
|
40
|
-
And I run the query
|
41
|
-
Then the method "Name" on the result should equal: "Changed Test Product"
|
42
|
-
|
43
|
-
Scenario: Untracked entities shouldn't be able to be updated
|
44
|
-
|
1
|
+
Feature: Service management
|
2
|
+
In order to manage entities
|
3
|
+
As a admin
|
4
|
+
I want to be able to add, edit, and delete entities
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given an ODataService exists with uri: "http://localhost:8888/SampleService/Entities.svc"
|
8
|
+
And blueprints exist for the service
|
9
|
+
|
10
|
+
Scenario: Service should respond to AddToEntityName for adding objects
|
11
|
+
Given I call "AddToProducts" on the service with a new "Product" object with Name: "Sample Product"
|
12
|
+
When I save changes
|
13
|
+
Then the save result should be of type "Product"
|
14
|
+
And the method "Name" on the save result should equal: "Sample Product"
|
15
|
+
|
16
|
+
Scenario: Service should allow for deletes
|
17
|
+
Given I call "AddToProducts" on the service with a new "Product" object
|
18
|
+
When I save changes
|
19
|
+
Then the save result should be of type "Product"
|
20
|
+
When I call "delete_object" on the service with the last save result
|
21
|
+
And I save changes
|
22
|
+
Then the save result should equal: "true"
|
23
|
+
And no "Products" should exist
|
24
|
+
|
25
|
+
Scenario: Untracked entities shouldn't be able to be deleted
|
26
|
+
Given I call "delete_object" on the service with a new "Product" object it should throw an exception with message "You cannot delete a non-tracked entity"
|
27
|
+
|
28
|
+
Scenario: Entities should be able to be updated
|
29
|
+
Given I call "AddToProducts" on the service with a new "Product" object with Name: "Test Product"
|
30
|
+
When I save changes
|
31
|
+
And I call "Products" on the service with args: "1"
|
32
|
+
And I run the query
|
33
|
+
Then the method "Name" on the result should equal: "Test Product"
|
34
|
+
When I set "Name" on the result to "Changed Test Product"
|
35
|
+
Then the method "Name" on the result should equal: "Changed Test Product"
|
36
|
+
And I call "update_object" on the service with the last query result
|
37
|
+
And I save changes
|
38
|
+
Then the save result should equal: "true"
|
39
|
+
When I call "Products" on the service with args: "1"
|
40
|
+
And I run the query
|
41
|
+
Then the method "Name" on the result should equal: "Changed Test Product"
|
42
|
+
|
43
|
+
Scenario: Untracked entities shouldn't be able to be updated
|
44
|
+
Given I call "update_object" on the service with a new "Product" object it should throw an exception with message "You cannot update a non-tracked entity"
|
45
|
+
|
46
|
+
Scenario: Related entities shouldn't be recreated on a child add
|
47
|
+
Given I call "AddToCategories" on the service with a new "Category" object with Name: "Test Category"
|
48
|
+
And I save changes
|
49
|
+
And I call "AddToProducts" on the service with a new "Product" object with Category: "@@LastSave"
|
50
|
+
And I save changes
|
51
|
+
And I call "Products" on the service with args: "1"
|
52
|
+
And I expand the query to include "Category"
|
53
|
+
When I run the query
|
54
|
+
Then the method "Id" on the result's method "Category" should equal: "1"
|
@@ -1,244 +1,256 @@
|
|
1
|
-
Given /^an ODataService exists with uri: "([^\"]*)"$/ do |uri|
|
2
|
-
@service = OData::Service.new(uri)
|
3
|
-
end
|
4
|
-
|
5
|
-
|
6
|
-
@
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
|
-
@
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
lambda { @service.
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
Then /^
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
Then /^
|
34
|
-
@
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
@
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
@service_result
|
43
|
-
end
|
44
|
-
|
45
|
-
Then /^the
|
46
|
-
@service_result.
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
@service_result.
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
@
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
@
|
59
|
-
end
|
60
|
-
|
61
|
-
When /^I
|
62
|
-
@
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
@service_query.
|
67
|
-
end
|
68
|
-
|
69
|
-
When /^I
|
70
|
-
@service_query.
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
@service.send(method.to_sym,
|
109
|
-
end
|
110
|
-
|
111
|
-
When /^I
|
112
|
-
@service.
|
113
|
-
end
|
114
|
-
|
115
|
-
Then /^the save result should
|
116
|
-
@saved_result.to_s.should ==
|
117
|
-
end
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
Then /^the
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
1
|
+
Given /^an ODataService exists with uri: "([^\"]*)"$/ do |uri|
|
2
|
+
@service = OData::Service.new(uri)
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^an ODataService exists with uri: "([^\"]*)" using username "([^\"]*)" and password "([^\"]*)"$/ do |uri, username, password|
|
6
|
+
@service = OData::Service.new(uri, { :username => username, :password => password })
|
7
|
+
end
|
8
|
+
|
9
|
+
Given /^an ODataService exists with uri: "([^\"]*)" using username "([^\"]*)" and password "([^\"]*)" it should throw an exception with message "([^\"]*)"$/ do |uri, username, password, msg|
|
10
|
+
lambda { @service = OData::Service.new(uri, { :username => username, :password => password }) }.should raise_error(msg)
|
11
|
+
end
|
12
|
+
|
13
|
+
Given /^an ODataService exists with uri: "([^\"]*)" it should throw an exception with message "([^\"]*)"$/ do |uri, msg|
|
14
|
+
lambda { @service = OData::Service.new(uri) }.should raise_error(msg)
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^I call "([^\"]*)" on the service$/ do |method|
|
18
|
+
@service_query = @service.send(method)
|
19
|
+
end
|
20
|
+
|
21
|
+
Then /^the result should be "([^\"]*)"$/ do |result|
|
22
|
+
@service_result.should == result
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^I should be able to call "([^\"]*)" on the service$/ do |method|
|
26
|
+
lambda { @service.send(method) }.should_not raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
Then /^I should not be able to call "([^\"]*)" on the service$/ do |method|
|
30
|
+
lambda { @service.send(method) }.should raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
Then /^I should be able to call "([^\"]*)" on the service with args: "([^\"]*)"$/ do |method, args|
|
34
|
+
lambda { @service.send(method, args) }.should_not raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
When /^I call "([^\"]*)" on the service with args: "([^\"]*)"$/ do |method, args|
|
38
|
+
@service_query = @service.send(method, args)
|
39
|
+
end
|
40
|
+
|
41
|
+
When /^I run the query$/ do
|
42
|
+
@service_result = @service.execute
|
43
|
+
end
|
44
|
+
|
45
|
+
Then /^the result should be of type "([^\"]*)"$/ do |type|
|
46
|
+
@service_result.class.to_s.should == type
|
47
|
+
end
|
48
|
+
|
49
|
+
Then /^the result should have a method: "([^\"]*)"$/ do |method|
|
50
|
+
@service_result.respond_to?(method.to_sym).should == true
|
51
|
+
end
|
52
|
+
|
53
|
+
Then /^the method "([^\"]*)" on the result should equal: "([^\"]*)"$/ do |method, value|
|
54
|
+
@service_result.send(method.to_sym).to_s.should == value
|
55
|
+
end
|
56
|
+
|
57
|
+
Then /^the method "([^\"]*)" on the result should be nil$/ do |method|
|
58
|
+
@service_result.send(method.to_sym).should == nil
|
59
|
+
end
|
60
|
+
|
61
|
+
When /^I set "([^\"]*)" on the result to "([^\"]*)"$/ do |property_name, value|
|
62
|
+
@service_result.send("#{property_name}=", value)
|
63
|
+
end
|
64
|
+
|
65
|
+
Given /^I expand the query to include "([^\"]*)"$/ do |expands|
|
66
|
+
@service_query.expand(expands)
|
67
|
+
end
|
68
|
+
|
69
|
+
When /^I filter the query with: "([^\"]*)"$/ do |filter|
|
70
|
+
@service_query.filter(filter)
|
71
|
+
end
|
72
|
+
|
73
|
+
When /^I order by: "([^\"]*)"$/ do |order|
|
74
|
+
@service_query.order_by(order)
|
75
|
+
end
|
76
|
+
|
77
|
+
When /^I skip (\d+)$/ do |skip|
|
78
|
+
@service_query.skip(skip)
|
79
|
+
end
|
80
|
+
|
81
|
+
When /^I ask for the top (\d+)$/ do |top|
|
82
|
+
@service_query.top(top)
|
83
|
+
end
|
84
|
+
|
85
|
+
Then /^the method "([^\"]*)" on the result should be of type "([^\"]*)"$/ do |method, type|
|
86
|
+
result = @service_result.send(method.to_sym)
|
87
|
+
result.class.to_s.should == type
|
88
|
+
end
|
89
|
+
|
90
|
+
Given /^I call "([^\"]*)" on the service with a new "([^\"]*)" object(?: with (.*))?$/ do |method, object, fields|
|
91
|
+
fields_hash = {}
|
92
|
+
|
93
|
+
if !fields.nil?
|
94
|
+
fields.split(', ').each do |field|
|
95
|
+
if field =~ /^(?:(\w+): "(.*)")$/
|
96
|
+
key = $1
|
97
|
+
val = $2
|
98
|
+
if val =~ /^@@LastSave$/
|
99
|
+
val = @saved_result
|
100
|
+
end
|
101
|
+
|
102
|
+
fields_hash.merge!({ key => val })
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
obj = object.constantize.send(:make, fields_hash)
|
108
|
+
@service.send(method.to_sym, obj)
|
109
|
+
end
|
110
|
+
|
111
|
+
When /^I save changes$/ do
|
112
|
+
@saved_result = @service.save_changes
|
113
|
+
end
|
114
|
+
|
115
|
+
Then /^the save result should be of type "([^\"]*)"$/ do |type|
|
116
|
+
@saved_result.class.to_s.should == type
|
117
|
+
end
|
118
|
+
|
119
|
+
When /^I call "([^\"]*)" on the service with the last save result$/ do |method|
|
120
|
+
@service.send(method.to_sym, @saved_result)
|
121
|
+
end
|
122
|
+
|
123
|
+
When /^I call "([^\"]*)" on the service with the last query result$/ do |method|
|
124
|
+
@service.send(method.to_sym, @service_result)
|
125
|
+
end
|
126
|
+
|
127
|
+
Then /^the save result should equal: "([^\"]*)"$/ do |result|
|
128
|
+
@saved_result.to_s.should == result
|
129
|
+
end
|
130
|
+
|
131
|
+
Then /^the method "([^\"]*)" on the save result should equal: "([^\"]*)"$/ do |method, value|
|
132
|
+
result = @saved_result.send(method.to_sym)
|
133
|
+
result.should == value
|
134
|
+
end
|
135
|
+
|
136
|
+
When /^blueprints exist for the service$/ do
|
137
|
+
require File.expand_path(File.dirname(__FILE__) + "../../../test/blueprints")
|
138
|
+
end
|
139
|
+
|
140
|
+
Given /^I call "([^\"]*)" on the service with a new "([^\"]*)" object it should throw an exception with message "([^\"]*)"$/ do |method, object, msg|
|
141
|
+
obj = object.constantize.send :make
|
142
|
+
lambda { @service.send(method.to_sym, obj) }.should raise_error(msg)
|
143
|
+
end
|
144
|
+
|
145
|
+
Then /^no "([^\"]*)" should exist$/ do |collection|
|
146
|
+
@service.send(collection)
|
147
|
+
results = @service.execute
|
148
|
+
results.should == []
|
149
|
+
end
|
150
|
+
|
151
|
+
Given /^the following (.*) exist:$/ do |plural_factory, table|
|
152
|
+
# table is a Cucumber::Ast::Table
|
153
|
+
factory = plural_factory.singularize
|
154
|
+
table.hashes.map do |hash|
|
155
|
+
obj = factory.constantize.send(:make, hash)
|
156
|
+
@service.send("AddTo#{plural_factory}", obj)
|
157
|
+
@service.save_changes
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
Given /^(\d+) (.*) exist$/ do |num, plural_factory|
|
162
|
+
factory = plural_factory.singularize
|
163
|
+
num.to_i.times do
|
164
|
+
obj = factory.constantize.send(:make)
|
165
|
+
@service.send("AddTo#{plural_factory}", obj)
|
166
|
+
end
|
167
|
+
@service.save_changes # Batch save
|
168
|
+
end
|
169
|
+
|
170
|
+
Then /^the result should be:$/ do |table|
|
171
|
+
# table is a Cucumber::Ast::Table
|
172
|
+
|
173
|
+
fields = table.hashes[0].keys
|
174
|
+
|
175
|
+
# Build an array of hashes so that we can compare tables
|
176
|
+
results = []
|
177
|
+
|
178
|
+
@service_result.each do |result|
|
179
|
+
obj_hash = Hash.new
|
180
|
+
fields.each do |field|
|
181
|
+
obj_hash[field] = result.send(field)
|
182
|
+
end
|
183
|
+
results << obj_hash
|
184
|
+
end
|
185
|
+
|
186
|
+
result_table = Cucumber::Ast::Table.new(results)
|
187
|
+
|
188
|
+
table.diff!(result_table)
|
189
|
+
end
|
190
|
+
|
191
|
+
Then /^the save result should be:$/ do |table|
|
192
|
+
# table is a Cucumber::Ast::Table
|
193
|
+
|
194
|
+
fields = table.hashes[0].keys
|
195
|
+
|
196
|
+
# Build an array of hashes so that we can compare tables
|
197
|
+
results = []
|
198
|
+
|
199
|
+
@saved_result.each do |result|
|
200
|
+
obj_hash = Hash.new
|
201
|
+
fields.each do |field|
|
202
|
+
obj_hash[field] = result.send(field)
|
203
|
+
end
|
204
|
+
results << obj_hash
|
205
|
+
end
|
206
|
+
|
207
|
+
result_table = Cucumber::Ast::Table.new(results)
|
208
|
+
|
209
|
+
table.diff!(result_table)
|
210
|
+
end
|
211
|
+
|
212
|
+
Then /^a class named "([^\"]*)" should exist$/ do |klass_name|
|
213
|
+
(Object.const_defined? klass_name).should == true
|
214
|
+
end
|
215
|
+
|
216
|
+
# Operations against a method on the service result
|
217
|
+
When /^I call "([^\"]*)" for "([^\"]*)" on the result$/ do |method2, method1|
|
218
|
+
r1 = @service_result.send(method1)
|
219
|
+
@operation_result = r1.send(method2)
|
220
|
+
end
|
221
|
+
|
222
|
+
Then /^the operation should not be null$/ do
|
223
|
+
@operation_result.nil?.should == false
|
224
|
+
end
|
225
|
+
|
226
|
+
|
227
|
+
Then /^the method "([^\"]*)" on the result's method "([^\"]*)" should equal: "([^\"]*)"$/ do |method, result_method, value|
|
228
|
+
obj = @service_result.send(result_method.to_sym)
|
229
|
+
obj.send(method.to_sym).to_s.should == value
|
230
|
+
end
|
231
|
+
|
232
|
+
When /^I set "([^\"]*)" on the result's method "([^\"]*)" to "([^\"]*)"$/ do |property_name, result_method, value|
|
233
|
+
@service_result.send(result_method).send("#{property_name}=", value)
|
234
|
+
end
|
235
|
+
|
236
|
+
# Type tests
|
237
|
+
Then /^the "([^\"]*)" method should return a (.*)/ do |method_name, type|
|
238
|
+
methods = method_name.split '.'
|
239
|
+
if methods.length == 1
|
240
|
+
@service_result.send(method_name).class.to_s.should == type
|
241
|
+
else
|
242
|
+
@service_result.send(methods[0]).send(methods[1]).class.to_s.should == type
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
Then /^I store the last query result for comparison$/ do
|
247
|
+
@stored_query_result = @service_result
|
248
|
+
end
|
249
|
+
Then /^the new query result's time "([^\"]*)" should equal the saved query result$/ do |method_name|
|
250
|
+
methods = method_name.split '.'
|
251
|
+
if methods.length == 1
|
252
|
+
@service_result.send(method_name).xmlschema(3).should == @stored_query_result.send(method_name).xmlschema(3)
|
253
|
+
else
|
254
|
+
@service_result.send(methods[0]).send(methods[1]).xmlschema(3).should == @stored_query_result.send(methods[0]).send(methods[1]).xmlschema(3)
|
255
|
+
end
|
244
256
|
end
|