invite_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. require 'rails_helper'
  2. RSpec.describe Invite, type: :model do
  3. describe '#valid_for_use?' do
  4. it 'returns true when there are no limitations' do
  5. invite = Fabricate(:invite, max_uses: nil, expires_at: nil)
  6. expect(invite.valid_for_use?).to be true
  7. end
  8. it 'returns true when not expired' do
  9. invite = Fabricate(:invite, max_uses: nil, expires_at: 1.hour.from_now)
  10. expect(invite.valid_for_use?).to be true
  11. end
  12. it 'returns false when expired' do
  13. invite = Fabricate(:invite, max_uses: nil, expires_at: 1.hour.ago)
  14. expect(invite.valid_for_use?).to be false
  15. end
  16. it 'returns true when uses still available' do
  17. invite = Fabricate(:invite, max_uses: 250, uses: 249, expires_at: nil)
  18. expect(invite.valid_for_use?).to be true
  19. end
  20. it 'returns false when maximum uses reached' do
  21. invite = Fabricate(:invite, max_uses: 250, uses: 250, expires_at: nil)
  22. expect(invite.valid_for_use?).to be false
  23. end
  24. it 'returns false when invite creator has been disabled' do
  25. invite = Fabricate(:invite, max_uses: nil, expires_at: nil)
  26. SuspendAccountService.new.call(invite.user.account)
  27. expect(invite.valid_for_use?).to be false
  28. end
  29. end
  30. end