Commit 34be1835 authored by Valery Sizov's avatar Valery Sizov

[Multiple issue assignee] Fix a number of specs

parent c4094b7e
...@@ -94,7 +94,6 @@ module Issuable ...@@ -94,7 +94,6 @@ module Issuable
acts_as_paranoid acts_as_paranoid
after_save :update_assignee_cache_counts, if: :assignee_id_changed?
after_save :record_metrics, unless: :imported? after_save :record_metrics, unless: :imported?
# We want to use optimistic lock for cases when only title or description are involved # We want to use optimistic lock for cases when only title or description are involved
......
...@@ -26,15 +26,22 @@ module Members ...@@ -26,15 +26,22 @@ module Members
def unassign_issues_and_merge_requests(member) def unassign_issues_and_merge_requests(member)
if member.is_a?(GroupMember) if member.is_a?(GroupMember)
IssuesFinder.new(user, group_id: member.source_id, assignee_id: member.user_id). issue_ids = IssuesFinder.new(user, group_id: member.source_id, assignee_id: member.user_id).
execute. execute.pluck(:id)
update_all(assignee_id: nil)
IssueAssignee.destroy_all(issue_id: issue_ids, user_id: member.user_id)
MergeRequestsFinder.new(user, group_id: member.source_id, assignee_id: member.user_id). MergeRequestsFinder.new(user, group_id: member.source_id, assignee_id: member.user_id).
execute. execute.
update_all(assignee_id: nil) update_all(assignee_id: nil)
else else
project = member.source project = member.source
project.issues.opened.assigned_to(member.user).update_all(assignee_id: nil)
IssueAssignee.destroy_all(
user_id: member.user_id,
issue_id: project.issues.opened.assigned_to(member.user).select(:id)
)
project.merge_requests.opened.assigned_to(member.user).update_all(assignee_id: nil) project.merge_requests.opened.assigned_to(member.user).update_all(assignee_id: nil)
member.user.update_cache_counts member.user.update_cache_counts
end end
......
...@@ -84,7 +84,7 @@ module SystemNoteService ...@@ -84,7 +84,7 @@ module SystemNoteService
"assigned to #{issue.assignees.map(&:to_reference).to_sentence}" "assigned to #{issue.assignees.map(&:to_reference).to_sentence}"
end end
NoteSummary.new(issue, project, author, body, action: 'assignee') create_note(NoteSummary.new(issue, project, author, body, action: 'assignee'))
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
......
...@@ -26,7 +26,7 @@ class CreateIssueAssigneesTable < ActiveRecord::Migration ...@@ -26,7 +26,7 @@ class CreateIssueAssigneesTable < ActiveRecord::Migration
# disable_ddl_transaction! # disable_ddl_transaction!
def up def up
create_table :issue_assignees, id: false do |t| create_table :issue_assignees do |t|
t.references :user, foreign_key: { on_delete: :cascade }, index: true, null: false t.references :user, foreign_key: { on_delete: :cascade }, index: true, null: false
t.references :issue, foreign_key: { on_delete: :cascade }, null: false t.references :issue, foreign_key: { on_delete: :cascade }, null: false
end end
......
...@@ -452,7 +452,7 @@ ActiveRecord::Schema.define(version: 20170502091007) do ...@@ -452,7 +452,7 @@ ActiveRecord::Schema.define(version: 20170502091007) do
add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree
create_table "issue_assignees", id: false, force: :cascade do |t| create_table "issue_assignees", force: :cascade do |t|
t.integer "user_id", null: false t.integer "user_id", null: false
t.integer "issue_id", null: false t.integer "issue_id", null: false
end end
......
...@@ -245,7 +245,7 @@ module Github ...@@ -245,7 +245,7 @@ module Github
issue.label_ids = label_ids(representation.labels) issue.label_ids = label_ids(representation.labels)
issue.milestone_id = milestone_id(representation.milestone) issue.milestone_id = milestone_id(representation.milestone)
issue.author_id = author_id issue.author_id = author_id
issue.assignee_id = user_id(representation.assignee) issue.assignee_ids = [user_id(representation.assignee)]
issue.created_at = representation.created_at issue.created_at = representation.created_at
issue.updated_at = representation.updated_at issue.updated_at = representation.updated_at
issue.save!(validate: false) issue.save!(validate: false)
......
...@@ -19,6 +19,8 @@ describe 'Navigation bar counter', feature: true, caching: true do ...@@ -19,6 +19,8 @@ describe 'Navigation bar counter', feature: true, caching: true do
issue.assignees = [] issue.assignees = []
user.update_cache_counts
Timecop.travel(3.minutes.from_now) do Timecop.travel(3.minutes.from_now) do
visit issues_path visit issues_path
......
require 'spec_helper' require 'spec_helper'
describe IssuesFinder do describe IssuesFinder do
let(:user) { create(:user) } set(:user) { create(:user) }
let(:user2) { create(:user) } set(:user2) { create(:user) }
let(:project1) { create(:empty_project) } set(:project1) { create(:empty_project) }
let(:project2) { create(:empty_project) } set(:project2) { create(:empty_project) }
let(:milestone) { create(:milestone, project: project1) } set(:milestone) { create(:milestone, project: project1) }
let(:label) { create(:label, project: project2) } set(:label) { create(:label, project: project2) }
let(:issue1) { create(:issue, author: user, assignees: [user], project: project1, milestone: milestone, title: 'gitlab') } set(:issue1) { create(:issue, author: user, assignees: [user], project: project1, milestone: milestone, title: 'gitlab') }
let(:issue2) { create(:issue, author: user, assignees: [user], project: project2, description: 'gitlab') } set(:issue2) { create(:issue, author: user, assignees: [user], project: project2, description: 'gitlab') }
let(:issue3) { create(:issue, author: user2, assignees: [user2], project: project2, title: 'tanuki', description: 'tanuki') } set(:issue3) { create(:issue, author: user2, assignees: [user2], project: project2, title: 'tanuki', description: 'tanuki') }
describe '#execute' do describe '#execute' do
let(:closed_issue) { create(:issue, author: user2, assignees: [user2], project: project2, state: 'closed') } set(:closed_issue) { create(:issue, author: user2, assignees: [user2], project: project2, state: 'closed') }
let!(:label_link) { create(:label_link, label: label, target: issue2) } set(:label_link) { create(:label_link, label: label, target: issue2) }
let(:search_user) { user } let(:search_user) { user }
let(:params) { {} } let(:params) { {} }
let(:issues) { described_class.new(search_user, params.reverse_merge(scope: scope, state: 'opened')).execute } let(:issues) { described_class.new(search_user, params.reverse_merge(scope: scope, state: 'opened')).execute }
......
...@@ -1157,38 +1157,6 @@ describe API::V3::Issues do ...@@ -1157,38 +1157,6 @@ describe API::V3::Issues do
end end
end end
describe 'PUT /projects/:id/issues/:issue_id to update weight' do
it 'updates an issue with no weight' do
put v3_api("/projects/#{project.id}/issues/#{issue.id}", user), weight: 5
expect(response).to have_http_status(200)
expect(json_response['weight']).to eq(5)
end
it 'removes a weight from an issue' do
weighted_issue = create(:issue, project: project, weight: 2)
put v3_api("/projects/#{project.id}/issues/#{weighted_issue.id}", user), weight: nil
expect(response).to have_http_status(200)
expect(json_response['weight']).to be_nil
end
it 'returns 400 if weight is less than minimum weight' do
put v3_api("/projects/#{project.id}/issues/#{issue.id}", user), weight: -1
expect(response).to have_http_status(400)
expect(json_response['error']).to eq('weight does not have a valid value')
end
it 'returns 400 if weight is more than maximum weight' do
put v3_api("/projects/#{project.id}/issues/#{issue.id}", user), weight: 10
expect(response).to have_http_status(400)
expect(json_response['error']).to eq('weight does not have a valid value')
end
end
describe "DELETE /projects/:id/issues/:issue_id" do describe "DELETE /projects/:id/issues/:issue_id" do
it "rejects a non member from deleting an issue" do it "rejects a non member from deleting an issue" do
delete v3_api("/projects/#{project.id}/issues/#{issue.id}", non_member) delete v3_api("/projects/#{project.id}/issues/#{issue.id}", non_member)
......
...@@ -164,7 +164,9 @@ describe SystemNoteService, services: true do ...@@ -164,7 +164,9 @@ describe SystemNoteService, services: true do
let(:assignee2) { create(:user) } let(:assignee2) { create(:user) }
let(:assignee3) { create(:user) } let(:assignee3) { create(:user) }
it_behaves_like 'a system note' it_behaves_like 'a system note' do
let(:action) { 'assignee' }
end
def build_note(old_assignees, new_assignees) def build_note(old_assignees, new_assignees)
issue.assignees = new_assignees issue.assignees = new_assignees
......
...@@ -60,7 +60,7 @@ describe Users::DestroyService, services: true do ...@@ -60,7 +60,7 @@ describe Users::DestroyService, services: true do
it 'migrates the issue so that it is "Unassigned"' do it 'migrates the issue so that it is "Unassigned"' do
migrated_issue = Issue.find_by_id(issue.id) migrated_issue = Issue.find_by_id(issue.id)
expect(migrated_issue.assignees).to be_nil expect(migrated_issue.assignees).to be_empty
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