instance_accounts_measure_spec.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::Metrics::Measure::InstanceAccountsMeasure 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. Fabricate(:account, domain: domain, created_at: 1.year.ago)
  11. Fabricate(:account, domain: domain, created_at: 1.month.ago)
  12. Fabricate(:account, domain: domain)
  13. Fabricate(:account, domain: "foo.#{domain}", created_at: 1.year.ago)
  14. Fabricate(:account, domain: "foo.#{domain}")
  15. Fabricate(:account, domain: "bar.#{domain}")
  16. end
  17. describe 'total' do
  18. context 'without include_subdomains' do
  19. it 'returns the expected number of accounts' do
  20. expect(measure.total).to eq 3
  21. end
  22. end
  23. context 'with include_subdomains' do
  24. let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') }
  25. it 'returns the expected number of accounts' do
  26. expect(measure.total).to eq 6
  27. end
  28. end
  29. end
  30. describe '#data' do
  31. it 'runs data query without error' do
  32. expect { measure.data }.to_not raise_error
  33. end
  34. end
  35. end