Commit 174655c4 authored by Felipe Artur's avatar Felipe Artur Committed by Sean McGivern

Fix issuable assignee update bug when previous assignee is null

parent 20be0c01
...@@ -96,9 +96,10 @@ module Issuable ...@@ -96,9 +96,10 @@ module Issuable
after_save :record_metrics after_save :record_metrics
def update_assignee_cache_counts def update_assignee_cache_counts
# make sure we flush the cache for both the old *and* new assignee # make sure we flush the cache for both the old *and* new assignees(if they exist)
User.find(assignee_id_was).update_cache_counts if assignee_id_was previous_assignee = User.find_by_id(assignee_id_was)
assignee.update_cache_counts if assignee previous_assignee.try(:update_cache_counts)
assignee.try(:update_cache_counts)
end end
# 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
......
---
title: Fix issuable assignee update bug when previous assignee is null
merge_request:
author:
...@@ -44,6 +44,26 @@ describe Issue, "Issuable" do ...@@ -44,6 +44,26 @@ describe Issue, "Issuable" do
it { expect(described_class).to respond_to(:assigned) } it { expect(described_class).to respond_to(:assigned) }
end end
describe "after_save" do
describe "#update_cache_counts" do
context "when previous assignee exists" do
it "user updates cache counts" do
expect(user).to receive(:update_cache_counts)
issue.update(assignee: user)
end
end
context "when previous assignee does not exist" do
it "does not raise error" do
issue.update(assignee_id: "")
expect { issue.update(assignee_id: user) }.not_to raise_error
end
end
end
end
describe ".search" do describe ".search" do
let!(:searchable_issue) { create(:issue, title: "Searchable issue") } let!(:searchable_issue) { create(:issue, title: "Searchable issue") }
......
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