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
def expired?
return false unless x509
current = Time.new
current = Time.current
current < x509.not_before || x509.not_after < current
end
......
......@@ -300,7 +300,7 @@ class GeoNodeStatus < ApplicationRecord
end
def attribute_timestamp=(attr, value)
self[attr] = Time.at(value)
self[attr] = Time.zone.at(value)
end
def self.percentage_methods
......
......@@ -1114,7 +1114,7 @@ describe GeoNodeStatus, :geo, :geo_fdw do
expect(result.id).to be_nil
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)
end
end
......
......@@ -118,7 +118,7 @@ describe Ci::PipelineSchedule do
let(:pipeline_schedule) { create(:ci_pipeline_schedule, :every_minute) }
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)
end
end
......
......@@ -708,7 +708,7 @@ describe CommitStatus do
end
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
allow(Time).to receive(:now).and_return(current_time)
......
......@@ -91,7 +91,7 @@ describe Sortable do
Group.all.order_by(order).map(&:name)
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!(: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) }
......
......@@ -994,7 +994,7 @@ describe Issue do
it_behaves_like 'versioned description'
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) }
it 'returns updated_at value if updated_at did not change at all' do
......@@ -1010,15 +1010,15 @@ describe Issue do
end
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)
end
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
......
......@@ -62,7 +62,7 @@ describe Iteration do
end
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 }
it 'is not valid' do
......@@ -94,7 +94,7 @@ describe Iteration do
describe '#future_date' 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 }
it { is_expected.to be_valid }
......@@ -111,7 +111,7 @@ describe Iteration do
end
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 }
it 'is not valid' do
......@@ -122,7 +122,7 @@ describe Iteration do
context 'when start_date is over 500 years in the future' do
let(:start_date) { 501.years.from_now }
let(:due_date) { Time.now }
let(:due_date) { Time.current }
it 'is not valid' do
expect(subject).not_to be_valid
......@@ -131,7 +131,7 @@ describe Iteration do
end
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 }
it 'is not valid' do
......@@ -143,7 +143,7 @@ describe Iteration do
end
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(: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) }
......
......@@ -73,7 +73,7 @@ describe MergeRequestDiffCommit do
# This commit's date is "Sun Aug 17 07:12:55 292278994 +0000"
[project.commit('ba3343bc4fa403a8dfbfcab7fc1a8c29ee34bd69')]
end
let(:timestamp) { Time.at((1 << 31) - 1) }
let(:timestamp) { Time.zone.at((1 << 31) - 1) }
let(:rows) do
[{
"message": "Weird commit date\n",
......
......@@ -97,8 +97,8 @@ describe PagesDomain do
it 'saves validity time' do
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_after).to be_like_time(Time.parse("2220-01-28 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.zone.parse("2220-01-28 14:20:34 UTC"))
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