FIX: Avoid race condition when enqueuing job.
This commit is contained in:
parent
dfbc93aa2e
commit
195bd02fce
|
@ -25,7 +25,6 @@ class Group < ActiveRecord::Base
|
|||
before_save :cook_bio
|
||||
|
||||
after_save :destroy_deletions
|
||||
after_save :automatic_group_membership
|
||||
after_save :update_primary_group
|
||||
after_save :update_title
|
||||
|
||||
|
@ -35,6 +34,7 @@ class Group < ActiveRecord::Base
|
|||
after_save :expire_cache
|
||||
after_destroy :expire_cache
|
||||
|
||||
after_commit :automatic_group_membership, on: [:create, :update]
|
||||
after_commit :trigger_group_created_event, on: :create
|
||||
after_commit :trigger_group_updated_event, on: :update
|
||||
after_commit :trigger_group_destroyed_event, on: :destroy
|
||||
|
|
|
@ -786,4 +786,29 @@ describe Group do
|
|||
group.reload
|
||||
expect(group.has_messages?).to eq true
|
||||
end
|
||||
|
||||
describe '#automatic_group_membership' do
|
||||
describe 'for a automatic_membership_retroactive group' do
|
||||
let(:group) { Fabricate(:group, automatic_membership_retroactive: true) }
|
||||
|
||||
it "should be triggered on create and update" do
|
||||
expect { group }
|
||||
.to change { Jobs::AutomaticGroupMembership.jobs.size }.by(1)
|
||||
|
||||
job = Jobs::AutomaticGroupMembership.jobs.last
|
||||
|
||||
expect(job["args"].first["group_id"]).to eq(group.id)
|
||||
|
||||
Jobs::AutomaticGroupMembership.jobs.clear
|
||||
|
||||
expect do
|
||||
group.update!(name: 'asdiaksjdias')
|
||||
end.to change { Jobs::AutomaticGroupMembership.jobs.size }.by(1)
|
||||
|
||||
job = Jobs::AutomaticGroupMembership.jobs.last
|
||||
|
||||
expect(job["args"].first["group_id"]).to eq(group.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue