mirror of
https://git.bsd.gay/fef/nyastodon.git
synced 2024-12-25 20:13:43 +01:00
92569ffde8
* Disable invite links from disabled/suspended users * Add has_many invites relationship to users * Destroy unused invites when suspending an account
36 lines
1.2 KiB
Ruby
36 lines
1.2 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Invite, type: :model do
|
|
describe '#valid_for_use?' do
|
|
it 'returns true when there are no limitations' do
|
|
invite = Fabricate(:invite, max_uses: nil, expires_at: nil)
|
|
expect(invite.valid_for_use?).to be true
|
|
end
|
|
|
|
it 'returns true when not expired' do
|
|
invite = Fabricate(:invite, max_uses: nil, expires_at: 1.hour.from_now)
|
|
expect(invite.valid_for_use?).to be true
|
|
end
|
|
|
|
it 'returns false when expired' do
|
|
invite = Fabricate(:invite, max_uses: nil, expires_at: 1.hour.ago)
|
|
expect(invite.valid_for_use?).to be false
|
|
end
|
|
|
|
it 'returns true when uses still available' do
|
|
invite = Fabricate(:invite, max_uses: 250, uses: 249, expires_at: nil)
|
|
expect(invite.valid_for_use?).to be true
|
|
end
|
|
|
|
it 'returns false when maximum uses reached' do
|
|
invite = Fabricate(:invite, max_uses: 250, uses: 250, expires_at: nil)
|
|
expect(invite.valid_for_use?).to be false
|
|
end
|
|
|
|
it 'returns false when invite creator has been disabled' do
|
|
invite = Fabricate(:invite, max_uses: nil, expires_at: nil)
|
|
SuspendAccountService.new.call(invite.user.account)
|
|
expect(invite.valid_for_use?).to be false
|
|
end
|
|
end
|
|
end
|