2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-09 14:47:25 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe InstancePresenter do
|
2023-03-16 11:07:24 +01:00
|
|
|
let(:instance_presenter) { described_class.new }
|
2017-04-09 14:47:25 +02:00
|
|
|
|
2022-10-05 03:47:56 +02:00
|
|
|
describe '#description' do
|
2023-02-18 23:38:14 +01: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 15:03:35 +02:00
|
|
|
end
|
2017-04-09 14:47:25 +02:00
|
|
|
end
|
|
|
|
|
2022-10-05 03:47:56 +02:00
|
|
|
describe '#extended_description' do
|
2023-02-18 23:38:14 +01: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 15:03:35 +02:00
|
|
|
end
|
2017-04-09 14:47:25 +02:00
|
|
|
end
|
|
|
|
|
2022-10-05 03:47:56 +02:00
|
|
|
describe '#email' do
|
2023-02-18 23:38:14 +01: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 15:03:35 +02:00
|
|
|
end
|
2017-04-09 14:47:25 +02:00
|
|
|
end
|
|
|
|
|
2022-10-05 03:47:56 +02:00
|
|
|
describe '#account' do
|
2023-02-18 23:38:14 +01:00
|
|
|
it 'returns the account for the site contact username' do
|
|
|
|
Setting.site_contact_username = 'aaa'
|
|
|
|
account = Fabricate(:account, username: 'aaa')
|
2022-10-05 03:47:56 +02:00
|
|
|
expect(instance_presenter.contact.account).to eq(account)
|
2017-04-09 14:47:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-05 03:47:56 +02:00
|
|
|
describe '#user_count' do
|
2023-02-18 23:38:14 +01:00
|
|
|
it 'returns the number of site users' do
|
2018-02-17 22:35:05 +01:00
|
|
|
Rails.cache.write 'user_count', 123
|
2017-04-09 14:47:25 +02:00
|
|
|
|
|
|
|
expect(instance_presenter.user_count).to eq(123)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-05 03:47:56 +02:00
|
|
|
describe '#status_count' do
|
2023-02-18 23:38:14 +01:00
|
|
|
it 'returns the number of local statuses' do
|
2018-02-17 22:35:05 +01:00
|
|
|
Rails.cache.write 'local_status_count', 234
|
2017-04-09 14:47:25 +02:00
|
|
|
|
|
|
|
expect(instance_presenter.status_count).to eq(234)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-05 03:47:56 +02:00
|
|
|
describe '#domain_count' do
|
2023-02-18 23:38:14 +01:00
|
|
|
it 'returns the number of known domains' do
|
2018-02-17 22:35:05 +01:00
|
|
|
Rails.cache.write 'distinct_domain_count', 345
|
2017-04-09 14:47:25 +02:00
|
|
|
|
|
|
|
expect(instance_presenter.domain_count).to eq(345)
|
|
|
|
end
|
|
|
|
end
|
2018-12-21 08:59:56 +01:00
|
|
|
|
2022-10-05 03:47:56 +02:00
|
|
|
describe '#version' do
|
|
|
|
it 'returns string' do
|
|
|
|
expect(instance_presenter.version).to be_a String
|
2018-12-21 08:59:56 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#source_url' do
|
2023-03-09 14:27:48 +01: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 08:59:56 +01: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 14:47:25 +02:00
|
|
|
end
|