2016-11-15 15:50:27 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-11-16 12:28:38 -05:00
|
|
|
describe Gitlab::ChatCommands::IssueShow, service: true do
|
2016-11-15 15:50:27 -05:00
|
|
|
describe '#execute' do
|
2016-11-17 06:06:45 -05:00
|
|
|
let(:issue) { create(:issue) }
|
|
|
|
let(:project) { issue.project }
|
|
|
|
let(:user) { issue.author }
|
2016-11-16 12:28:38 -05:00
|
|
|
let(:regex_match) { described_class.match("issue show #{issue.iid}") }
|
2016-11-15 15:50:27 -05:00
|
|
|
|
2016-11-17 06:06:45 -05:00
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
|
2016-11-17 06:06:45 -05:00
|
|
|
subject do
|
|
|
|
described_class.new(project, user).execute(regex_match)
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
|
|
|
|
context 'the issue exists' do
|
|
|
|
it 'returns the issue' do
|
2016-11-17 09:30:04 -05:00
|
|
|
expect(subject.iid).to be issue.iid
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|
2016-11-21 16:27:10 -05:00
|
|
|
|
|
|
|
context 'when its reference is given' do
|
|
|
|
let(:regex_match) { described_class.match("issue show #{issue.to_reference}") }
|
|
|
|
|
|
|
|
it 'shows the issue' do
|
|
|
|
expect(subject.iid).to be issue.iid
|
|
|
|
end
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'the issue does not exist' do
|
2016-11-17 09:30:04 -05:00
|
|
|
let(:regex_match) { described_class.match("issue show 2343242") }
|
2016-11-15 15:50:27 -05:00
|
|
|
|
|
|
|
it "returns nil" do
|
2016-11-17 09:30:04 -05:00
|
|
|
expect(subject).to be_nil
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-17 06:06:45 -05:00
|
|
|
|
|
|
|
describe 'self.match' do
|
|
|
|
it 'matches the iid' do
|
|
|
|
match = described_class.match("issue show 123")
|
|
|
|
|
|
|
|
expect(match[:iid]).to eq("123")
|
|
|
|
end
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|