BigW Consortium Gitlab

remove_expired_members_worker_spec.rb 2.26 KB
Newer Older
1 2 3
require 'spec_helper'

describe RemoveExpiredMembersWorker do
4
  let(:worker) { RemoveExpiredMembersWorker.new }
5

6
  describe '#perform' do
7 8 9 10 11 12 13 14 15 16
    context 'project members' do
      let!(:expired_project_member) { create(:project_member, expires_at: 1.hour.ago, access_level: GroupMember::DEVELOPER) }
      let!(:project_member_expiring_in_future) { create(:project_member, expires_at: 10.days.from_now, access_level: GroupMember::DEVELOPER) }
      let!(:non_expiring_project_member) { create(:project_member, expires_at: nil, access_level: GroupMember::DEVELOPER) }

      it 'removes expired members' do
        expect { worker.perform }.to change { Member.count }.by(-1)
        expect(Member.find_by(id: expired_project_member.id)).to be_nil
      end

17
      it 'leaves members that expire in the future' do
18 19 20 21
        worker.perform
        expect(project_member_expiring_in_future.reload).to be_present
      end

22
      it 'leaves members that do not expire at all' do
23 24 25
        worker.perform
        expect(non_expiring_project_member.reload).to be_present
      end
26 27
    end

28 29 30 31 32 33 34 35 36 37
    context 'group members' do
      let!(:expired_group_member) { create(:group_member, expires_at: 1.hour.ago, access_level: GroupMember::DEVELOPER) }
      let!(:group_member_expiring_in_future) { create(:group_member, expires_at: 10.days.from_now, access_level: GroupMember::DEVELOPER) }
      let!(:non_expiring_group_member) { create(:group_member, expires_at: nil, access_level: GroupMember::DEVELOPER) }

      it 'removes expired members' do
        expect { worker.perform }.to change { Member.count }.by(-1)
        expect(Member.find_by(id: expired_group_member.id)).to be_nil
      end

38
      it 'leaves members that expire in the future' do
39 40 41 42
        worker.perform
        expect(group_member_expiring_in_future.reload).to be_present
      end

43
      it 'leaves members that do not expire at all' do
44 45 46
        worker.perform
        expect(non_expiring_group_member.reload).to be_present
      end
47 48
    end

49 50 51 52 53 54 55
    context 'when the last group owner expires' do
      let!(:expired_group_owner) { create(:group_member, expires_at: 1.hour.ago, access_level: GroupMember::OWNER) }

      it 'does not delete the owner' do
        worker.perform
        expect(expired_group_owner.reload).to be_present
      end
56 57 58
    end
  end
end