mastodon/spec/models/instance_spec.rb
Emelia Smith 72f2f35bfb
Some checks failed
Check i18n / check-i18n (push) Waiting to run
Chromatic / Run Chromatic (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (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
Ruby Linting / lint (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 / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick 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
Implement Instance Moderation Notes (#31529)
2025-06-25 08:15:44 +00:00

105 lines
3.2 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Instance do
before { described_class.refresh }
describe 'Scopes' do
describe '#searchable' do
let(:expected_domain) { 'host.example' }
let(:blocked_domain) { 'other.example' }
before do
Fabricate :account, domain: expected_domain
Fabricate :account, domain: blocked_domain
Fabricate :domain_block, domain: blocked_domain
end
it 'returns records not domain blocked' do
results = described_class.searchable.pluck(:domain)
expect(results)
.to include(expected_domain)
.and not_include(blocked_domain)
end
end
describe '#matches_domain' do
let(:host_domain) { 'host.example.com' }
let(:host_under_domain) { 'host_under.example.com' }
let(:other_domain) { 'other.example' }
before do
Fabricate :account, domain: host_domain
Fabricate :account, domain: host_under_domain
Fabricate :account, domain: other_domain
end
it 'returns matching records' do
expect(described_class.matches_domain('host.exa').pluck(:domain))
.to include(host_domain)
.and not_include(other_domain)
expect(described_class.matches_domain('ple.com').pluck(:domain))
.to include(host_domain)
.and not_include(other_domain)
expect(described_class.matches_domain('example').pluck(:domain))
.to include(host_domain)
.and include(other_domain)
expect(described_class.matches_domain('host_').pluck(:domain)) # Preserve SQL wildcards
.to include(host_domain)
.and include(host_under_domain)
.and not_include(other_domain)
end
end
describe '#by_domain_and_subdomains' do
let(:exact_match_domain) { 'example.com' }
let(:subdomain_domain) { 'foo.example.com' }
let(:partial_domain) { 'grexample.com' }
before do
Fabricate(:account, domain: exact_match_domain)
Fabricate(:account, domain: subdomain_domain)
Fabricate(:account, domain: partial_domain)
end
it 'returns matching instances' do
results = described_class.by_domain_and_subdomains('example.com').pluck(:domain)
expect(results)
.to include(exact_match_domain)
.and include(subdomain_domain)
.and not_include(partial_domain)
end
end
describe '#with_domain_follows' do
let(:example_domain) { 'example.host' }
let(:other_domain) { 'other.host' }
let(:none_domain) { 'none.host' }
before do
example_account = Fabricate(:account, domain: example_domain)
other_account = Fabricate(:account, domain: other_domain)
Fabricate(:account, domain: none_domain)
Fabricate :follow, account: example_account
Fabricate :follow, target_account: other_account
end
it 'returns instances with domain accounts that have follows' do
results = described_class.with_domain_follows(['example.host', 'other.host', 'none.host']).pluck(:domain)
expect(results)
.to include(example_domain)
.and include(other_domain)
.and not_include(none_domain)
end
end
end
end