Skip to content
代码片段 群组 项目
提交 0b175174 编辑于 作者: Vitali Tatarintev's avatar Vitali Tatarintev
浏览文件

Validate timeline event note on update

Return validation error when timeline event's note is blank
during update

Changelog: changed
上级 96d624d2
No related branches found
No related tags found
无相关合并请求
...@@ -34,7 +34,7 @@ def execute ...@@ -34,7 +34,7 @@ def execute
attr_reader :timeline_event, :incident, :user, :note, :occurred_at attr_reader :timeline_event, :incident, :user, :note, :occurred_at
def update_params def update_params
{ updated_by_user: user, note: note.presence, occurred_at: occurred_at.presence }.compact { updated_by_user: user, note: note, occurred_at: occurred_at }.compact
end end
def add_system_note(timeline_event) def add_system_note(timeline_event)
......
...@@ -57,17 +57,40 @@ ...@@ -57,17 +57,40 @@
end end
context 'when there is a validation error' do context 'when there is a validation error' do
let(:occurred_at) { 'invalid date' } context 'when note is blank' do
let(:note) { '' }
it 'does not update the timeline event' do it 'does not update the timeline event' do
expect { resolve }.not_to change { timeline_event.reload.updated_at } expect { resolve }.not_to change { timeline_event.reload.updated_at }
end
it 'responds with error' do
expect(resolve).to eq(timeline_event: nil, errors: ["Note can't be blank"])
end
end end
it 'responds with error' do context 'when occurred_at is blank' do
expect(resolve).to eq( let(:occurred_at) { '' }
timeline_event: nil,
errors: ["Occurred at can't be blank"] it 'does not update the timeline event' do
) expect { resolve }.not_to change { timeline_event.reload.updated_at }
end
it 'responds with error' do
expect(resolve).to eq(timeline_event: nil, errors: ["Occurred at can't be blank"])
end
end
context 'when occurred_at is invalid' do
let(:occurred_at) { 'invalid date' }
it 'does not update the timeline event' do
expect { resolve }.not_to change { timeline_event.reload.updated_at }
end
it 'responds with error' do
expect(resolve).to eq(timeline_event: nil, errors: ["Occurred at can't be blank"])
end
end end
end end
end end
......
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
expect(execute.message).to eq(message) expect(execute.message).to eq(message)
end end
it 'does not update the note' do
expect { execute }.not_to change { timeline_event.reload.note }
end
it_behaves_like 'does not track incident management event', :incident_management_timeline_event_edited it_behaves_like 'does not track incident management event', :incident_management_timeline_event_edited
end end
...@@ -94,16 +98,7 @@ ...@@ -94,16 +98,7 @@
context 'when note is blank' do context 'when note is blank' do
let(:params) { { note: '', occurred_at: occurred_at } } let(:params) { { note: '', occurred_at: occurred_at } }
it_behaves_like 'successful response' it_behaves_like 'error response', "Note can't be blank"
it_behaves_like 'passing the correct was_changed value', :occurred_at
it 'does not update the note' do
expect { execute }.not_to change { timeline_event.reload.note }
end
it 'updates occurred_at' do
expect { execute }.to change { timeline_event.occurred_at }.to(params[:occurred_at])
end
end end
context 'when occurred_at is nil' do context 'when occurred_at is nil' do
...@@ -121,6 +116,12 @@ ...@@ -121,6 +116,12 @@
end end
end end
context 'when occurred_at is blank' do
let(:params) { { note: 'Updated note', occurred_at: '' } }
it_behaves_like 'error response', "Occurred at can't be blank"
end
context 'when both occurred_at and note is nil' do context 'when both occurred_at and note is nil' do
let(:params) { {} } let(:params) { {} }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册