Bust cache of organization page when new member is added (#19861)
This commit is contained in:
parent
0699ba05f2
commit
d28b69b658
2 changed files with 22 additions and 0 deletions
|
|
@ -14,6 +14,8 @@ class OrganizationMembership < ApplicationRecord
|
|||
after_create :update_user_organization_info_updated_at
|
||||
after_destroy :update_user_organization_info_updated_at
|
||||
|
||||
after_commit :bust_cache
|
||||
|
||||
scope :admin, -> { where(type_of_user: "admin") }
|
||||
scope :member, -> { where(type_of_user: %w[admin member]) }
|
||||
|
||||
|
|
@ -23,4 +25,10 @@ class OrganizationMembership < ApplicationRecord
|
|||
def update_user_organization_info_updated_at
|
||||
user.touch(:organization_info_updated_at)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def bust_cache
|
||||
BustCachePathWorker.perform_async(organization.path.to_s)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -390,4 +390,18 @@ RSpec.describe Organization do
|
|||
expect(results.size).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#bust_cache" do
|
||||
context "when a new user is added to the organization" do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
it "calls BustCachePathWorker after creating an organization membership" do
|
||||
org_membership = OrganizationMembership.create(user: user, organization: organization, type_of_user: "admin")
|
||||
|
||||
allow(org_membership).to receive(:bust_cache)
|
||||
org_membership.save
|
||||
expect(org_membership).to have_received(:bust_cache)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue