Skip to content

Commit f24d6df

Browse files
committed
Update entries API to accept multiple errors
The lambda sends an array of validation errors when it finds errors. This updates the API to accept the validation errors in the format they are being sent in. Note that the strong params gets complicated here because we are having to accept an array of hashes, and Rails assumes that this will be for a nested model. This isn't viable longer term where we may need to set different keys on the validation errors. At that point it will probably make sense to whitelist the validation error params separately to strong params and assign them directly.
1 parent 4344e83 commit f24d6df

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

app/controllers/v1/submission_entries_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def initialize_submission_entry
5252
end
5353

5454
def submission_entry_params
55-
params.require(:submission_entry).permit(:status, source: {}, data: {}, validation_errors: {})
55+
params
56+
.require(:submission_entry)
57+
.permit(:status, :type, source: {}, data: {}, validation_errors: [:message, location: {}])
5658
end
5759
end

spec/requests/v1/files_spec.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,12 @@
131131
data: {
132132
type: 'submission_entries',
133133
attributes: {
134-
validation_errors: {
135-
location: {
136-
row: 20,
137-
column: 2
138-
},
139-
message: 'Required value error'
140-
}
134+
validation_errors: [
135+
{
136+
location: { row: 20, column: 2 },
137+
message: 'Required value error'
138+
}
139+
]
141140
}
142141
}
143142
}
@@ -153,7 +152,8 @@
153152

154153
expect(response).to have_http_status(:no_content)
155154
expect(entry.reload).to be_pending
156-
expect(entry.reload.validation_errors['message']).to eql 'Required value error'
155+
expect(entry.validation_errors[0]['message']).to eq 'Required value error'
156+
expect(entry.validation_errors[0]['location']).to eq('row' => 20, 'column' => 2)
157157
end
158158

159159
it 'updates both the given entry\'s status and the validation errors received from DAVE' do
@@ -167,13 +167,12 @@
167167
type: 'submission_entries',
168168
attributes: {
169169
status: 'errored',
170-
validation_errors: {
171-
location: {
172-
row: 20,
173-
column: 2
174-
},
175-
message: 'Required value error'
176-
}
170+
validation_errors: [
171+
{
172+
location: { row: 20, column: 2 },
173+
message: 'Required value error'
174+
}
175+
]
177176
}
178177
}
179178
}
@@ -189,7 +188,8 @@
189188

190189
expect(response).to have_http_status(:no_content)
191190
expect(entry.reload).to be_errored
192-
expect(entry.reload.validation_errors['message']).to eql 'Required value error'
191+
expect(entry.validation_errors[0]['message']).to eq 'Required value error'
192+
expect(entry.validation_errors[0]['location']).to eq('row' => 20, 'column' => 2)
193193
end
194194
end
195195

0 commit comments

Comments
 (0)