File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
lib/jsonapi_errorable/serializers Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -16,11 +16,18 @@ def errors
16
16
messages . map do |message |
17
17
meta = { attribute : attribute , message : message } . merge ( @relationship_message )
18
18
meta = { relationship : meta } if @relationship_message . present?
19
+
20
+ detail = "#{ attribute . capitalize } #{ message } "
21
+
22
+ if attribute . to_s . downcase == 'base'
23
+ detail = message
24
+ end
25
+
19
26
{
20
27
code : 'unprocessable_entity' ,
21
28
status : '422' ,
22
29
title : 'Validation Error' ,
23
- detail : " #{ attribute . capitalize } #{ message } " ,
30
+ detail : detail ,
24
31
source : { pointer : pointer_for ( object , attribute ) } ,
25
32
meta : meta
26
33
}
Original file line number Diff line number Diff line change 43
43
]
44
44
)
45
45
end
46
+
47
+ context 'when the error attribute is "base"' do
48
+ let ( :errors_hash ) { { base : [ "Model is invalid" ] } }
49
+
50
+ before do
51
+ allow ( object ) . to receive ( :respond_to? ) . with ( :base ) { true }
52
+ end
53
+
54
+ it 'should not render the attribute in the message detail' do
55
+ expect ( subject ) . to eq (
56
+ [
57
+ {
58
+ code : 'unprocessable_entity' ,
59
+ status : '422' ,
60
+ title : "Validation Error" ,
61
+ detail : "Model is invalid" ,
62
+ source : { pointer : '/data/attributes/base' } ,
63
+ meta : {
64
+ attribute : :base ,
65
+ message : "Model is invalid"
66
+ }
67
+ }
68
+ ]
69
+ )
70
+ end
71
+ end
46
72
end
47
73
48
74
context 'when the error is on a relationship' do
You can’t perform that action at this time.
0 commit comments