mirror of
https://github.com/whippyshou/mastodon
synced 2024-12-15 23:28:22 +09:00
740f8a95a9
* Add consumable invites * Add UI for generating invite codes * Add tests * Display max uses and expiration in invites table, delete invite * Remove unused column and redundant validator - Default follows not used, probably bad idea - InviteCodeValidator is redundant because RegistrationsController checks invite code validity * Add admin setting to disable invites * Add admin UI for invites, configurable role for invite creation - Admin UI that lists everyone's invites, always available - Admin setting min_invite_role to control who can invite people - Non-admin invite UI only visible if users are allowed to * Do not remove invites from database, expire them instantly
31 lines
956 B
Ruby
31 lines
956 B
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 = Invite.new(max_uses: nil, expires_at: nil)
|
|
expect(invite.valid_for_use?).to be true
|
|
end
|
|
|
|
it 'returns true when not expired' do
|
|
invite = Invite.new(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 = Invite.new(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 = Invite.new(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 = Invite.new(max_uses: 250, uses: 250, expires_at: nil)
|
|
expect(invite.valid_for_use?).to be false
|
|
end
|
|
end
|
|
end
|