vigia 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c5a64fc8e29c2baf38e81587d991a0e62dedf24
4
- data.tar.gz: dc220251eff74b8feaed637d4d2a4802936301d3
3
+ metadata.gz: 8722e96d1e6af556c120af443297ce37858d92d6
4
+ data.tar.gz: c018d6fd8b5a6f89f089bd0e06e950018be721e2
5
5
  SHA512:
6
- metadata.gz: 1161a4e2a69ac0e9973c264233df0bc5c5be9619145281e8462b61386cfaba1805684340e242caa3cddaf7bb4534e35dcb507353ddea81078f5407090fc45811
7
- data.tar.gz: aa904625ce42d4eb35c1c8d5c91c0ad3537661bff22c98b6a1121c1529bec72a7283309f3adbeb68d86bd58406ee7f0947d22d09fcbd5e60d543dde9401f0071
6
+ metadata.gz: 48a7844f8d51d4c0acfb9884586b79ab336b833d5914f78f7333acee0ca86fccf6167afe3212919f7563a264c86d67b441ba8f40073962298c14ab3c1f5b0d85
7
+ data.tar.gz: 562b1162f366fe61099cd0eb9530389374cf5cf9f76b5d9dc20ef1ae3d8aa4bd845ef5a8f8a1a1b8fd178d2f6a1cef06f7a0a9f05b27d7eb8b23c93e6c9dca1c
@@ -22,6 +22,14 @@ module Vigia
22
22
  end
23
23
  end
24
24
 
25
+ def with_payload?(method)
26
+ [ :post, :patch, :put, :delete ].include?(method.to_s.downcase.to_sym)
27
+ end
28
+
29
+ def required_payload?(method)
30
+ [ :post, :patch, :put ].include?(method.to_s.downcase.to_sym)
31
+ end
32
+
25
33
  class Structure
26
34
  class << self
27
35
  def generate(adapter, structure)
@@ -45,7 +45,7 @@ module Vigia
45
45
  method: -> { action.method },
46
46
  uri_template: -> { resource.uri_template },
47
47
  parameters: -> { adapter.parameters_for(resource, action) },
48
- payload: -> { adapter.payload_for(transactional_example, response) if adapter.with_payload?(action) }
48
+ payload: -> { adapter.payload_for(transactional_example, response) if adapter.with_payload?(action.method) }
49
49
  },
50
50
  expectations: {
51
51
  code: -> { response.name.to_i },
@@ -61,7 +61,7 @@ module Vigia
61
61
  method: -> { action.method },
62
62
  uri_template: -> { resource.uri_template },
63
63
  parameters: -> { adapter.required_parameters_for(resource, action) },
64
- payload: -> { adapter.payload_for(transactional_example, response) if adapter.with_payload?(action) }
64
+ payload: -> { adapter.payload_for(transactional_example, response) if adapter.with_payload?(action.method) }
65
65
  },
66
66
  expectations: {
67
67
  code: -> { response.name.to_i },
@@ -71,7 +71,7 @@ module Vigia
71
71
 
72
72
  def headers_for(action, transactional_example, response, include_payload = true)
73
73
  headers = headers_for_response(response)
74
- headers += headers_for_payload(transactional_example, response) if with_payload?(action) && include_payload
74
+ headers += headers_for_payload(transactional_example, response) if with_payload?(action.method) && include_payload
75
75
  compile_headers(headers)
76
76
  end
77
77
 
@@ -87,13 +87,16 @@ module Vigia
87
87
  end
88
88
  end
89
89
 
90
- def with_payload?(action)
91
- %w(POST PUT PATCH).include? action.method
92
- end
93
-
94
90
  def payload_for(transactional_example, response)
95
91
  payload = get_payload(transactional_example, response)
96
- payload.body
92
+
93
+ if required_payload?(transactional_example.action.method) && payload.nil?
94
+ raise "Unable to load payload for response #{ response.name }"
95
+ elsif payload.nil?
96
+ nil
97
+ else
98
+ payload.body
99
+ end
97
100
  end
98
101
 
99
102
  def inspector object
@@ -184,14 +187,16 @@ module Vigia
184
187
 
185
188
  def headers_for_payload(transactional_example, response)
186
189
  payload = get_payload(transactional_example, response)
190
+
191
+ return [] if payload.nil?
192
+
187
193
  [ *payload.headers.collection ].flatten
188
194
  end
189
195
 
190
196
  def get_payload(transactional_example, response)
191
197
  index = transactional_example.responses.index(response)
192
- transactional_example.requests.fetch(index)
193
- rescue => e
194
- raise "Unable to load payload for response #{ response.name }"
198
+
199
+ index.nil? ? nil : transactional_example.requests.at(index)
195
200
  end
196
201
  end
197
202
  end
@@ -76,11 +76,17 @@ module Vigia
76
76
  return unless with_payload?(method.name)
77
77
 
78
78
  payload = request_body_for(method, body)
79
- payload.example || payload.schema.value
80
- end
81
79
 
82
- def with_payload?(method_name)
83
- [ :post, :put, :patch ].include?(method_name.to_s.downcase.to_sym)
80
+ case
81
+ when required_payload?(method.name) && payload.nil?
82
+ raise(
83
+ "An example body cannot be found for method #{ method.name } #{ method.parent.resource_path }"
84
+ )
85
+ when payload.nil?
86
+ nil
87
+ else
88
+ payload.example || payload.schema.value
89
+ end
84
90
  end
85
91
 
86
92
  private
@@ -103,8 +109,8 @@ module Vigia
103
109
  end
104
110
 
105
111
  def request_body_for(method, response_body)
106
- body = response_body.name == '*/*' ? method.bodies.values.first : method.bodies[response_body.name]
107
- body ||raise("An example body cannot be found for method #{ method.name } #{ method.parent.resource_path }")
112
+ response_body.name == '*/*' ?
113
+ method.bodies.values.first : method.bodies[response_body.name]
108
114
  end
109
115
 
110
116
  def query_parameters(method)
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Vigia
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vigia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Tapiador
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-22 00:00:00.000000000 Z
12
+ date: 2016-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake