Commit 378904d6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'rs-issue-1778' into 'master'

Correctly remove already-mentioned commits for cross references

Fixes #1778

See merge request !785
parents 4d6a338c 23954b0f
...@@ -67,7 +67,13 @@ module Mentionable ...@@ -67,7 +67,13 @@ module Mentionable
# Create a cross-reference Note for each GFM reference to another Mentionable found in +mentionable_text+. # Create a cross-reference Note for each GFM reference to another Mentionable found in +mentionable_text+.
def create_cross_references!(p = project, a = author, without = []) def create_cross_references!(p = project, a = author, without = [])
refs = references(p) - without refs = references(p)
# We're using this method instead of Array diffing because that requires
# both of the object's `hash` values to be the same, which may not be the
# case for otherwise identical Commit objects.
refs.reject! { |ref| without.include?(ref) }
refs.each do |ref| refs.each do |ref|
Note.create_cross_reference_note(ref, local_reference, a) Note.create_cross_reference_note(ref, local_reference, a)
end end
......
require 'spec_helper' require 'spec_helper'
describe Issue, "Mentionable" do describe Issue, "Mentionable" do
describe :mentioned_users do describe '#mentioned_users' do
let!(:user) { create(:user, username: 'stranger') } let!(:user) { create(:user, username: 'stranger') }
let!(:user2) { create(:user, username: 'john') } let!(:user2) { create(:user, username: 'john') }
let!(:issue) { create(:issue, description: '@stranger mentioned') } let!(:issue) { create(:issue, description: "#{user.to_reference} mentioned") }
subject { issue.mentioned_users } subject { issue.mentioned_users }
it { is_expected.to include(user) } it { is_expected.to include(user) }
it { is_expected.not_to include(user2) } it { is_expected.not_to include(user2) }
end end
describe '#create_cross_references!' do
let(:project) { create(:project) }
let(:author) { double('author') }
let(:commit) { project.commit }
let(:commit2) { project.commit }
let!(:issue) do
create(:issue, project: project, description: commit.to_reference)
end
it 'correctly removes already-mentioned Commits' do
expect(Note).not_to receive(:create_cross_reference_note)
issue.create_cross_references!(project, author, [commit2])
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