1
0

instance_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Instance do
  4. describe 'Scopes' do
  5. before { described_class.refresh }
  6. describe '#searchable' do
  7. let(:expected_domain) { 'host.example' }
  8. let(:blocked_domain) { 'other.example' }
  9. before do
  10. Fabricate :account, domain: expected_domain
  11. Fabricate :account, domain: blocked_domain
  12. Fabricate :domain_block, domain: blocked_domain
  13. end
  14. it 'returns records not domain blocked' do
  15. results = described_class.searchable.pluck(:domain)
  16. expect(results)
  17. .to include(expected_domain)
  18. .and not_include(blocked_domain)
  19. end
  20. end
  21. describe '#matches_domain' do
  22. let(:host_domain) { 'host.example.com' }
  23. let(:host_under_domain) { 'host_under.example.com' }
  24. let(:other_domain) { 'other.example' }
  25. before do
  26. Fabricate :account, domain: host_domain
  27. Fabricate :account, domain: host_under_domain
  28. Fabricate :account, domain: other_domain
  29. end
  30. it 'returns matching records' do
  31. expect(described_class.matches_domain('host.exa').pluck(:domain))
  32. .to include(host_domain)
  33. .and not_include(other_domain)
  34. expect(described_class.matches_domain('ple.com').pluck(:domain))
  35. .to include(host_domain)
  36. .and not_include(other_domain)
  37. expect(described_class.matches_domain('example').pluck(:domain))
  38. .to include(host_domain)
  39. .and include(other_domain)
  40. expect(described_class.matches_domain('host_').pluck(:domain)) # Preserve SQL wildcards
  41. .to include(host_domain)
  42. .and include(host_under_domain)
  43. .and not_include(other_domain)
  44. end
  45. end
  46. describe '#by_domain_and_subdomains' do
  47. let(:exact_match_domain) { 'example.com' }
  48. let(:subdomain_domain) { 'foo.example.com' }
  49. let(:partial_domain) { 'grexample.com' }
  50. before do
  51. Fabricate(:account, domain: exact_match_domain)
  52. Fabricate(:account, domain: subdomain_domain)
  53. Fabricate(:account, domain: partial_domain)
  54. end
  55. it 'returns matching instances' do
  56. results = described_class.by_domain_and_subdomains('example.com').pluck(:domain)
  57. expect(results)
  58. .to include(exact_match_domain)
  59. .and include(subdomain_domain)
  60. .and not_include(partial_domain)
  61. end
  62. end
  63. describe '#with_domain_follows' do
  64. let(:example_domain) { 'example.host' }
  65. let(:other_domain) { 'other.host' }
  66. let(:none_domain) { 'none.host' }
  67. before do
  68. example_account = Fabricate(:account, domain: example_domain)
  69. other_account = Fabricate(:account, domain: other_domain)
  70. Fabricate(:account, domain: none_domain)
  71. Fabricate :follow, account: example_account
  72. Fabricate :follow, target_account: other_account
  73. end
  74. it 'returns instances with domain accounts that have follows' do
  75. results = described_class.with_domain_follows(['example.host', 'other.host', 'none.host']).pluck(:domain)
  76. expect(results)
  77. .to include(example_domain)
  78. .and include(other_domain)
  79. .and not_include(none_domain)
  80. end
  81. end
  82. end
  83. end