instance_presenter_spec.rb 3.5 KB

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