instance_presenter_spec.rb 2.9 KB

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