Skip to content

Commit 289b52d

Browse files
author
Lee Richmond
committed
Add validation errors helper
1 parent 9c0b996 commit 289b52d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/jsonapi_spec_helpers/helpers.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,24 @@ def json_ids(integers = false)
5454
ids
5555
end
5656

57+
def validation_errors
58+
@validation_errors ||= {}.tap do |errors|
59+
json['errors'].each do |e|
60+
errors[e['meta']['attribute'].to_sym] = e['meta']['message']
61+
end
62+
end
63+
end
64+
5765
def jsonapi_headers
5866
{
5967
'CONTENT_TYPE' => 'application/vnd.api+json'
6068
}
6169
end
6270

71+
def jsonapi_get(url, params: {})
72+
get url, params: params, headers: jsonapi_headers
73+
end
74+
6375
def jsonapi_post(url, payload)
6476
post url, params: payload.to_json, headers: jsonapi_headers
6577
end

0 commit comments

Comments
 (0)