logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

invite_spec.rb (956B)


  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 = Invite.new(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 = Invite.new(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 = Invite.new(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 = Invite.new(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 = Invite.new(max_uses: 250, uses: 250, expires_at: nil)
  22. expect(invite.valid_for_use?).to be false
  23. end
  24. end
  25. end