From 59da591d13e666f5426b72fd4079530c886d9657 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 5 Apr 2024 04:54:11 -0400 Subject: [PATCH] Improve spec for dimension/languages admin metric (#29842) --- .../dimension/languages_dimension_spec.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/lib/admin/metrics/dimension/languages_dimension_spec.rb b/spec/lib/admin/metrics/dimension/languages_dimension_spec.rb index 1722c4c616..9d80970693 100644 --- a/spec/lib/admin/metrics/dimension/languages_dimension_spec.rb +++ b/spec/lib/admin/metrics/dimension/languages_dimension_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Admin::Metrics::Dimension::LanguagesDimension do - subject(:dimension) { described_class.new(start_at, end_at, limit, params) } + subject { described_class.new(start_at, end_at, limit, params) } let(:start_at) { 2.days.ago } let(:end_at) { Time.now.utc } @@ -11,8 +11,21 @@ describe Admin::Metrics::Dimension::LanguagesDimension do let(:params) { ActionController::Parameters.new } describe '#data' do - it 'runs data query without error' do - expect { dimension.data }.to_not raise_error + let(:alice) { Fabricate(:user, locale: 'en', current_sign_in_at: 1.day.ago) } + let(:bob) { Fabricate(:user, locale: 'en', current_sign_in_at: 30.days.ago) } + + before do + alice.update(current_sign_in_at: 1.day.ago) + bob.update(current_sign_in_at: 30.days.ago) + end + + it 'returns locales with sign in counts' do + expect(subject.data.size) + .to eq(1) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(key: 'en', value: '1') + ) end end end