Commit 49165cd5 authored by charlie ablett's avatar charlie ablett

Merge branch 'fix-ci-minutes-usage-times' into 'master'

Ensure use of UTC timezone when counting CI Minutes

See merge request gitlab-org/gitlab!55191
parents 19cd6a64 c6561fa7
......@@ -9,7 +9,11 @@ module Ci
belongs_to :namespace
scope :current_month, -> { where(date: Time.current.utc.beginning_of_month) }
scope :current_month, -> { where(date: beginning_of_month) }
def self.beginning_of_month(time = Time.current)
time.utc.beginning_of_month
end
# We should pretty much always use this method to access data for the current month
# since this will lazily create an entry if it doesn't exist.
......
......@@ -9,7 +9,11 @@ module Ci
belongs_to :project
scope :current_month, -> { where(date: Time.current.beginning_of_month) }
scope :current_month, -> { where(date: beginning_of_month) }
def self.beginning_of_month(time = Time.current)
time.utc.beginning_of_month
end
# We should pretty much always use this method to access data for the current month
# since this will lazily create an entry if it doesn't exist.
......
......@@ -16,7 +16,7 @@ RSpec.describe Ci::Minutes::NamespaceMonthlyUsage do
end
it 'does not raise exception if unique index is not violated' do
expect { create(:ci_namespace_monthly_usage, namespace: namespace, date: 1.month.ago.utc.beginning_of_month) }
expect { create(:ci_namespace_monthly_usage, namespace: namespace, date: described_class.beginning_of_month(1.month.ago)) }
.to change { described_class.count }.by(1)
end
end
......@@ -31,7 +31,7 @@ RSpec.describe Ci::Minutes::NamespaceMonthlyUsage do
expect(subject.amount_used).to eq(0)
expect(subject.namespace).to eq(namespace)
expect(subject.date).to eq(Time.current.beginning_of_month)
expect(subject.date).to eq(described_class.beginning_of_month)
end
end
end
......@@ -42,7 +42,7 @@ RSpec.describe Ci::Minutes::NamespaceMonthlyUsage do
context 'when namespace usage exists for previous months' do
before do
create(:ci_namespace_monthly_usage, namespace: namespace, date: 2.months.ago.utc.beginning_of_month)
create(:ci_namespace_monthly_usage, namespace: namespace, date: described_class.beginning_of_month(2.months.ago))
end
it_behaves_like 'creates usage record'
......
......@@ -16,7 +16,7 @@ RSpec.describe Ci::Minutes::ProjectMonthlyUsage do
end
it 'does not raise exception if unique index is not violated' do
expect { create(:ci_project_monthly_usage, project: project, date: 1.month.ago.utc.beginning_of_month) }
expect { create(:ci_project_monthly_usage, project: project, date: described_class.beginning_of_month(1.month.ago)) }
.to change { described_class.count }.by(1)
end
end
......@@ -31,7 +31,7 @@ RSpec.describe Ci::Minutes::ProjectMonthlyUsage do
expect(subject.amount_used).to eq(0)
expect(subject.project).to eq(project)
expect(subject.date).to eq(Time.current.beginning_of_month)
expect(subject.date).to eq(described_class.beginning_of_month)
end
end
end
......@@ -42,7 +42,7 @@ RSpec.describe Ci::Minutes::ProjectMonthlyUsage do
context 'when project usage exists for previous months' do
before do
create(:ci_project_monthly_usage, project: project, date: 2.months.ago.utc.beginning_of_month)
create(:ci_project_monthly_usage, project: project, date: described_class.beginning_of_month(2.months.ago))
end
it_behaves_like 'creates usage record'
......
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