Commit 9f7c29ba authored by Lin Jen-Shin's avatar Lin Jen-Shin

Follow feedback on the review

parent 4ded8b1c
...@@ -28,13 +28,13 @@ module Banzai ...@@ -28,13 +28,13 @@ module Banzai
issue_parser = Banzai::ReferenceParser::IssueParser.new(project, user) issue_parser = Banzai::ReferenceParser::IssueParser.new(project, user)
merge_request_parser = Banzai::ReferenceParser::MergeRequestParser.new(project, user) merge_request_parser = Banzai::ReferenceParser::MergeRequestParser.new(project, user)
hash = issue_parser.issues_for_nodes(nodes).merge( issues_for_nodes = issue_parser.issues_for_nodes(nodes).merge(
merge_request_parser.merge_requests_for_nodes(nodes) merge_request_parser.merge_requests_for_nodes(nodes)
) )
hash.each_with_object({}) do |(node, issuable), result| # The project for the issue might be pending for deletion!
result[node] = issuable if issuable.project # Filter them out because we don't care about them.
end issues_for_nodes.select { |node, issuable| issuable.project }
end end
end end
end end
...@@ -6,23 +6,19 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do ...@@ -6,23 +6,19 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:context) { { current_user: user, issuable_state_filter_enabled: true } } let(:context) { { current_user: user, issuable_state_filter_enabled: true } }
let(:closed_issue) { create_issue(:closed, project) } let(:closed_issue) { create_issue(:closed) }
let(:project) { create_project } let(:project) { create(:empty_project, :public) }
let(:other_project) { create_project } let(:other_project) { create(:empty_project, :public) }
def create_link(text, data) def create_link(text, data)
link_to(text, '', class: 'gfm has-tooltip', data: data) link_to(text, '', class: 'gfm has-tooltip', data: data)
end end
def create_project def create_issue(state)
create(:empty_project, :public) create(:issue, state, project: project)
end end
def create_issue(state, the_project = project) def create_merge_request(state)
create(:issue, state, project: the_project)
end
def create_merge_request(state, the_project = project)
create(:merge_request, state, create(:merge_request, state,
source_project: project, target_project: project) source_project: project, target_project: project)
end end
...@@ -91,7 +87,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do ...@@ -91,7 +87,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
context 'when project is in pending delete' do context 'when project is in pending delete' do
before do before do
project.update(pending_delete: true) project.update!(pending_delete: true)
end end
it 'does not append issue state' do it 'does not append issue state' do
...@@ -128,7 +124,9 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do ...@@ -128,7 +124,9 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
end end
context 'for merge request references' do context 'for merge request references' do
def expect_link_text(merge_request, text) it 'ignores open merge request references' do
merge_request = create_merge_request(:opened)
link = create_link( link = create_link(
merge_request.to_reference, merge_request.to_reference,
merge_request: merge_request.id, merge_request: merge_request.id,
...@@ -137,37 +135,63 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do ...@@ -137,37 +135,63 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
doc = filter(link, context) doc = filter(link, context)
expect(doc.css('a').last.text).to eq(text) expect(doc.css('a').last.text).to eq(merge_request.to_reference)
end
it 'ignores open merge request references' do
merge_request = create_merge_request(:opened)
expect_link_text(merge_request, merge_request.to_reference)
end end
it 'ignores reopened merge request references' do it 'ignores reopened merge request references' do
merge_request = create_merge_request(:reopened) merge_request = create_merge_request(:reopened)
expect_link_text(merge_request, merge_request.to_reference) link = create_link(
merge_request.to_reference,
merge_request: merge_request.id,
reference_type: 'merge_request'
)
doc = filter(link, context)
expect(doc.css('a').last.text).to eq(merge_request.to_reference)
end end
it 'ignores locked merge request references' do it 'ignores locked merge request references' do
merge_request = create_merge_request(:locked) merge_request = create_merge_request(:locked)
expect_link_text(merge_request, merge_request.to_reference) link = create_link(
merge_request.to_reference,
merge_request: merge_request.id,
reference_type: 'merge_request'
)
doc = filter(link, context)
expect(doc.css('a').last.text).to eq(merge_request.to_reference)
end end
it 'appends state to closed merge request references' do it 'appends state to closed merge request references' do
merge_request = create_merge_request(:closed) merge_request = create_merge_request(:closed)
expect_link_text(merge_request, "#{merge_request.to_reference} (closed)") link = create_link(
merge_request.to_reference,
merge_request: merge_request.id,
reference_type: 'merge_request'
)
doc = filter(link, context)
expect(doc.css('a').last.text).to eq("#{merge_request.to_reference} (closed)")
end end
it 'appends state to merged merge request references' do it 'appends state to merged merge request references' do
merge_request = create_merge_request(:merged) merge_request = create_merge_request(:merged)
expect_link_text(merge_request, "#{merge_request.to_reference} (merged)") link = create_link(
merge_request.to_reference,
merge_request: merge_request.id,
reference_type: 'merge_request'
)
doc = filter(link, context)
expect(doc.css('a').last.text).to eq("#{merge_request.to_reference} (merged)")
end end
end end
end end
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