Commit 2d5328ed authored by Sean Arnold's avatar Sean Arnold Committed by Stan Hu

More Time usages fixes for /models

Using cop to find offences
parent 2b467078
...@@ -141,7 +141,7 @@ class PagesDomain < ApplicationRecord ...@@ -141,7 +141,7 @@ class PagesDomain < ApplicationRecord
def expired? def expired?
return false unless x509 return false unless x509
current = Time.new current = Time.current
current < x509.not_before || x509.not_after < current current < x509.not_before || x509.not_after < current
end end
......
...@@ -300,7 +300,7 @@ class GeoNodeStatus < ApplicationRecord ...@@ -300,7 +300,7 @@ class GeoNodeStatus < ApplicationRecord
end end
def attribute_timestamp=(attr, value) def attribute_timestamp=(attr, value)
self[attr] = Time.at(value) self[attr] = Time.zone.at(value)
end end
def self.percentage_methods def self.percentage_methods
......
...@@ -1114,7 +1114,7 @@ describe GeoNodeStatus, :geo, :geo_fdw do ...@@ -1114,7 +1114,7 @@ describe GeoNodeStatus, :geo, :geo_fdw do
expect(result.id).to be_nil expect(result.id).to be_nil
expect(result.attachments_count).to eq(status.attachments_count) expect(result.attachments_count).to eq(status.attachments_count)
expect(result.cursor_last_event_date).to eq(Time.at(status.cursor_last_event_timestamp)) expect(result.cursor_last_event_date).to eq(Time.zone.at(status.cursor_last_event_timestamp))
expect(result.storage_shards.count).to eq(Settings.repositories.storages.count) expect(result.storage_shards.count).to eq(Settings.repositories.storages.count)
end end
end end
......
...@@ -118,7 +118,7 @@ describe Ci::PipelineSchedule do ...@@ -118,7 +118,7 @@ describe Ci::PipelineSchedule do
let(:pipeline_schedule) { create(:ci_pipeline_schedule, :every_minute) } let(:pipeline_schedule) { create(:ci_pipeline_schedule, :every_minute) }
it "updates next_run_at to the sidekiq worker's execution time" do it "updates next_run_at to the sidekiq worker's execution time" do
Timecop.freeze(Time.parse("2019-06-01 12:18:00+0000")) do Timecop.freeze(Time.zone.parse("2019-06-01 12:18:00+0000")) do
expect(pipeline_schedule.next_run_at).to eq(cron_worker_next_run_at) expect(pipeline_schedule.next_run_at).to eq(cron_worker_next_run_at)
end end
end end
......
...@@ -708,7 +708,7 @@ describe CommitStatus do ...@@ -708,7 +708,7 @@ describe CommitStatus do
end end
describe '#enqueue' do describe '#enqueue' do
let!(:current_time) { Time.new(2018, 4, 5, 14, 0, 0) } let!(:current_time) { Time.zone.local(2018, 4, 5, 14, 0, 0) }
before do before do
allow(Time).to receive(:now).and_return(current_time) allow(Time).to receive(:now).and_return(current_time)
......
...@@ -91,7 +91,7 @@ describe Sortable do ...@@ -91,7 +91,7 @@ describe Sortable do
Group.all.order_by(order).map(&:name) Group.all.order_by(order).map(&:name)
end end
let!(:ref_time) { Time.parse('2018-05-01 00:00:00') } let!(:ref_time) { Time.zone.parse('2018-05-01 00:00:00') }
let!(:group1) { create(:group, name: 'aa', id: 1, created_at: ref_time - 15.seconds, updated_at: ref_time) } let!(:group1) { create(:group, name: 'aa', id: 1, created_at: ref_time - 15.seconds, updated_at: ref_time) }
let!(:group2) { create(:group, name: 'AAA', id: 2, created_at: ref_time - 10.seconds, updated_at: ref_time - 5.seconds) } let!(:group2) { create(:group, name: 'AAA', id: 2, created_at: ref_time - 10.seconds, updated_at: ref_time - 5.seconds) }
let!(:group3) { create(:group, name: 'BB', id: 3, created_at: ref_time - 5.seconds, updated_at: ref_time - 10.seconds) } let!(:group3) { create(:group, name: 'BB', id: 3, created_at: ref_time - 5.seconds, updated_at: ref_time - 10.seconds) }
......
...@@ -994,7 +994,7 @@ describe Issue do ...@@ -994,7 +994,7 @@ describe Issue do
it_behaves_like 'versioned description' it_behaves_like 'versioned description'
describe "#previous_updated_at" do describe "#previous_updated_at" do
let_it_be(:updated_at) { Time.new(2012, 01, 06) } let_it_be(:updated_at) { Time.zone.local(2012, 01, 06) }
let_it_be(:issue) { create(:issue, updated_at: updated_at) } let_it_be(:issue) { create(:issue, updated_at: updated_at) }
it 'returns updated_at value if updated_at did not change at all' do it 'returns updated_at value if updated_at did not change at all' do
...@@ -1010,15 +1010,15 @@ describe Issue do ...@@ -1010,15 +1010,15 @@ describe Issue do
end end
it 'returns updated_at value if previous updated_at value is not present' do it 'returns updated_at value if previous updated_at value is not present' do
allow(issue).to receive(:previous_changes).and_return({ 'updated_at' => [nil, Time.new(2013, 02, 06)] }) allow(issue).to receive(:previous_changes).and_return({ 'updated_at' => [nil, Time.zone.local(2013, 02, 06)] })
expect(issue.previous_updated_at).to eq(updated_at) expect(issue.previous_updated_at).to eq(updated_at)
end end
it 'returns previous updated_at when present' do it 'returns previous updated_at when present' do
allow(issue).to receive(:previous_changes).and_return({ 'updated_at' => [Time.new(2013, 02, 06), Time.new(2013, 03, 06)] }) allow(issue).to receive(:previous_changes).and_return({ 'updated_at' => [Time.zone.local(2013, 02, 06), Time.zone.local(2013, 03, 06)] })
expect(issue.previous_updated_at).to eq(Time.new(2013, 02, 06)) expect(issue.previous_updated_at).to eq(Time.zone.local(2013, 02, 06))
end end
end end
......
...@@ -62,7 +62,7 @@ describe Iteration do ...@@ -62,7 +62,7 @@ describe Iteration do
end end
context 'when end_date is in range' do context 'when end_date is in range' do
let(:start_date) { Time.now } let(:start_date) { Time.current }
let(:due_date) { 6.days.from_now } let(:due_date) { 6.days.from_now }
it 'is not valid' do it 'is not valid' do
...@@ -94,7 +94,7 @@ describe Iteration do ...@@ -94,7 +94,7 @@ describe Iteration do
describe '#future_date' do describe '#future_date' do
context 'when dates are in the future' do context 'when dates are in the future' do
let(:start_date) { Time.now } let(:start_date) { Time.current }
let(:due_date) { 1.week.from_now } let(:due_date) { 1.week.from_now }
it { is_expected.to be_valid } it { is_expected.to be_valid }
...@@ -111,7 +111,7 @@ describe Iteration do ...@@ -111,7 +111,7 @@ describe Iteration do
end end
context 'when due_date is in the past' do context 'when due_date is in the past' do
let(:start_date) { Time.now } let(:start_date) { Time.current }
let(:due_date) { 1.week.ago } let(:due_date) { 1.week.ago }
it 'is not valid' do it 'is not valid' do
...@@ -122,7 +122,7 @@ describe Iteration do ...@@ -122,7 +122,7 @@ describe Iteration do
context 'when start_date is over 500 years in the future' do context 'when start_date is over 500 years in the future' do
let(:start_date) { 501.years.from_now } let(:start_date) { 501.years.from_now }
let(:due_date) { Time.now } let(:due_date) { Time.current }
it 'is not valid' do it 'is not valid' do
expect(subject).not_to be_valid expect(subject).not_to be_valid
...@@ -131,7 +131,7 @@ describe Iteration do ...@@ -131,7 +131,7 @@ describe Iteration do
end end
context 'when due_date is over 500 years in the future' do context 'when due_date is over 500 years in the future' do
let(:start_date) { Time.now } let(:start_date) { Time.current }
let(:due_date) { 501.years.from_now } let(:due_date) { 501.years.from_now }
it 'is not valid' do it 'is not valid' do
...@@ -143,7 +143,7 @@ describe Iteration do ...@@ -143,7 +143,7 @@ describe Iteration do
end end
describe '.within_timeframe' do describe '.within_timeframe' do
let_it_be(:now) { Time.now } let_it_be(:now) { Time.current }
let_it_be(:project) { create(:project, :empty_repo) } let_it_be(:project) { create(:project, :empty_repo) }
let_it_be(:iteration_1) { create(:iteration, project: project, start_date: now, due_date: 1.day.from_now) } let_it_be(:iteration_1) { create(:iteration, project: project, start_date: now, due_date: 1.day.from_now) }
let_it_be(:iteration_2) { create(:iteration, project: project, start_date: 2.days.from_now, due_date: 3.days.from_now) } let_it_be(:iteration_2) { create(:iteration, project: project, start_date: 2.days.from_now, due_date: 3.days.from_now) }
......
...@@ -73,7 +73,7 @@ describe MergeRequestDiffCommit do ...@@ -73,7 +73,7 @@ describe MergeRequestDiffCommit do
# This commit's date is "Sun Aug 17 07:12:55 292278994 +0000" # This commit's date is "Sun Aug 17 07:12:55 292278994 +0000"
[project.commit('ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69')] [project.commit('ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69')]
end end
let(:timestamp) { Time.at((1 << 31) - 1) } let(:timestamp) { Time.zone.at((1 << 31) - 1) }
let(:rows) do let(:rows) do
[{ [{
"message": "Weird commit date\n", "message": "Weird commit date\n",
......
...@@ -97,8 +97,8 @@ describe PagesDomain do ...@@ -97,8 +97,8 @@ describe PagesDomain do
it 'saves validity time' do it 'saves validity time' do
domain.save domain.save
expect(domain.certificate_valid_not_before).to be_like_time(Time.parse("2020-03-16 14:20:34 UTC")) expect(domain.certificate_valid_not_before).to be_like_time(Time.zone.parse("2020-03-16 14:20:34 UTC"))
expect(domain.certificate_valid_not_after).to be_like_time(Time.parse("2220-01-28 14:20:34 UTC")) expect(domain.certificate_valid_not_after).to be_like_time(Time.zone.parse("2220-01-28 14:20:34 UTC"))
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