soaspec 0.0.65 → 0.0.66

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b74599fe5d32dc78abe0ad63f1454c5173ac188
4
- data.tar.gz: ab105cf905b37f63a6fc6a52c694e85d3577c621
3
+ metadata.gz: 8e85c415626794edcaa1b13f12026dc04e619359
4
+ data.tar.gz: 1bafaf7d28a044e41cfd284d94ee5210c19a3d98
5
5
  SHA512:
6
- metadata.gz: fe214897a46aef14ffc950badadcd818927d5e6e38d427d29a7e3ce4d9ae0916d24f4262c3457d2d812ea3b198c7d2365ee174d498d31a457c485d0f54085bac
7
- data.tar.gz: ec75d15728e9b97082d9039bf9ea14652671488652991b539c1d883f77061057acf9de25ef83b6cce0d8a7b944dd51c83937e7549bc73cb6c2b920e5ca4aa0be
6
+ metadata.gz: c4062eae6480b45730bd44a8f94a2f564ba9a95f33c2e82cc5cb35de5a6d496d61e5f4cb41854c805e167c7d14d0758bb4bb2099f219f3fe3b9e6255b00091cd
7
+ data.tar.gz: aa7e71f4c08aa808fc381eb1199ee5027b4ee56bd5b03a41cc5ecbd4cd7692763f17ff9f642cf2d5f73de016427293f7ec5271e6625d46fb69873c8a2c7a3fbb
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ Version 0.0.66
2
+ * Enhancements
3
+ * Added method to convert REST request keys to 'PascalCase' if 'pascal_keys' is set to true
4
+ * This also converts paths obtaining elements to 'PascalCase' if they're simple and have no starting '//' or '$..'
5
+
1
6
  Version 0.0.65
2
7
  * Enhancements
3
8
  * Added ability to set 'suburl' and 'method' in Exchange accessor. Will be used in FactoryBot later
@@ -35,8 +35,8 @@ end
35
35
  post '/test/name' do
36
36
  request_hash = JSON.parse(request.body.string)
37
37
  id = Soaspec::TestServer::PuppyService.new_id
38
- Soaspec::TestServer::PuppyService.data[id][:name] = request_hash['name']
39
- response_hash = { result: { status: 'success', data: Soaspec::TestServer::PuppyService.data[id] } }
38
+ Soaspec::TestServer::PuppyService.data[id][:Name] = request_hash['Name']
39
+ response_hash = { result: { Status: 'success', Data: Soaspec::TestServer::PuppyService.data[id] } }
40
40
  JSON.generate response_hash
41
41
  end
42
42
 
@@ -48,7 +48,7 @@ end
48
48
 
49
49
  patch '/test/name/:id' do |id|
50
50
  request_hash = JSON.parse(request.body.string)
51
- Soaspec::TestServer::PuppyService.data[id.to_i][:name] = request_hash['name']
52
- response_hash = { result: { status: 'updated', with: request_hash['name'] } }
51
+ Soaspec::TestServer::PuppyService.data[id.to_i][:Name] = request_hash['Name']
52
+ response_hash = { result: { Status: 'updated', With: request_hash['Name'] } }
53
53
  JSON.generate response_hash
54
54
  end
@@ -84,6 +84,13 @@ module Soaspec
84
84
  end
85
85
  end
86
86
 
87
+ # Convert each key from snake_case to PascalCase
88
+ def pascal_keys(set)
89
+ define_method('pascal_keys?') do
90
+ set
91
+ end
92
+ end
93
+
87
94
  end
88
95
 
89
96
  # Wraps around Savon client defining default values dependent on the soap request
@@ -138,6 +145,26 @@ module Soaspec
138
145
  @resource = RestClient::Resource.new(base_url_value, merged_options) # @resource[url_extension].get
139
146
  end
140
147
 
148
+ def convert_to_pascal_case(key)
149
+ key.split('_').map(&:capitalize).join
150
+ end
151
+
152
+ # @return Whether to convert each key in the request to PascalCase
153
+ # It will also auto convert simple XPath, JSONPath where '//' or '..' not specified
154
+ def pascal_keys?
155
+ false
156
+ end
157
+
158
+ # @return [Hash]
159
+ def hash_used_in_request(override_hash)
160
+ request = @default_hash.merge(override_hash)
161
+ if pascal_keys?
162
+ request.map { |k, v| [convert_to_pascal_case(k.to_s), v] }.to_h
163
+ else
164
+ request
165
+ end
166
+ end
167
+
141
168
  # Used in together with Exchange request that passes such override parameters
142
169
  # @param [Hash] override_parameters Params to characterize REST request
143
170
  # @param_value [params] Extra parameters (E.g. headers)
@@ -156,7 +183,7 @@ module Soaspec
156
183
  response = case test_values[:method]
157
184
  when :post, :patch, :put
158
185
  unless test_values[:payload]
159
- test_values[:payload] = JSON.generate(@default_hash.merge(test_values[:body])).to_s if test_values[:body]
186
+ test_values[:payload] = JSON.generate(hash_used_in_request(test_values[:body])).to_s if test_values[:body]
160
187
  end
161
188
  @resource_used.send(test_values[:method].to_s, test_values[:payload], test_values[:params])
162
189
  else
@@ -170,9 +197,9 @@ module Soaspec
170
197
  response
171
198
  end
172
199
 
173
- # @param [Hash] format Format of expected result. Ignored for this
200
+ # @param [Hash] _format Format of expected result. Ignored for this
174
201
  # @return [Object] Generic body to be displayed in error messages
175
- def response_body(response, format: :hash)
202
+ def response_body(response, _format: :hash)
176
203
  extract_hash response
177
204
  end
178
205
 
@@ -270,11 +297,17 @@ module Soaspec
270
297
  case Interpreter.response_type_for(response)
271
298
  when :xml
272
299
  path = "//*[@#{attribute}]" unless attribute.nil?
273
- path = '//' + path if path[0] != '/'
300
+ if path[0] != '/'
301
+ path = convert_to_pascal_case(path) if pascal_keys?
302
+ path = '//' + path
303
+ end
274
304
  xpath_value_for(response: response, xpath: path, attribute: attribute)
275
305
  when :json
276
306
  raise 'JSON does not support attributes' if attribute
277
- path = '$..' + path if path[0] != '$'
307
+ if path[0] != '$'
308
+ path = convert_to_pascal_case(path) if pascal_keys?
309
+ path = '$..' + path
310
+ end
278
311
  matching_values = JsonPath.on(response.body, path)
279
312
  raise NoElementAtPath, "Element in #{response.body} not found with path '#{path}'" if matching_values.empty?
280
313
  matching_values.first
@@ -8,7 +8,7 @@ module Soaspec
8
8
 
9
9
  def new_id
10
10
  @data[@current_id] = {}
11
- @data[@current_id][:id] = @current_id
11
+ @data[@current_id][:Id] = @current_id
12
12
  @current_id += 1
13
13
  @current_id - 1
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module Soaspec
2
- VERSION = '0.0.65'.freeze
2
+ VERSION = '0.0.66'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.65
4
+ version: 0.0.66
5
5
  platform: ruby
6
6
  authors:
7
7
  - SamuelGarrattIQA