Commit a45fa017 authored by Ruben Davila's avatar Ruben Davila

Add more specs and handle errors related to time parsing.

parent fcd3625c
......@@ -254,7 +254,7 @@ module SlashCommands
current_user.can?(:"admin_#{issuable.to_ability_name}", project)
end
command :estimate do |raw_duration|
time_spent = ChronicDuration.parse(raw_duration, default_unit: 'hours')
time_spent = ChronicDuration.parse(raw_duration, default_unit: 'hours') rescue nil
if time_spent
@updates[:time_estimate] = time_spent
......@@ -268,7 +268,7 @@ module SlashCommands
end
command :spend do |raw_duration|
reduce_time = raw_duration.sub!(/\A-/, '')
time_spent = ChronicDuration.parse(raw_duration, default_unit: 'hours')
time_spent = ChronicDuration.parse(raw_duration, default_unit: 'hours') rescue nil
if time_spent
@updates[:spend_time] = reduce_time ? (time_spent * -1) : time_spent
......
......@@ -472,11 +472,31 @@ describe SlashCommands::InterpretService, services: true do
let(:issuable) { issue }
end
it_behaves_like 'empty command' do
let(:content) { '/estimate' }
let(:issuable) { issue }
end
it_behaves_like 'empty command' do
let(:content) { '/estimate abc' }
let(:issuable) { issue }
end
it_behaves_like 'spend command' do
let(:content) { '/spend 1h' }
let(:issuable) { issue }
end
it_behaves_like 'empty command' do
let(:content) { '/spend' }
let(:issuable) { issue }
end
it_behaves_like 'empty command' do
let(:content) { '/spend abc' }
let(:issuable) { issue }
end
context 'when current_user cannot :admin_issue' do
let(:visitor) { create(:user) }
let(:issue) { create(:issue, project: project, author: visitor) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment