You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.3 KiB

  1. require 'rails_helper'
  2. describe InstancePresenter do
  3. let(:instance_presenter) { InstancePresenter.new }
  4. context do
  5. around do |example|
  6. site_description = Setting.site_description
  7. example.run
  8. Setting.site_description = site_description
  9. end
  10. it "delegates site_description to Setting" do
  11. Setting.site_description = "Site desc"
  12. expect(instance_presenter.site_description).to eq "Site desc"
  13. end
  14. end
  15. context 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.site_extended_description).to eq "Extended desc"
  24. end
  25. end
  26. context do
  27. around do |example|
  28. open_registrations = Setting.open_registrations
  29. example.run
  30. Setting.open_registrations = open_registrations
  31. end
  32. it "delegates open_registrations to Setting" do
  33. Setting.open_registrations = false
  34. expect(instance_presenter.open_registrations).to eq false
  35. end
  36. end
  37. context do
  38. around do |example|
  39. closed_registrations_message = Setting.closed_registrations_message
  40. example.run
  41. Setting.closed_registrations_message = closed_registrations_message
  42. end
  43. it "delegates closed_registrations_message to Setting" do
  44. Setting.closed_registrations_message = "Closed message"
  45. expect(instance_presenter.closed_registrations_message).to eq "Closed message"
  46. end
  47. end
  48. context do
  49. around do |example|
  50. site_contact_email = Setting.site_contact_email
  51. example.run
  52. Setting.site_contact_email = site_contact_email
  53. end
  54. it "delegates contact_email to Setting" do
  55. Setting.site_contact_email = "admin@example.com"
  56. expect(instance_presenter.site_contact_email).to eq "admin@example.com"
  57. end
  58. end
  59. describe "contact_account" do
  60. around do |example|
  61. site_contact_username = Setting.site_contact_username
  62. example.run
  63. Setting.site_contact_username = site_contact_username
  64. end
  65. it "returns the account for the site contact username" do
  66. Setting.site_contact_username = "aaa"
  67. account = Fabricate(:account, username: "aaa")
  68. expect(instance_presenter.contact_account).to eq(account)
  69. end
  70. end
  71. describe "user_count" do
  72. it "returns the number of site users" do
  73. cache = double
  74. allow(Rails).to receive(:cache).and_return(cache)
  75. allow(cache).to receive(:fetch).with("user_count").and_return(123)
  76. expect(instance_presenter.user_count).to eq(123)
  77. end
  78. end
  79. describe "status_count" do
  80. it "returns the number of local statuses" do
  81. cache = double
  82. allow(Rails).to receive(:cache).and_return(cache)
  83. allow(cache).to receive(:fetch).with("local_status_count").and_return(234)
  84. expect(instance_presenter.status_count).to eq(234)
  85. end
  86. end
  87. describe "domain_count" do
  88. it "returns the number of known domains" do
  89. cache = double
  90. allow(Rails).to receive(:cache).and_return(cache)
  91. allow(cache).to receive(:fetch).with("distinct_domain_count").and_return(345)
  92. expect(instance_presenter.domain_count).to eq(345)
  93. end
  94. end
  95. end