[Multiple issue assignee] Fix a number of specs

This commit is contained in:
Valery Sizov 2017-05-05 13:41:35 +03:00
parent c4094b7ec4
commit 34be1835af
11 changed files with 32 additions and 54 deletions

View file

@ -94,7 +94,6 @@ module Issuable
acts_as_paranoid
after_save :update_assignee_cache_counts, if: :assignee_id_changed?
after_save :record_metrics, unless: :imported?
# We want to use optimistic lock for cases when only title or description are involved

View file

@ -26,15 +26,22 @@ module Members
def unassign_issues_and_merge_requests(member)
if member.is_a?(GroupMember)
IssuesFinder.new(user, group_id: member.source_id, assignee_id: member.user_id).
execute.
update_all(assignee_id: nil)
issue_ids = IssuesFinder.new(user, group_id: member.source_id, assignee_id: member.user_id).
execute.pluck(:id)
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).
execute.
update_all(assignee_id: nil)
else
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)
member.user.update_cache_counts
end

View file

@ -84,7 +84,7 @@ module SystemNoteService
"assigned to #{issue.assignees.map(&:to_reference).to_sentence}"
end
NoteSummary.new(issue, project, author, body, action: 'assignee')
create_note(NoteSummary.new(issue, project, author, body, action: 'assignee'))
end
# Called when one or more labels on a Noteable are added and/or removed

View file

@ -26,7 +26,7 @@ class CreateIssueAssigneesTable < ActiveRecord::Migration
# disable_ddl_transaction!
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 :issue, foreign_key: { on_delete: :cascade }, null: false
end

View file

@ -452,7 +452,7 @@ ActiveRecord::Schema.define(version: 20170502091007) do
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 "issue_id", null: false
end

View file

@ -245,7 +245,7 @@ module Github
issue.label_ids = label_ids(representation.labels)
issue.milestone_id = milestone_id(representation.milestone)
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.updated_at = representation.updated_at
issue.save!(validate: false)

View file

@ -19,6 +19,8 @@ describe 'Navigation bar counter', feature: true, caching: true do
issue.assignees = []
user.update_cache_counts
Timecop.travel(3.minutes.from_now) do
visit issues_path

View file

@ -1,19 +1,19 @@
require 'spec_helper'
describe IssuesFinder do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:project1) { create(:empty_project) }
let(:project2) { create(:empty_project) }
let(:milestone) { create(:milestone, project: project1) }
let(:label) { create(:label, project: project2) }
let(: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') }
let(:issue3) { create(:issue, author: user2, assignees: [user2], project: project2, title: 'tanuki', description: 'tanuki') }
set(:user) { create(:user) }
set(:user2) { create(:user) }
set(:project1) { create(:empty_project) }
set(:project2) { create(:empty_project) }
set(:milestone) { create(:milestone, project: project1) }
set(:label) { create(:label, project: project2) }
set(:issue1) { create(:issue, author: user, assignees: [user], project: project1, milestone: milestone, title: 'gitlab') }
set(:issue2) { create(:issue, author: user, assignees: [user], project: project2, description: 'gitlab') }
set(:issue3) { create(:issue, author: user2, assignees: [user2], project: project2, title: 'tanuki', description: 'tanuki') }
describe '#execute' do
let(:closed_issue) { create(:issue, author: user2, assignees: [user2], project: project2, state: 'closed') }
let!(:label_link) { create(:label_link, label: label, target: issue2) }
set(:closed_issue) { create(:issue, author: user2, assignees: [user2], project: project2, state: 'closed') }
set(:label_link) { create(:label_link, label: label, target: issue2) }
let(:search_user) { user }
let(:params) { {} }
let(:issues) { described_class.new(search_user, params.reverse_merge(scope: scope, state: 'opened')).execute }

View file

@ -1157,38 +1157,6 @@ describe API::V3::Issues do
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
it "rejects a non member from deleting an issue" do
delete v3_api("/projects/#{project.id}/issues/#{issue.id}", non_member)

View file

@ -164,7 +164,9 @@ describe SystemNoteService, services: true do
let(:assignee2) { 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)
issue.assignees = new_assignees

View file

@ -60,7 +60,7 @@ describe Users::DestroyService, services: true do
it 'migrates the issue so that it is "Unassigned"' do
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