gitlab-org--gitlab-foss/spec/lib/gitlab/slash_commands/issue_show_spec.rb

60 lines
1.6 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Gitlab::SlashCommands::IssueShow do
describe '#execute' do
let(:issue) { create(:issue, project: project) }
let(:project) { create(:project) }
let(:user) { issue.author }
let(:regex_match) { described_class.match("issue show #{issue.iid}") }
before do
project.add_master(user)
end
subject do
described_class.new(project, user).execute(regex_match)
end
context 'the issue exists' do
let(:title) { subject[:attachments].first[:title] }
it 'returns the issue' do
expect(subject[:response_type]).to be(:in_channel)
2017-01-19 03:22:09 -05:00
expect(title).to start_with(issue.title)
end
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[:response_type]).to be(:in_channel)
2017-01-19 03:22:09 -05:00
expect(title).to start_with(issue.title)
end
end
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") }
it "returns not found" do
expect(subject[:response_type]).to be(:ephemeral)
expect(subject[:text]).to match("not found")
end
end
end
describe '.match' do
it 'matches the iid' do
match = described_class.match("issue show 123")
expect(match[:iid]).to eq("123")
end
it 'accepts a reference' do
match = described_class.match("issue show #{Issue.reference_prefix}123")
expect(match[:iid]).to eq("123")
end
end
end