Don't error out in system hook if user has `nil` datetime columns

Deleting a user would fail in the system hooks if the user had
`nil` column in `datetime` or `updated_at` fields.

Closes #43871
This commit is contained in:
Stan Hu 2018-03-05 13:37:37 -08:00
parent 8a0052c037
commit 2d1ceca077
3 changed files with 15 additions and 2 deletions

View File

@ -20,8 +20,8 @@ class SystemHooksService
def build_event_data(model, event)
data = {
event_name: build_event_name(model, event),
created_at: model.created_at.xmlschema,
updated_at: model.updated_at.xmlschema
created_at: model.created_at&.xmlschema,
updated_at: model.updated_at&.xmlschema
}
case model

View File

@ -0,0 +1,5 @@
---
title: Don't error out in system hook if user has `nil` datetime columns
merge_request:
author:
type: fixed

View File

@ -70,6 +70,14 @@ describe SystemHooksService do
expect(data[:project_visibility]).to eq('private')
end
it 'handles nil datetime columns' do
user.update_attributes(created_at: nil, updated_at: nil)
data = event_data(user, :destroy)
expect(data[:created_at]).to be(nil)
expect(data[:updated_at]).to be(nil)
end
context 'group_rename' do
it 'contains old and new path' do
allow(group).to receive(:path_was).and_return('old-path')