Commit abec9d3d authored by Stan Hu's avatar Stan Hu

Merge branch...

Merge branch 'rd-8292-maximum-historical-users-should-be-based-on-a-license-s-start-date-not-1-year' into 'master'

Fix query used to calculate number of users over license

Closes #8292

See merge request gitlab-org/gitlab-ee!10556
parents 8894b3c5 f1929bf7
......@@ -22,7 +22,9 @@ class HistoricalData < ApplicationRecord
end
def max_historical_user_count
HistoricalData.during(1.year.ago..Date.today).maximum(:active_user_count) || 0
exp_date = License.current&.expires_at || Date.today
HistoricalData.during(exp_date.ago(1.year)..exp_date).maximum(:active_user_count) || 0
end
end
end
---
title: Fix query used to calculate number of users over license
merge_request: 10556
author:
type: fixed
......@@ -76,4 +76,39 @@ describe HistoricalData do
end
end
end
describe '.max_historical_user_count with data outside of the license period' do
let!(:license) { create(:license) }
context 'with stats before the license period' do
before do
described_class.create!(date: license.starts_at.ago(2.days), active_user_count: 10)
end
it 'ignore those records' do
expect(described_class.max_historical_user_count).to eq(0)
end
end
context 'with stats after the license period' do
before do
described_class.create!(date: license.expires_at.in(2.days), active_user_count: 10)
end
it 'ignore those records' do
expect(described_class.max_historical_user_count).to eq(0)
end
end
context 'with stats inside license period' do
before do
described_class.create!(date: license.starts_at.in(2.days), active_user_count: 10)
described_class.create!(date: license.starts_at.in(5.days), active_user_count: 15)
end
it 'returns max value for active_user_count' do
expect(described_class.max_historical_user_count).to eq(15)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment