From 5ec214b0a5d9d3f0f0418a0e14ebf30b60a14a12 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Thu, 26 Jan 2017 15:30:34 +0100 Subject: Rename presenters for consitency --- lib/gitlab/chat_commands/command.rb | 2 +- lib/gitlab/chat_commands/issue_create.rb | 42 ------------ lib/gitlab/chat_commands/issue_new.rb | 42 ++++++++++++ lib/gitlab/chat_commands/issue_search.rb | 8 +-- lib/gitlab/chat_commands/issue_show.rb | 2 +- lib/gitlab/chat_commands/presenters/deploy.rb | 8 --- lib/gitlab/chat_commands/presenters/help.rb | 6 +- lib/gitlab/chat_commands/presenters/issuable.rb | 4 +- lib/gitlab/chat_commands/presenters/issue_new.rb | 48 +++++++++++++ .../chat_commands/presenters/issue_search.rb | 45 +++++++++++++ lib/gitlab/chat_commands/presenters/issue_show.rb | 56 ++++++++++++++++ lib/gitlab/chat_commands/presenters/list_issues.rb | 43 ------------ lib/gitlab/chat_commands/presenters/new_issue.rb | 42 ------------ lib/gitlab/chat_commands/presenters/show_issue.rb | 54 --------------- lib/mattermost/command.rb | 4 -- spec/lib/gitlab/chat_commands/command_spec.rb | 2 +- spec/lib/gitlab/chat_commands/issue_create_spec.rb | 78 ---------------------- spec/lib/gitlab/chat_commands/issue_new_spec.rb | 78 ++++++++++++++++++++++ .../chat_commands/presenters/issue_new_spec.rb | 17 +++++ .../chat_commands/presenters/issue_search_spec.rb | 23 +++++++ .../chat_commands/presenters/issue_show_spec.rb | 27 ++++++++ .../chat_commands/presenters/list_issues_spec.rb | 23 ------- .../chat_commands/presenters/show_issue_spec.rb | 27 -------- 23 files changed, 346 insertions(+), 335 deletions(-) delete mode 100644 lib/gitlab/chat_commands/issue_create.rb create mode 100644 lib/gitlab/chat_commands/issue_new.rb create mode 100644 lib/gitlab/chat_commands/presenters/issue_new.rb create mode 100644 lib/gitlab/chat_commands/presenters/issue_search.rb create mode 100644 lib/gitlab/chat_commands/presenters/issue_show.rb delete mode 100644 lib/gitlab/chat_commands/presenters/list_issues.rb delete mode 100644 lib/gitlab/chat_commands/presenters/new_issue.rb delete mode 100644 lib/gitlab/chat_commands/presenters/show_issue.rb delete mode 100644 spec/lib/gitlab/chat_commands/issue_create_spec.rb create mode 100644 spec/lib/gitlab/chat_commands/issue_new_spec.rb create mode 100644 spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb create mode 100644 spec/lib/gitlab/chat_commands/presenters/issue_search_spec.rb create mode 100644 spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/presenters/list_issues_spec.rb delete mode 100644 spec/lib/gitlab/chat_commands/presenters/show_issue_spec.rb diff --git a/lib/gitlab/chat_commands/command.rb b/lib/gitlab/chat_commands/command.rb index 4e5031a8a26..e7baa20356c 100644 --- a/lib/gitlab/chat_commands/command.rb +++ b/lib/gitlab/chat_commands/command.rb @@ -3,7 +3,7 @@ module Gitlab class Command < BaseCommand COMMANDS = [ Gitlab::ChatCommands::IssueShow, - Gitlab::ChatCommands::IssueCreate, + Gitlab::ChatCommands::IssueNew, Gitlab::ChatCommands::IssueSearch, Gitlab::ChatCommands::Deploy, ].freeze diff --git a/lib/gitlab/chat_commands/issue_create.rb b/lib/gitlab/chat_commands/issue_create.rb deleted file mode 100644 index 3f3d7de8b2e..00000000000 --- a/lib/gitlab/chat_commands/issue_create.rb +++ /dev/null @@ -1,42 +0,0 @@ -module Gitlab - module ChatCommands - class IssueCreate < IssueCommand - def self.match(text) - # we can not match \n with the dot by passing the m modifier as than - # the title and description are not seperated - /\Aissue\s+(new|create)\s+(?[^\n]*)\n*(?<description>(.|\n)*)/.match(text) - end - - def self.help_message - 'issue new <title> *`⇧ Shift`*+*`↵ Enter`* <description>' - end - - def self.allowed?(project, user) - can?(user, :create_issue, project) - end - - def execute(match) - title = match[:title] - description = match[:description].to_s.rstrip - - issue = create_issue(title: title, description: description) - - if issue.errors.any? - presenter(issue).display_errors - else - presenter(issue).present - end - end - - private - - def create_issue(title:, description:) - Issues::CreateService.new(project, current_user, title: title, description: description).execute - end - - def presenter(issue) - Gitlab::ChatCommands::Presenters::NewIssue.new(issue) - end - end - end -end diff --git a/lib/gitlab/chat_commands/issue_new.rb b/lib/gitlab/chat_commands/issue_new.rb new file mode 100644 index 00000000000..016054ecd46 --- /dev/null +++ b/lib/gitlab/chat_commands/issue_new.rb @@ -0,0 +1,42 @@ +module Gitlab + module ChatCommands + class IssueNew < IssueCommand + def self.match(text) + # we can not match \n with the dot by passing the m modifier as than + # the title and description are not seperated + /\Aissue\s+(new|create)\s+(?<title>[^\n]*)\n*(?<description>(.|\n)*)/.match(text) + end + + def self.help_message + 'issue new <title> *`⇧ Shift`*+*`↵ Enter`* <description>' + end + + def self.allowed?(project, user) + can?(user, :create_issue, project) + end + + def execute(match) + title = match[:title] + description = match[:description].to_s.rstrip + + issue = create_issue(title: title, description: description) + + if issue.persisted? + presenter(issue).present + else + presenter(issue).display_errors + end + end + + private + + def create_issue(title:, description:) + Issues::CreateService.new(project, current_user, title: title, description: description).execute + end + + def presenter(issue) + Gitlab::ChatCommands::Presenters::IssueNew.new(issue) + end + end + end +end diff --git a/lib/gitlab/chat_commands/issue_search.rb b/lib/gitlab/chat_commands/issue_search.rb index e2d3a0f466a..3491b53093e 100644 --- a/lib/gitlab/chat_commands/issue_search.rb +++ b/lib/gitlab/chat_commands/issue_search.rb @@ -12,12 +12,10 @@ module Gitlab def execute(match) issues = collection.search(match[:query]).limit(QUERY_LIMIT) - if issues.none? - Presenters::Access.new(issues).not_found - elsif issues.one? - Presenters::ShowIssue.new(issues.first).present + if issues.present? + Presenters::IssueSearch.new(issues).present else - Presenters::ListIssues.new(issues).present + Presenters::Access.new(issues).not_found end end end diff --git a/lib/gitlab/chat_commands/issue_show.rb b/lib/gitlab/chat_commands/issue_show.rb index 9f3e1b9a64b..d6013f4d10c 100644 --- a/lib/gitlab/chat_commands/issue_show.rb +++ b/lib/gitlab/chat_commands/issue_show.rb @@ -13,7 +13,7 @@ module Gitlab issue = find_by_iid(match[:iid]) if issue - Gitlab::ChatCommands::Presenters::ShowIssue.new(issue).present + Gitlab::ChatCommands::Presenters::IssueShow.new(issue).present else Gitlab::ChatCommands::Presenters::Access.new.not_found end diff --git a/lib/gitlab/chat_commands/presenters/deploy.rb b/lib/gitlab/chat_commands/presenters/deploy.rb index b1cfaac15af..863d0bf99ca 100644 --- a/lib/gitlab/chat_commands/presenters/deploy.rb +++ b/lib/gitlab/chat_commands/presenters/deploy.rb @@ -15,14 +15,6 @@ module Gitlab def too_many_actions ephemeral_response(text: "Too many actions defined") end - - private - - def resource_url - polymorphic_url( - [ @resource.project.namespace.becomes(Namespace), @resource.project, @resource] - ) - end end end end diff --git a/lib/gitlab/chat_commands/presenters/help.rb b/lib/gitlab/chat_commands/presenters/help.rb index c7a67467b7e..39ad3249f5b 100644 --- a/lib/gitlab/chat_commands/presenters/help.rb +++ b/lib/gitlab/chat_commands/presenters/help.rb @@ -9,10 +9,10 @@ module Gitlab private def help_message(trigger) - if @resource.none? - "No commands available :thinking_face:" - else + if @resource.present? header_with_list("Available commands", full_commands(trigger)) + else + "No commands available :thinking_face:" end end diff --git a/lib/gitlab/chat_commands/presenters/issuable.rb b/lib/gitlab/chat_commands/presenters/issuable.rb index 2cb6b1525fc..dfb1c8f6616 100644 --- a/lib/gitlab/chat_commands/presenters/issuable.rb +++ b/lib/gitlab/chat_commands/presenters/issuable.rb @@ -1,9 +1,7 @@ module Gitlab module ChatCommands module Presenters - class Issuable < Presenters::Base - private - + module Issuable def color(issuable) issuable.open? ? '#38ae67' : '#d22852' end diff --git a/lib/gitlab/chat_commands/presenters/issue_new.rb b/lib/gitlab/chat_commands/presenters/issue_new.rb new file mode 100644 index 00000000000..d26dd22b2a0 --- /dev/null +++ b/lib/gitlab/chat_commands/presenters/issue_new.rb @@ -0,0 +1,48 @@ +module Gitlab + module ChatCommands + module Presenters + class IssueNew < Presenters::Base + include Presenters::Issuable + + def present + in_channel_response(new_issue) + end + + private + + def new_issue + { + attachments: [ + { + title: "#{@resource.title} · #{@resource.to_reference}", + title_link: resource_url, + author_name: author.name, + author_icon: author.avatar_url, + fallback: "New issue #{@resource.to_reference}: #{@resource.title}", + pretext: pretext, + color: color(@resource), + fields: fields, + mrkdwn_in: [ + :title, + :text + ] + } + ] + } + end + + def pretext + "I opened an issue on behalf on #{author_profile_link}: *#{@resource.to_reference}* from #{project.name_with_namespace}" + end + + def project_link + "[#{project.name_with_namespace}](#{url_for(project)})" + end + + def author_profile_link + "[#{author.to_reference}](#{url_for(author)})" + end + end + end + end +end diff --git a/lib/gitlab/chat_commands/presenters/issue_search.rb b/lib/gitlab/chat_commands/presenters/issue_search.rb new file mode 100644 index 00000000000..d58a6d6114a --- /dev/null +++ b/lib/gitlab/chat_commands/presenters/issue_search.rb @@ -0,0 +1,45 @@ +module Gitlab + module ChatCommands + module Presenters + class IssueSearch < Presenters::Base + include Presenters::Issuable + + def present + text = if @resource.count >= 5 + "Here are the first 5 issues I found:" + else + "Here are the #{@resource.count} issues I found:" + end + + ephemeral_response(text: text, attachments: attachments) + end + + private + + def attachments + @resource.map do |issue| + url = "[#{issue.to_reference}](#{url_for([namespace, project, issue])})" + + { + color: color(issue), + fallback: "#{issue.to_reference} #{issue.title}", + text: "#{url} · #{issue.title} (#{status_text(issue)})", + + mrkdwn_in: [ + "text" + ] + } + end + end + + def project + @project ||= @resource.first.project + end + + def namespace + @namespace ||= project.namespace.becomes(Namespace) + end + end + end + end +end diff --git a/lib/gitlab/chat_commands/presenters/issue_show.rb b/lib/gitlab/chat_commands/presenters/issue_show.rb new file mode 100644 index 00000000000..2fc671f13a6 --- /dev/null +++ b/lib/gitlab/chat_commands/presenters/issue_show.rb @@ -0,0 +1,56 @@ +module Gitlab + module ChatCommands + module Presenters + class IssueShow < Presenters::Base + include Presenters::Issuable + + def present + in_channel_response(show_issue) + end + + private + + def show_issue + { + attachments: [ + { + title: "#{@resource.title} · #{@resource.to_reference}", + title_link: resource_url, + author_name: author.name, + author_icon: author.avatar_url, + fallback: "Issue #{@resource.to_reference}: #{@resource.title}", + pretext: pretext, + text: text, + color: color(@resource), + fields: fields, + mrkdwn_in: [ + :pretext, + :text + ] + } + ] + } + end + + def text + message = "**#{status_text(@resource)}**" + + if @resource.upvotes.zero? && @resource.downvotes.zero? && @resource.user_notes_count.zero? + return message + end + + message << " · " + message << ":+1: #{@resource.upvotes} " unless @resource.upvotes.zero? + message << ":-1: #{@resource.downvotes} " unless @resource.downvotes.zero? + message << ":speech_balloon: #{@resource.user_notes_count}" unless @resource.user_notes_count.zero? + + message + end + + def pretext + "Issue *#{@resource.to_reference} from #{project.name_with_namespace}" + end + end + end + end +end diff --git a/lib/gitlab/chat_commands/presenters/list_issues.rb b/lib/gitlab/chat_commands/presenters/list_issues.rb deleted file mode 100644 index 2458b9356b7..00000000000 --- a/lib/gitlab/chat_commands/presenters/list_issues.rb +++ /dev/null @@ -1,43 +0,0 @@ -module Gitlab - module ChatCommands - module Presenters - class ListIssues < Presenters::Issuable - def present - text = if @resource.count >= 5 - "Here are the first 5 issues I found:" - else - "Here are the #{@resource.count} issues I found:" - end - - ephemeral_response(text: text, attachments: attachments) - end - - private - - def attachments - @resource.map do |issue| - url = "[#{issue.to_reference}](#{url_for([namespace, project, issue])})" - - { - color: color(issue), - fallback: "#{issue.to_reference} #{issue.title}", - text: "#{url} · #{issue.title} (#{status_text(issue)})", - - mrkdwn_in: [ - "text" - ] - } - end - end - - def project - @project ||= @resource.first.project - end - - def namespace - @namespace ||= project.namespace.becomes(Namespace) - end - end - end - end -end diff --git a/lib/gitlab/chat_commands/presenters/new_issue.rb b/lib/gitlab/chat_commands/presenters/new_issue.rb deleted file mode 100644 index c7c6febb56e..00000000000 --- a/lib/gitlab/chat_commands/presenters/new_issue.rb +++ /dev/null @@ -1,42 +0,0 @@ -module Gitlab - module ChatCommands - module Presenters - class NewIssue < Presenters::Issuable - def present - in_channel_response(show_issue) - end - - private - - def show_issue - { - attachments: [ - { - title: "#{@resource.title} · #{@resource.to_reference}", - title_link: resource_url, - author_name: author.name, - author_icon: author.avatar_url, - fallback: "New issue #{@resource.to_reference}: #{@resource.title}", - pretext: pretext, - color: color(@resource), - fields: fields, - mrkdwn_in: [ - :title, - :text - ] - } - ] - } - end - - def pretext - "I opened an issue on behalf on #{author_profile_link}: *#{@resource.to_reference}* from #{project.name_with_namespace}" - end - - def author_profile_link - "[#{author.to_reference}](#{url_for(author)})" - end - end - end - end -end diff --git a/lib/gitlab/chat_commands/presenters/show_issue.rb b/lib/gitlab/chat_commands/presenters/show_issue.rb deleted file mode 100644 index e5644a4ad7e..00000000000 --- a/lib/gitlab/chat_commands/presenters/show_issue.rb +++ /dev/null @@ -1,54 +0,0 @@ -module Gitlab - module ChatCommands - module Presenters - class ShowIssue < Presenters::Issuable - def present - in_channel_response(show_issue) - end - - private - - def show_issue - { - attachments: [ - { - title: "#{@resource.title} · #{@resource.to_reference}", - title_link: resource_url, - author_name: author.name, - author_icon: author.avatar_url, - fallback: "New issue #{@resource.to_reference}: #{@resource.title}", - pretext: pretext, - text: text, - color: color(@resource), - fields: fields, - mrkdwn_in: [ - :pretext, - :text - ] - } - ] - } - end - - def text - message = "**#{status_text(@resource)}**" - - if @resource.upvotes.zero? && @resource.downvotes.zero? && @resource.user_notes_count.zero? - return message - end - - message << " · " - message << ":+1: #{@resource.upvotes} " unless @resource.upvotes.zero? - message << ":-1: #{@resource.downvotes} " unless @resource.downvotes.zero? - message << ":speech_balloon: #{@resource.user_notes_count}" unless @resource.user_notes_count.zero? - - message - end - - def pretext - "Issue *#{@resource.to_reference} from #{project.name_with_namespace}" - end - end - end - end -end diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb index 2e4f7705f86..33e450d7f0a 100644 --- a/lib/mattermost/command.rb +++ b/lib/mattermost/command.rb @@ -1,11 +1,7 @@ module Mattermost class Command < Client def create(params) -<<<<<<< HEAD response = session_post("/api/v3/teams/#{params[:team_id]}/commands/create", -======= - response = json_post("/api/v3/teams/#{params[:team_id]}/commands/create", ->>>>>>> Revert removing of some files body: params.to_json) response['token'] diff --git a/spec/lib/gitlab/chat_commands/command_spec.rb b/spec/lib/gitlab/chat_commands/command_spec.rb index d8b2303555c..0acf40de1d3 100644 --- a/spec/lib/gitlab/chat_commands/command_spec.rb +++ b/spec/lib/gitlab/chat_commands/command_spec.rb @@ -94,7 +94,7 @@ describe Gitlab::ChatCommands::Command, service: true do context 'IssueCreate is triggered' do let(:params) { { text: 'issue create my title' } } - it { is_expected.to eq(Gitlab::ChatCommands::IssueCreate) } + it { is_expected.to eq(Gitlab::ChatCommands::IssueNew) } end context 'IssueSearch is triggered' do diff --git a/spec/lib/gitlab/chat_commands/issue_create_spec.rb b/spec/lib/gitlab/chat_commands/issue_create_spec.rb deleted file mode 100644 index 0f84b19a5a4..00000000000 --- a/spec/lib/gitlab/chat_commands/issue_create_spec.rb +++ /dev/null @@ -1,78 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::IssueCreate, service: true do - describe '#execute' do - let(:project) { create(:empty_project) } - let(:user) { create(:user) } - let(:regex_match) { described_class.match("issue create bird is the word") } - - before do - project.team << [user, :master] - end - - subject do - described_class.new(project, user).execute(regex_match) - end - - context 'without description' do - it 'creates the issue' do - expect { subject }.to change { project.issues.count }.by(1) - - expect(subject[:response_type]).to be(:in_channel) - end - end - - context 'with description' do - let(:description) { "Surfin bird" } - let(:regex_match) { described_class.match("issue create bird is the word\n#{description}") } - - it 'creates the issue with description' do - subject - - expect(Issue.last.description).to eq(description) - end - end - - context "with more newlines between the title and the description" do - let(:description) { "Surfin bird" } - let(:regex_match) { described_class.match("issue create bird is the word\n\n#{description}\n") } - - it 'creates the issue' do - expect { subject }.to change { project.issues.count }.by(1) - end - end - - context 'issue cannot be created' do - let!(:issue) { create(:issue, project: project, title: 'bird is the word') } - let(:regex_match) { described_class.match("issue create #{'a' * 512}}") } - - it 'displays the errors' do - expect(subject[:response_type]).to be(:ephemeral) - expect(subject[:text]).to match("- Title is too long") - end - end - end - - describe '.match' do - it 'matches the title without description' do - match = described_class.match("issue create my title") - - expect(match[:title]).to eq('my title') - expect(match[:description]).to eq("") - end - - it 'matches the title with description' do - match = described_class.match("issue create my title\n\ndescription") - - expect(match[:title]).to eq('my title') - expect(match[:description]).to eq('description') - end - - it 'matches the alias new' do - match = described_class.match("issue new my title") - - expect(match).not_to be_nil - expect(match[:title]).to eq('my title') - end - end -end diff --git a/spec/lib/gitlab/chat_commands/issue_new_spec.rb b/spec/lib/gitlab/chat_commands/issue_new_spec.rb new file mode 100644 index 00000000000..84c22328064 --- /dev/null +++ b/spec/lib/gitlab/chat_commands/issue_new_spec.rb @@ -0,0 +1,78 @@ +require 'spec_helper' + +describe Gitlab::ChatCommands::IssueNew, service: true do + describe '#execute' do + let(:project) { create(:empty_project) } + let(:user) { create(:user) } + let(:regex_match) { described_class.match("issue create bird is the word") } + + before do + project.team << [user, :master] + end + + subject do + described_class.new(project, user).execute(regex_match) + end + + context 'without description' do + it 'creates the issue' do + expect { subject }.to change { project.issues.count }.by(1) + + expect(subject[:response_type]).to be(:in_channel) + end + end + + context 'with description' do + let(:description) { "Surfin bird" } + let(:regex_match) { described_class.match("issue create bird is the word\n#{description}") } + + it 'creates the issue with description' do + subject + + expect(Issue.last.description).to eq(description) + end + end + + context "with more newlines between the title and the description" do + let(:description) { "Surfin bird" } + let(:regex_match) { described_class.match("issue create bird is the word\n\n#{description}\n") } + + it 'creates the issue' do + expect { subject }.to change { project.issues.count }.by(1) + end + end + + context 'issue cannot be created' do + let!(:issue) { create(:issue, project: project, title: 'bird is the word') } + let(:regex_match) { described_class.match("issue create #{'a' * 512}}") } + + it 'displays the errors' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to match("- Title is too long") + end + end + end + + describe '.match' do + it 'matches the title without description' do + match = described_class.match("issue create my title") + + expect(match[:title]).to eq('my title') + expect(match[:description]).to eq("") + end + + it 'matches the title with description' do + match = described_class.match("issue create my title\n\ndescription") + + expect(match[:title]).to eq('my title') + expect(match[:description]).to eq('description') + end + + it 'matches the alias new' do + match = described_class.match("issue new my title") + + expect(match).not_to be_nil + expect(match[:title]).to eq('my title') + end + end +end diff --git a/spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb b/spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb new file mode 100644 index 00000000000..17fcdbc2452 --- /dev/null +++ b/spec/lib/gitlab/chat_commands/presenters/issue_new_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Gitlab::ChatCommands::Presenters::IssueNew do + let(:project) { create(:empty_project) } + let(:issue) { create(:issue, project: project) } + let(:attachment) { subject[:attachments].first } + + subject { described_class.new(issue).present } + + it { is_expected.to be_a(Hash) } + + it 'shows the issue' do + expect(subject[:response_type]).to be(:in_channel) + expect(subject).to have_key(:attachments) + expect(attachment[:title]).to start_with(issue.title) + end +end diff --git a/spec/lib/gitlab/chat_commands/presenters/issue_search_spec.rb b/spec/lib/gitlab/chat_commands/presenters/issue_search_spec.rb new file mode 100644 index 00000000000..ec6d3e34a96 --- /dev/null +++ b/spec/lib/gitlab/chat_commands/presenters/issue_search_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Gitlab::ChatCommands::Presenters::IssueSearch do + let(:project) { create(:empty_project) } + let(:message) { subject[:text] } + + before { create_list(:issue, 2, project: project) } + + subject { described_class.new(project.issues).present } + + it 'formats the message correct' do + is_expected.to have_key(:text) + is_expected.to have_key(:status) + is_expected.to have_key(:response_type) + is_expected.to have_key(:attachments) + end + + it 'shows a list of results' do + expect(subject[:response_type]).to be(:ephemeral) + + expect(message).to start_with("Here are the 2 issues I found") + end +end diff --git a/spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb b/spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb new file mode 100644 index 00000000000..89d154e26e4 --- /dev/null +++ b/spec/lib/gitlab/chat_commands/presenters/issue_show_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe Gitlab::ChatCommands::Presenters::IssueShow do + let(:project) { create(:empty_project) } + let(:issue) { create(:issue, project: project) } + let(:attachment) { subject[:attachments].first } + + subject { described_class.new(issue).present } + + it { is_expected.to be_a(Hash) } + + it 'shows the issue' do + expect(subject[:response_type]).to be(:in_channel) + expect(subject).to have_key(:attachments) + expect(attachment[:title]).to start_with(issue.title) + end + + context 'with upvotes' do + before do + create(:award_emoji, :upvote, awardable: issue) + end + + it 'shows the upvote count' do + expect(attachment[:text]).to start_with("**Open** · :+1: 1") + end + end +end diff --git a/spec/lib/gitlab/chat_commands/presenters/list_issues_spec.rb b/spec/lib/gitlab/chat_commands/presenters/list_issues_spec.rb deleted file mode 100644 index 13a1f70fe78..00000000000 --- a/spec/lib/gitlab/chat_commands/presenters/list_issues_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::Presenters::ListIssues do - let(:project) { create(:empty_project) } - let(:message) { subject[:text] } - - before { create_list(:issue, 2, project: project) } - - subject { described_class.new(project.issues).present } - - it 'formats the message correct' do - is_expected.to have_key(:text) - is_expected.to have_key(:status) - is_expected.to have_key(:response_type) - is_expected.to have_key(:attachments) - end - - it 'shows a list of results' do - expect(subject[:response_type]).to be(:ephemeral) - - expect(message).to start_with("Here are the 2 issues I found") - end -end diff --git a/spec/lib/gitlab/chat_commands/presenters/show_issue_spec.rb b/spec/lib/gitlab/chat_commands/presenters/show_issue_spec.rb deleted file mode 100644 index ca4062e692a..00000000000 --- a/spec/lib/gitlab/chat_commands/presenters/show_issue_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'spec_helper' - -describe Gitlab::ChatCommands::Presenters::ShowIssue do - let(:project) { create(:empty_project) } - let(:issue) { create(:issue, project: project) } - let(:attachment) { subject[:attachments].first } - - subject { described_class.new(issue).present } - - it { is_expected.to be_a(Hash) } - - it 'shows the issue' do - expect(subject[:response_type]).to be(:in_channel) - expect(subject).to have_key(:attachments) - expect(attachment[:title]).to start_with(issue.title) - end - - context 'with upvotes' do - before do - create(:award_emoji, :upvote, awardable: issue) - end - - it 'shows the upvote count' do - expect(attachment[:text]).to start_with("**Open** · :+1: 1") - end - end -end -- cgit v1.2.1