Commit d0b64118 authored by Valery Sizov's avatar Valery Sizov

[Multiple issue asignees] fix a few specs

parent cd364ec5
class IssueAssignee < ActiveRecord::Base class IssueAssignee < ActiveRecord::Base
belongs_to :issue belongs_to :issue
belongs_to :assignee, class_name: "User", foreign_key: :user_id belongs_to :assignee, class_name: "User", foreign_key: :user_id
end end
\ No newline at end of file
...@@ -7,10 +7,14 @@ module Issuable ...@@ -7,10 +7,14 @@ module Issuable
ids = params.delete(:issuable_ids).split(",") ids = params.delete(:issuable_ids).split(",")
items = model_class.where(id: ids) items = model_class.where(id: ids)
%i(state_event milestone_id assignee_id add_label_ids remove_label_ids subscription_event).each do |key| %i(state_event milestone_id assignee_id assignee_ids add_label_ids remove_label_ids subscription_event).each do |key|
params.delete(key) unless params[key].present? params.delete(key) unless params[key].present?
end end
if params[:assignee_ids] == [IssuableFinder::NONE.to_s]
params[:assignee_ids] = []
end
items.each do |issuable| items.each do |issuable|
next unless can?(current_user, :"update_#{type}", issuable) next unless can?(current_user, :"update_#{type}", issuable)
......
...@@ -14,7 +14,7 @@ module MergeRequests ...@@ -14,7 +14,7 @@ module MergeRequests
def execute def execute
assignable_issues.each do |issue| assignable_issues.each do |issue|
Issues::UpdateService.new(issue.project, current_user, assignee_ids: current_user.id.to_s).execute(issue) Issues::UpdateService.new(issue.project, current_user, assignee_ids: [current_user.id]).execute(issue)
end end
{ {
......
...@@ -84,7 +84,6 @@ module SystemNoteService ...@@ -84,7 +84,6 @@ module SystemNoteService
create_note(noteable: issue, project: project, author: author, note: body) create_note(noteable: issue, project: project, author: author, note: body)
end end
# Called when one or more labels on a Noteable are added and/or removed # Called when one or more labels on a Noteable are added and/or removed
# #
# noteable - Noteable object # noteable - Noteable object
......
...@@ -270,7 +270,7 @@ class TodoService ...@@ -270,7 +270,7 @@ class TodoService
end end
end end
def create_mention_todos(project, target, author, note = nil) def create_mention_todos(project, target, author, note = nil)
# Create Todos for directly addressed users # Create Todos for directly addressed users
directly_addressed_users = filter_directly_addressed_users(project, note || target, author) directly_addressed_users = filter_directly_addressed_users(project, note || target, author)
attributes = attributes_for_todo(project, target, author, Todo::DIRECTLY_ADDRESSED, note) attributes = attributes_for_todo(project, target, author, Todo::DIRECTLY_ADDRESSED, note)
......
...@@ -7,7 +7,7 @@ describe 'Awards Emoji', feature: true do ...@@ -7,7 +7,7 @@ describe 'Awards Emoji', feature: true do
let!(:user) { create(:user) } let!(:user) { create(:user) }
let(:issue) do let(:issue) do
create(:issue, create(:issue,
assignees: [@user], assignees: [user],
project: project) project: project)
end end
......
...@@ -62,7 +62,7 @@ describe 'Issues', feature: true do ...@@ -62,7 +62,7 @@ describe 'Issues', feature: true do
expect(page).to have_content 'No assignee - assign yourself' expect(page).to have_content 'No assignee - assign yourself'
end end
expect(issue.reload.assignee).to be_nil expect(issue.reload.assignees).to be_empty
end end
end end
...@@ -363,9 +363,9 @@ describe 'Issues', feature: true do ...@@ -363,9 +363,9 @@ describe 'Issues', feature: true do
let(:user2) { create(:user) } let(:user2) { create(:user) }
before do before do
foo.assignee = user2 foo.assignees << user2
foo.save foo.save
bar.assignee = user2 bar.assignees << user2
bar.save bar.save
end end
...@@ -440,7 +440,7 @@ describe 'Issues', feature: true do ...@@ -440,7 +440,7 @@ describe 'Issues', feature: true do
expect(page).to have_content 'No assignee' expect(page).to have_content 'No assignee'
end end
expect(issue.reload.assignee).to be_nil expect(issue.reload.assignees).to be_empty
end end
it 'allows user to select an assignee', js: true do it 'allows user to select an assignee', js: true do
...@@ -498,7 +498,7 @@ describe 'Issues', feature: true do ...@@ -498,7 +498,7 @@ describe 'Issues', feature: true do
login_with guest login_with guest
visit namespace_project_issue_path(project.namespace, project, issue) visit namespace_project_issue_path(project.namespace, project, issue)
expect(page).to have_content issue.assignee.name expect(page).to have_content issue.assignees.first.name
end end
end end
end end
...@@ -590,7 +590,7 @@ describe 'Issues', feature: true do ...@@ -590,7 +590,7 @@ describe 'Issues', feature: true do
let(:user2) { create(:user) } let(:user2) { create(:user) }
before do before do
issue.assignee = user2 issue.assignees << user2
issue.save issue.save
end end
end end
......
...@@ -103,7 +103,7 @@ describe Banzai::Filter::RedactorFilter, lib: true do ...@@ -103,7 +103,7 @@ describe Banzai::Filter::RedactorFilter, lib: true do
it 'allows references for assignee' do it 'allows references for assignee' do
assignee = create(:user) assignee = create(:user)
project = create(:empty_project, :public) project = create(:empty_project, :public)
issue = create(:issue, :confidential, project: project, assignee: assignee) issue = create(:issue, :confidential, project: project, assignees: [assignee])
link = reference_link(project: project.id, issue: issue.id, reference_type: 'issue') link = reference_link(project: project.id, issue: issue.id, reference_type: 'issue')
doc = filter(link, current_user: assignee) doc = filter(link, current_user: assignee)
......
...@@ -24,7 +24,6 @@ describe User, models: true do ...@@ -24,7 +24,6 @@ describe User, models: true do
it { is_expected.to have_many(:recent_events).class_name('Event') } it { is_expected.to have_many(:recent_events).class_name('Event') }
it { is_expected.to have_many(:issues).dependent(:restrict_with_exception) } it { is_expected.to have_many(:issues).dependent(:restrict_with_exception) }
it { is_expected.to have_many(:notes).dependent(:destroy) } it { is_expected.to have_many(:notes).dependent(:destroy) }
it { is_expected.to have_many(:assigned_issues).dependent(:nullify) }
it { is_expected.to have_many(:merge_requests).dependent(:destroy) } it { is_expected.to have_many(:merge_requests).dependent(:destroy) }
it { is_expected.to have_many(:assigned_merge_requests).dependent(:nullify) } it { is_expected.to have_many(:assigned_merge_requests).dependent(:nullify) }
it { is_expected.to have_many(:identities).dependent(:destroy) } it { is_expected.to have_many(:identities).dependent(:destroy) }
......
...@@ -4,11 +4,12 @@ describe Issuable::BulkUpdateService, services: true do ...@@ -4,11 +4,12 @@ describe Issuable::BulkUpdateService, services: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:empty_project, namespace: user.namespace) } let(:project) { create(:empty_project, namespace: user.namespace) }
def bulk_update(issues, extra_params = {}) def bulk_update(issuables, extra_params = {})
bulk_update_params = extra_params bulk_update_params = extra_params
.reverse_merge(issuable_ids: Array(issues).map(&:id).join(',')) .reverse_merge(issuable_ids: Array(issuables).map(&:id).join(','))
Issuable::BulkUpdateService.new(project, user, bulk_update_params).execute('issue') type = Array(issuables).first.model_name.param_key
Issuable::BulkUpdateService.new(project, user, bulk_update_params).execute(type)
end end
describe 'close issues' do describe 'close issues' do
...@@ -47,15 +48,15 @@ describe Issuable::BulkUpdateService, services: true do ...@@ -47,15 +48,15 @@ describe Issuable::BulkUpdateService, services: true do
end end
end end
describe 'updating assignee' do describe 'updating merge request assignee' do
let(:issue) { create(:issue, project: project, assignee: user) } let(:merge_request) { create(:merge_request, target_project: project, source_project: project, assignee: user) }
context 'when the new assignee ID is a valid user' do context 'when the new assignee ID is a valid user' do
it 'succeeds' do it 'succeeds' do
new_assignee = create(:user) new_assignee = create(:user)
project.team << [new_assignee, :developer] project.team << [new_assignee, :developer]
result = bulk_update(issue, assignee_id: new_assignee.id) result = bulk_update(merge_request, assignee_id: new_assignee.id)
expect(result[:success]).to be_truthy expect(result[:success]).to be_truthy
expect(result[:count]).to eq(1) expect(result[:count]).to eq(1)
...@@ -65,22 +66,59 @@ describe Issuable::BulkUpdateService, services: true do ...@@ -65,22 +66,59 @@ describe Issuable::BulkUpdateService, services: true do
assignee = create(:user) assignee = create(:user)
project.team << [assignee, :developer] project.team << [assignee, :developer]
expect { bulk_update(issue, assignee_id: assignee.id) } expect { bulk_update(merge_request, assignee_id: assignee.id) }
.to change { issue.reload.assignee }.from(user).to(assignee) .to change { merge_request.reload.assignee }.from(user).to(assignee)
end end
end end
context "when the new assignee ID is #{IssuableFinder::NONE}" do context "when the new assignee ID is #{IssuableFinder::NONE}" do
it "unassigns the issues" do it "unassigns the issues" do
expect { bulk_update(issue, assignee_id: IssuableFinder::NONE) } expect { bulk_update(merge_request, assignee_id: IssuableFinder::NONE) }
.to change { issue.reload.assignee }.to(nil) .to change { merge_request.reload.assignee }.to(nil)
end end
end end
context 'when the new assignee ID is not present' do context 'when the new assignee ID is not present' do
it 'does not unassign' do it 'does not unassign' do
expect { bulk_update(issue, assignee_id: nil) } expect { bulk_update(merge_request, assignee_id: nil) }
.not_to change { issue.reload.assignee } .not_to change { merge_request.reload.assignee }
end
end
end
describe 'updating issue assignee' do
let(:issue) { create(:issue, project: project, assignees: [user]) }
context 'when the new assignee ID is a valid user' do
it 'succeeds' do
new_assignee = create(:user)
project.team << [new_assignee, :developer]
result = bulk_update(issue, assignee_ids: [new_assignee.id])
expect(result[:success]).to be_truthy
expect(result[:count]).to eq(1)
end
it 'updates the assignee to the use ID passed' do
assignee = create(:user)
project.team << [assignee, :developer]
expect { bulk_update(issue, assignee_ids: [assignee.id]) }
.to change { issue.reload.assignees.first }.from(user).to(assignee)
end
end
context "when the new assignee ID is #{IssuableFinder::NONE}" do
it "unassigns the issues" do
expect { bulk_update(issue, assignee_ids: [IssuableFinder::NONE.to_s]) }
.to change { issue.reload.assignees.count }.from(1).to(0)
end
end
context 'when the new assignee ID is not present' do
it 'does not unassign' do
expect { bulk_update(issue, assignee_ids: []) }
.not_to change{ issue.reload.assignees }
end end
end end
end end
......
...@@ -20,7 +20,7 @@ describe Issues::CreateService, services: true do ...@@ -20,7 +20,7 @@ describe Issues::CreateService, services: true do
let(:opts) do let(:opts) do
{ title: 'Awesome issue', { title: 'Awesome issue',
description: 'please fix', description: 'please fix',
assignee_ids: assignee.id.to_s, assignee_ids: [assignee.id],
label_ids: labels.map(&:id), label_ids: labels.map(&:id),
milestone_id: milestone.id, milestone_id: milestone.id,
due_date: Date.tomorrow } due_date: Date.tomorrow }
...@@ -37,7 +37,7 @@ describe Issues::CreateService, services: true do ...@@ -37,7 +37,7 @@ describe Issues::CreateService, services: true do
context 'when current user cannot admin issues in the project' do context 'when current user cannot admin issues in the project' do
let(:guest) { create(:user) } let(:guest) { create(:user) }
before do before do
project.team << [guest, :guest] project.team << [guest, :guest]
end end
......
...@@ -162,7 +162,7 @@ describe Issues::UpdateService, services: true do ...@@ -162,7 +162,7 @@ describe Issues::UpdateService, services: true do
it 'does not update assignee_id with unauthorized users' do it 'does not update assignee_id with unauthorized users' do
project.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC) project.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
update_issue(confidential: true) update_issue(confidential: true)
non_member = create(:user) non_member = create(:user)
original_assignees = issue.assignees original_assignees = issue.assignees
update_issue(assignee_ids: [non_member.id]) update_issue(assignee_ids: [non_member.id])
......
...@@ -569,7 +569,7 @@ describe NotificationService, services: true do ...@@ -569,7 +569,7 @@ describe NotificationService, services: true do
end end
it 'emails previous assignee even if he has the "on mention" notif level' do it 'emails previous assignee even if he has the "on mention" notif level' do
issue.assignees = [@u_mentioned] issue.assignees = [@u_mentioned]
notification.reassigned_issue(issue, @u_disabled, [@u_watcher]) notification.reassigned_issue(issue, @u_disabled, [@u_watcher])
should_email(@u_mentioned) should_email(@u_mentioned)
......
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