Commit 2fd03127 authored by Valery Sizov's avatar Valery Sizov

[Multiple issue assignees] Fix issuable.assignee_or_author?

parent 2f06d8b3
......@@ -342,11 +342,6 @@ module Issuable
false
end
def assignee_or_author?(user)
# We're comparing IDs here so we don't need to load any associations.
author_id == user.id || assignee_id == user.id
end
def record_metrics
metrics = self.metrics || create_metrics
metrics.record!
......
......@@ -139,6 +139,10 @@ class Issue < ActiveRecord::Base
}
end
def assignee_or_author?(user)
author_id == user.id || assignees.exists?(user)
end
def assignee_list
assignees.pluck(:name).join(', ')
end
......
......@@ -193,6 +193,10 @@ class MergeRequest < ActiveRecord::Base
}
end
def assignee_or_author?(user)
author_id == user.id || assignee_id == user.id
end
# `from` argument can be a Namespace or Project.
def to_reference(from = nil, full: false)
reference = "#{self.class.reference_prefix}#{iid}"
......
......@@ -36,7 +36,7 @@ module Issues
'Author' => 'author_name',
'Author Username' => -> (issue) { issue.author&.username },
'Assignee' => 'assignee_name',
'Assignee Username' => -> (issue) { issue.assignee&.username },
'Assignee Username' => -> (issue) { issue.assignee_list },
'Confidential' => -> (issue) { issue.confidential? ? 'Yes' : 'No' },
'Due Date' => -> (issue) { issue.due_date&.to_s(:csv) },
'Created At (UTC)' => -> (issue) { issue.created_at&.to_s(:csv) },
......
......@@ -493,27 +493,6 @@ describe Issue, "Issuable" do
end
end
describe '#assignee_or_author?' do
let(:user) { build(:user, id: 1) }
let(:issue) { build(:issue) }
it 'returns true for a user that is assigned to an issue' do
issue.assignee = user
expect(issue.assignee_or_author?(user)).to eq(true)
end
it 'returns true for a user that is the author of an issue' do
issue.author = user
expect(issue.assignee_or_author?(user)).to eq(true)
end
it 'returns false for a user that is not the assignee or author' do
expect(issue.assignee_or_author?(user)).to eq(false)
end
end
describe '#spend_time' do
let(:user) { create(:user) }
let(:issue) { create(:issue) }
......
......@@ -132,6 +132,27 @@ describe Issue, models: true do
end
end
describe '#assignee_or_author?' do
let(:user) { create(:user) }
let(:issue) { create(:issue) }
it 'returns true for a user that is assigned to an issue' do
issue.assignees << user
expect(issue.assignee_or_author?(user)).to be_truthy
end
it 'returns true for a user that is the author of an issue' do
issue.update(author: user)
expect(issue.assignee_or_author?(user)).to be_truthy
end
it 'returns false for a user that is not the assignee or author' do
expect(issue.assignee_or_author?(user)).to be_falsey
end
end
describe '#is_being_reassigned?' do
it 'returns true if the issue assignee has changed' do
subject.assignee = create(:user)
......
......@@ -87,6 +87,26 @@ describe MergeRequest, models: true do
end
end
describe '#assignee_or_author?' do
let(:user) { build(:user) }
it 'returns true for a user that is assigned to a merge request' do
subject.assignee = user
expect(subject.assignee_or_author?(user)).to eq(true)
end
it 'returns true for a user that is the author of a merge request' do
subject.author = user
expect(subject.assignee_or_author?(user)).to eq(true)
end
it 'returns false for a user that is not the assignee or author' do
expect(subject.assignee_or_author?(user)).to eq(false)
end
end
describe '#cache_merge_request_closes_issues!' do
before do
subject.project.team << [subject.author, :developer]
......
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