Skip to content

Commit da207c4

Browse files
Add specs for validation_errors
Tests the current, desired behavior Also displays the current, unwanted behavior
1 parent 3292476 commit da207c4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

spec/helpers_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@
7070
}
7171
end
7272

73+
let(:errors_json) do
74+
{
75+
'errors' => [
76+
{
77+
'code' => 'unprocessable_entity',
78+
'status' => '422',
79+
'title' => 'Validation Error',
80+
'detail' => 'Patron must exist',
81+
'source' => {
82+
'pointer' => '/data/relationships/patron'
83+
},
84+
'meta' => {
85+
'attribute' => 'patron',
86+
'message' => 'must exist',
87+
'code' => 'blank'
88+
}
89+
}
90+
]
91+
}
92+
end
93+
7394
describe '#json_item' do
7495
let(:json) { show_json }
7596

@@ -166,4 +187,20 @@
166187
})
167188
end
168189
end
190+
191+
describe '#validation_errors' do
192+
let(:json) { errors_json }
193+
194+
it 'creates a hash of the errors' do
195+
expect(validation_errors).to eq({:patron => 'must exist'})
196+
end
197+
198+
describe 'when there are no errors' do
199+
let(:json) { show_json }
200+
it 'does not raise an error of its own' do
201+
expect{ validation_errors }.not_to raise_error
202+
end
203+
end
204+
end
205+
169206
end

0 commit comments

Comments
 (0)