instance_follows_measure_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::Metrics::Measure::InstanceFollowsMeasure do
  4. subject(:measure) { described_class.new(start_at, end_at, params) }
  5. let(:domain) { 'example.com' }
  6. let(:start_at) { 2.days.ago }
  7. let(:end_at) { Time.now.utc }
  8. let(:params) { ActionController::Parameters.new(domain: domain) }
  9. before do
  10. local_account = Fabricate(:account)
  11. local_account.follow!(Fabricate(:account, domain: domain))
  12. local_account.follow!(Fabricate(:account, domain: domain))
  13. Fabricate(:account, domain: domain)
  14. local_account.follow!(Fabricate(:account, domain: "foo.#{domain}"))
  15. local_account.follow!(Fabricate(:account, domain: "foo.#{domain}"))
  16. Fabricate(:account, domain: "bar.#{domain}")
  17. end
  18. describe 'total' do
  19. context 'without include_subdomains' do
  20. it 'returns the expected number of accounts' do
  21. expect(measure.total).to eq 2
  22. end
  23. end
  24. context 'with include_subdomains' do
  25. let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') }
  26. it 'returns the expected number of accounts' do
  27. expect(measure.total).to eq 4
  28. end
  29. end
  30. end
  31. describe '#data' do
  32. it 'runs data query without error' do
  33. expect { measure.data }.to_not raise_error
  34. end
  35. end
  36. end