Skip to content

Commit cda530a

Browse files
committed
Merge pull request #172 from john-griffin/master
Ensure validation errors use correct formatter
2 parents aae8e20 + 944f724 commit cda530a

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/jsonapi/exceptions.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ class ValidationErrors < Error
284284
attr_accessor :messages
285285
def initialize(messages)
286286
@messages = messages
287+
@key_formatter = JSONAPI.configuration.key_formatter
288+
end
289+
290+
def format_key(key)
291+
@key_formatter.format(key)
287292
end
288293

289294
def errors
@@ -292,7 +297,7 @@ def errors
292297
element[1].map do |message|
293298
JSONAPI::Error.new(code: JSONAPI::VALIDATION_ERROR,
294299
status: :unprocessable_entity,
295-
title: "#{element[0]} - #{message}",
300+
title: "#{format_key(element[0])} - #{message}",
296301
detail: message,
297302
path: "/#{element[0]}")
298303
end

test/controllers/controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ def test_create_validations_missing_attribute
16841684
assert_equal 2, json_response['errors'].size
16851685
assert_equal JSONAPI::VALIDATION_ERROR, json_response['errors'][0]['code']
16861686
assert_equal JSONAPI::VALIDATION_ERROR, json_response['errors'][1]['code']
1687-
assert_match /date_joined - can't be blank/, response.body
1687+
assert_match /dateJoined - can't be blank/, response.body
16881688
assert_match /name - can't be blank/, response.body
16891689
end
16901690

0 commit comments

Comments
 (0)