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