diff options
author | Felipe Artur <felipefac@gmail.com> | 2016-12-14 17:57:14 -0200 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2016-12-20 17:55:14 -0200 |
commit | 77deeb12f74b857f9356168ccdf92612fc85fe84 (patch) | |
tree | eae473639b98b794b1249861af68f9f26efb4e3d | |
parent | b6d069c10fbf0ef13ad78bb22cfc965a278adcea (diff) | |
download | gitlab-ce-77deeb12f74b857f9356168ccdf92612fc85fe84.tar.gz |
Fix issuable assignee update bug when previous assignee is null
-rw-r--r-- | app/models/concerns/issuable.rb | 7 | ||||
-rw-r--r-- | changelogs/unreleased/issue_22664.yml | 4 | ||||
-rw-r--r-- | spec/models/concerns/issuable_spec.rb | 20 |
3 files changed, 28 insertions, 3 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 0ea7b1b1098..ecbfb625c5e 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -92,9 +92,10 @@ module Issuable after_save :record_metrics def update_assignee_cache_counts - # make sure we flush the cache for both the old *and* new assignee - User.find(assignee_id_was).update_cache_counts if assignee_id_was - assignee.update_cache_counts if assignee + # 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) + previous_assignee.try(:update_cache_counts) + assignee.try(:update_cache_counts) end # We want to use optimistic lock for cases when only title or description are involved diff --git a/changelogs/unreleased/issue_22664.yml b/changelogs/unreleased/issue_22664.yml new file mode 100644 index 00000000000..28d3e74b1f8 --- /dev/null +++ b/changelogs/unreleased/issue_22664.yml @@ -0,0 +1,4 @@ +--- +title: Fix issuable assignee update bug when previous assignee is null +merge_request: +author: diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 4fa06a8c60a..3cc96816cb0 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -44,6 +44,26 @@ describe Issue, "Issuable" do it { expect(described_class).to respond_to(:assigned) } 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 let!(:searchable_issue) { create(:issue, title: "Searchable issue") } |