1
0

invite_spec.rb 1.2 KB

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