2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-09 22:47:25 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 15:12:25 +10:00
|
|
|
RSpec.describe InstancePresenter do
|
2023-03-16 21:07:24 +11:00
|
|
|
let(:instance_presenter) { described_class.new }
|
2017-04-09 22:47:25 +10:00
|
|
|
|
2022-10-05 12:47:56 +11:00
|
|
|
describe '#description' do
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'delegates site_description to Setting' do
|
|
|
|
Setting.site_short_description = 'Site desc'
|
|
|
|
expect(instance_presenter.description).to eq 'Site desc'
|
2017-05-30 23:03:35 +10:00
|
|
|
end
|
2017-04-09 22:47:25 +10:00
|
|
|
end
|
|
|
|
|
2022-10-05 12:47:56 +11:00
|
|
|
describe '#extended_description' do
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'delegates site_extended_description to Setting' do
|
|
|
|
Setting.site_extended_description = 'Extended desc'
|
|
|
|
expect(instance_presenter.extended_description).to eq 'Extended desc'
|
2017-05-30 23:03:35 +10:00
|
|
|
end
|
2017-04-09 22:47:25 +10:00
|
|
|
end
|
|
|
|
|
2022-10-05 12:47:56 +11:00
|
|
|
describe '#email' do
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'delegates contact_email to Setting' do
|
|
|
|
Setting.site_contact_email = 'admin@example.com'
|
|
|
|
expect(instance_presenter.contact.email).to eq 'admin@example.com'
|
2017-05-30 23:03:35 +10:00
|
|
|
end
|
2017-04-09 22:47:25 +10:00
|
|
|
end
|
|
|
|
|
2022-10-05 12:47:56 +11:00
|
|
|
describe '#account' do
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'returns the account for the site contact username' do
|
|
|
|
Setting.site_contact_username = 'aaa'
|
|
|
|
account = Fabricate(:account, username: 'aaa')
|
2022-10-05 12:47:56 +11:00
|
|
|
expect(instance_presenter.contact.account).to eq(account)
|
2017-04-09 22:47:25 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-05 12:47:56 +11:00
|
|
|
describe '#user_count' do
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'returns the number of site users' do
|
2018-02-18 08:35:05 +11:00
|
|
|
Rails.cache.write 'user_count', 123
|
2017-04-09 22:47:25 +10:00
|
|
|
|
|
|
|
expect(instance_presenter.user_count).to eq(123)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-05 12:47:56 +11:00
|
|
|
describe '#status_count' do
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'returns the number of local statuses' do
|
2018-02-18 08:35:05 +11:00
|
|
|
Rails.cache.write 'local_status_count', 234
|
2017-04-09 22:47:25 +10:00
|
|
|
|
|
|
|
expect(instance_presenter.status_count).to eq(234)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-05 12:47:56 +11:00
|
|
|
describe '#domain_count' do
|
2023-02-19 09:38:14 +11:00
|
|
|
it 'returns the number of known domains' do
|
2018-02-18 08:35:05 +11:00
|
|
|
Rails.cache.write 'distinct_domain_count', 345
|
2017-04-09 22:47:25 +10:00
|
|
|
|
|
|
|
expect(instance_presenter.domain_count).to eq(345)
|
|
|
|
end
|
|
|
|
end
|
2018-12-21 18:59:56 +11:00
|
|
|
|
2022-10-05 12:47:56 +11:00
|
|
|
describe '#version' do
|
|
|
|
it 'returns string' do
|
|
|
|
expect(instance_presenter.version).to be_a String
|
2018-12-21 18:59:56 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#source_url' do
|
2023-03-10 00:27:48 +11:00
|
|
|
context 'with the GITHUB_REPOSITORY env variable set' do
|
|
|
|
around do |example|
|
|
|
|
ClimateControl.modify GITHUB_REPOSITORY: 'other/repo' do
|
|
|
|
example.run
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses the env variable to build a repo URL' do
|
|
|
|
expect(instance_presenter.source_url).to eq('https://github.com/other/repo')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without the GITHUB_REPOSITORY env variable set' do
|
|
|
|
around do |example|
|
|
|
|
ClimateControl.modify GITHUB_REPOSITORY: nil do
|
|
|
|
example.run
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults to the core mastodon repo URL' do
|
|
|
|
expect(instance_presenter.source_url).to eq('https://github.com/mastodon/mastodon')
|
|
|
|
end
|
2018-12-21 18:59:56 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#thumbnail' do
|
|
|
|
it 'returns SiteUpload' do
|
|
|
|
thumbnail = Fabricate(:site_upload, var: 'thumbnail')
|
|
|
|
expect(instance_presenter.thumbnail).to eq(thumbnail)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#mascot' do
|
|
|
|
it 'returns SiteUpload' do
|
|
|
|
mascot = Fabricate(:site_upload, var: 'mascot')
|
|
|
|
expect(instance_presenter.mascot).to eq(mascot)
|
|
|
|
end
|
|
|
|
end
|
2017-04-09 22:47:25 +10:00
|
|
|
end
|