instance_presenter_spec.rb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe InstancePresenter do
  4. let(:instance_presenter) { described_class.new }
  5. describe '#description' do
  6. it 'delegates site_description to Setting' do
  7. Setting.site_short_description = 'Site desc'
  8. expect(instance_presenter.description).to eq 'Site desc'
  9. end
  10. end
  11. describe '#extended_description' do
  12. it 'delegates site_extended_description to Setting' do
  13. Setting.site_extended_description = 'Extended desc'
  14. expect(instance_presenter.extended_description).to eq 'Extended desc'
  15. end
  16. end
  17. describe '#email' do
  18. it 'delegates contact_email to Setting' do
  19. Setting.site_contact_email = 'admin@example.com'
  20. expect(instance_presenter.contact.email).to eq 'admin@example.com'
  21. end
  22. end
  23. describe '#account' do
  24. it 'returns the account for the site contact username' do
  25. Setting.site_contact_username = 'aaa'
  26. account = Fabricate(:account, username: 'aaa')
  27. expect(instance_presenter.contact.account).to eq(account)
  28. end
  29. end
  30. describe '#user_count' do
  31. it 'returns the number of site users' do
  32. Rails.cache.write 'user_count', 123
  33. expect(instance_presenter.user_count).to eq(123)
  34. end
  35. end
  36. describe '#status_count' do
  37. it 'returns the number of local statuses' do
  38. Rails.cache.write 'local_status_count', 234
  39. expect(instance_presenter.status_count).to eq(234)
  40. end
  41. end
  42. describe '#domain_count' do
  43. it 'returns the number of known domains' do
  44. Rails.cache.write 'distinct_domain_count', 345
  45. expect(instance_presenter.domain_count).to eq(345)
  46. end
  47. end
  48. describe '#version' do
  49. it 'returns string' do
  50. expect(instance_presenter.version).to be_a String
  51. end
  52. end
  53. describe '#source_url' do
  54. context 'with the GITHUB_REPOSITORY env variable set' do
  55. around do |example|
  56. ClimateControl.modify GITHUB_REPOSITORY: 'other/repo' do
  57. example.run
  58. end
  59. end
  60. it 'uses the env variable to build a repo URL' do
  61. expect(instance_presenter.source_url).to eq('https://github.com/other/repo')
  62. end
  63. end
  64. context 'without the GITHUB_REPOSITORY env variable set' do
  65. around do |example|
  66. ClimateControl.modify GITHUB_REPOSITORY: nil do
  67. example.run
  68. end
  69. end
  70. it 'defaults to the core mastodon repo URL' do
  71. expect(instance_presenter.source_url).to eq('https://github.com/mastodon/mastodon')
  72. end
  73. end
  74. end
  75. describe '#thumbnail' do
  76. it 'returns SiteUpload' do
  77. thumbnail = Fabricate(:site_upload, var: 'thumbnail')
  78. expect(instance_presenter.thumbnail).to eq(thumbnail)
  79. end
  80. end
  81. describe '#mascot' do
  82. it 'returns SiteUpload' do
  83. mascot = Fabricate(:site_upload, var: 'mascot')
  84. expect(instance_presenter.mascot).to eq(mascot)
  85. end
  86. end
  87. end