mirror of
https://github.com/mastodon/mastodon.git
synced 2025-02-06 15:05:07 +00:00
22c1b6f3ee
Some checks failed
Check i18n / check-i18n (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Crowdin / Upload translations / upload-translations (push) Has been cancelled
Bundler Audit / security (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
86 lines
2.6 KiB
Ruby
86 lines
2.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe Invite do
|
|
include_examples 'Expireable'
|
|
|
|
describe 'Associations' do
|
|
it { is_expected.to belong_to(:user).inverse_of(:invites) }
|
|
it { is_expected.to have_many(:users).inverse_of(:invite) }
|
|
end
|
|
|
|
describe 'Validations' do
|
|
it { is_expected.to validate_length_of(:comment).is_at_most(described_class::COMMENT_SIZE_LIMIT) }
|
|
end
|
|
|
|
describe 'Scopes' do
|
|
describe '.available' do
|
|
let!(:no_expires) { Fabricate :invite, expires_at: nil }
|
|
let!(:past_expires) { Fabricate :invite, expires_at: 2.days.ago }
|
|
let!(:future_expires) { Fabricate :invite, expires_at: 2.days.from_now }
|
|
|
|
it 'returns future and non-epiring records' do
|
|
expect(described_class.available)
|
|
.to include(no_expires, future_expires)
|
|
.and not_include(past_expires)
|
|
end
|
|
end
|
|
end
|
|
|
|
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)
|
|
invite.user.account.suspend!
|
|
expect(invite.valid_for_use?).to be false
|
|
end
|
|
end
|
|
|
|
describe 'Callbacks' do
|
|
describe 'Setting the invite code' do
|
|
context 'when creating a new record' do
|
|
subject { Fabricate.build :invite }
|
|
|
|
it 'sets a code value' do
|
|
expect { subject.save }
|
|
.to change(subject, :code).from(be_blank).to(be_present)
|
|
end
|
|
end
|
|
|
|
context 'when updating a record' do
|
|
subject { Fabricate :invite }
|
|
|
|
it 'does not change the code value' do
|
|
expect { subject.update(max_uses: 123_456) }
|
|
.to not_change(subject, :code)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|