Commit 8835b788 authored by Josh Frye's avatar Josh Frye

Flush cache in callback. Add tests

parent bfccea37
......@@ -68,6 +68,14 @@ module Issuable
strip_attributes :title
acts_as_paranoid
after_save :update_assignee_cache_counts, if: :assignee_id_changed?
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_id
end
end
module ClassMethods
......
......@@ -776,18 +776,23 @@ class User < ActiveRecord::Base
notification_settings.find_or_initialize_by(source: source)
end
def assigned_open_merge_request_count
Rails.cache.fetch(['users', id, 'assigned_open_merge_request_count'], expires_in: 60) do
def assigned_open_merge_request_count(force: false)
Rails.cache.fetch(['users', id, 'assigned_open_merge_request_count'], force: force) do
assigned_merge_requests.opened.count
end
end
def assigned_open_issues_count
Rails.cache.fetch(['users', id, 'assigned_open_issues_count'], expires_in: 60) do
def assigned_open_issues_count(force: false)
Rails.cache.fetch(['users', id, 'assigned_open_issues_count'], force: force) do
assigned_issues.opened.count
end
end
def update_cache_counts
assigned_open_merge_request_count(force: true)
assigned_open_issues_count(force: true)
end
private
def projects_union
......
......@@ -62,6 +62,21 @@ describe 'Issues', feature: true do
expect(issue.reload.assignee).to be_nil
end
it 'updates assigned cache count on change', js: true do
visit edit_namespace_project_issue_path(project.namespace, project, issue)
expect(page).to have_content "Assignee #{@user.name}"
expect(@user.assigned_open_issues_count).to eq @user.assigned_issues.opened.count
first('#s2id_issue_assignee_id').click
sleep 2 # wait for ajax stuff to complete
first('.user-result').click
click_button 'Save changes'
expect(@user.assigned_open_issues_count).to eq @user.assigned_issues.opened.count
end
end
describe 'due date', js: true do
......
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