Commit 01e1c664 authored by Valery Sizov's avatar Valery Sizov

[Multiple issue asignees] fix update_cache_counts for issues and specs for that[ci skip]

parent 01d38b02
......@@ -136,14 +136,6 @@ class Issue < ActiveRecord::Base
"id DESC")
end
def update_assignee_cache_counts
return true # TODO implement it properly
# make sure we flush the cache for both the old *and* new assignees(if they exist)
previous_assignee = User.find_by_id(assignee_id_was) if assignee_id_was
previous_assignee&.update_cache_counts
assignee&.update_cache_counts
end
# Returns a Hash of attributes to be used for Twitter card metadata
def card_attributes
{
......
class IssueAssignee < ActiveRecord::Base
belongs_to :issue
belongs_to :assignee, class_name: "User", foreign_key: :user_id
belongs_to :issue
belongs_to :assignee, class_name: "User", foreign_key: :user_id
after_create :update_assignee_cache_counts
after_destroy :update_assignee_cache_counts
def update_assignee_cache_counts
assignee&.update_cache_counts
end
end
......@@ -210,7 +210,7 @@ class MergeRequest < ActiveRecord::Base
# This method is needed for compatibility with issues to not mess view and other code
def assignees
assignee ? [assignee] : []
Array(assignee)
end
def assignee_or_author?(user)
......
......@@ -58,12 +58,12 @@ describe Issue, "Issuable" do
end
describe "before_save" do
describe "#update_cache_counts" do
describe "#update_cache_counts when an issue is reassigned" do
context "when previous assignee exists" do
before do
assignee = create(:user)
issue.project.team << [assignee, :developer]
issue.update(assignee: assignee)
issue.assignees << assignee
end
it "updates cache counts for new assignee" do
......@@ -71,26 +71,65 @@ describe Issue, "Issuable" do
expect(user).to receive(:update_cache_counts)
issue.update(assignee: user)
issue.assignees << user
end
it "updates cache counts for previous assignee" do
old_assignee = issue.assignee
old_assignee = issue.assignees.first
expect_any_instance_of(User).to receive(:update_cache_counts)
issue.assignees.destroy_all
end
end
context "when previous assignee does not exist" do
before{ issue.assignees = [] }
it "updates cache count for the new assignee" do
expect_any_instance_of(User).to receive(:update_cache_counts)
issue.assignees << user
end
end
end
describe "#update_cache_counts when a merge request is reassigned" do
let(:project) { create :project }
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
context "when previous assignee exists" do
before do
assignee = create(:user)
project.team << [assignee, :developer]
merge_request.update(assignee: assignee)
end
it "updates cache counts for new assignee" do
user = create(:user)
expect(user).to receive(:update_cache_counts)
merge_request.update(assignee: user)
end
it "updates cache counts for previous assignee" do
old_assignee = merge_request.assignee
allow(User).to receive(:find_by_id).with(old_assignee.id).and_return(old_assignee)
expect(old_assignee).to receive(:update_cache_counts)
issue.update(assignee: nil)
merge_request.update(assignee: nil)
end
end
context "when previous assignee does not exist" do
before{ issue.update(assignee: nil) }
before { merge_request.update(assignee: nil) }
it "updates cache count for the new assignee" do
expect_any_instance_of(User).to receive(:update_cache_counts)
issue.update(assignee: user)
merge_request.update(assignee: user)
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