Commit b34dd89a authored by Sean Arnold's avatar Sean Arnold Committed by Stan Hu

Replace Time.now => Time.current in ee models

- models folder
- specs folder
parent c74cd3aa
...@@ -61,7 +61,7 @@ module Geo ...@@ -61,7 +61,7 @@ module Geo
model_record.update!( model_record.update!(
verification_checksum: checksum, verification_checksum: checksum,
verified_at: Time.now, verified_at: Time.current,
verification_failure: failure, verification_failure: failure,
verification_retry_at: retry_at, verification_retry_at: retry_at,
verification_retry_count: retry_count verification_retry_count: retry_count
......
...@@ -6,7 +6,7 @@ module Geo::Syncable ...@@ -6,7 +6,7 @@ module Geo::Syncable
included do included do
scope :failed, -> { where(success: false) } scope :failed, -> { where(success: false) }
scope :synced, -> { where(success: true) } scope :synced, -> { where(success: true) }
scope :retry_due, -> { where('retry_at is NULL OR retry_at < ?', Time.now) } scope :retry_due, -> { where('retry_at is NULL OR retry_at < ?', Time.current) }
scope :missing_on_primary, -> { where(missing_on_primary: true) } scope :missing_on_primary, -> { where(missing_on_primary: true) }
end end
end end
...@@ -38,7 +38,7 @@ module EE ...@@ -38,7 +38,7 @@ module EE
description_versions = description_versions =
issuable_description_versions.where('id BETWEEN ? AND ?', start_id, self.id) issuable_description_versions.where('id BETWEEN ? AND ?', start_id, self.id)
description_versions.update_all(deleted_at: Time.now) description_versions.update_all(deleted_at: Time.current)
issuable&.expire_note_etag_cache issuable&.expire_note_etag_cache
end end
......
...@@ -123,12 +123,12 @@ module EE ...@@ -123,12 +123,12 @@ module EE
end end
after_transition ready: :started do |group, _| after_transition ready: :started do |group, _|
group.ldap_sync_last_sync_at = DateTime.now group.ldap_sync_last_sync_at = DateTime.current
group.save group.save
end end
after_transition started: :ready do |group, _| after_transition started: :ready do |group, _|
current_time = DateTime.now current_time = DateTime.current
group.ldap_sync_last_update_at = current_time group.ldap_sync_last_update_at = current_time
group.ldap_sync_last_successful_update_at = current_time group.ldap_sync_last_successful_update_at = current_time
group.ldap_sync_error = nil group.ldap_sync_error = nil
...@@ -136,7 +136,7 @@ module EE ...@@ -136,7 +136,7 @@ module EE
end end
after_transition started: :failed do |group, _| after_transition started: :failed do |group, _|
group.ldap_sync_last_update_at = DateTime.now group.ldap_sync_last_update_at = DateTime.current
group.save group.save
end end
end end
......
...@@ -22,7 +22,7 @@ module EE ...@@ -22,7 +22,7 @@ module EE
end end
def review_end_at def review_end_at
merged_at || Time.now merged_at || Time.current
end end
end end
end end
......
...@@ -15,16 +15,16 @@ module EE ...@@ -15,16 +15,16 @@ module EE
state_machine :status, initial: :none do state_machine :status, initial: :none do
before_transition [:none, :finished, :failed] => :scheduled do |state, _| before_transition [:none, :finished, :failed] => :scheduled do |state, _|
state.last_update_scheduled_at = Time.now state.last_update_scheduled_at = Time.current
end end
before_transition scheduled: :started do |state, _| before_transition scheduled: :started do |state, _|
state.last_update_started_at = Time.now state.last_update_started_at = Time.current
end end
before_transition scheduled: :failed do |state, _| before_transition scheduled: :failed do |state, _|
if state.mirror? if state.mirror?
state.last_update_at = Time.now state.last_update_at = Time.current
state.set_next_execution_to_now state.set_next_execution_to_now
end end
end end
...@@ -41,7 +41,7 @@ module EE ...@@ -41,7 +41,7 @@ module EE
before_transition started: :failed do |state, _| before_transition started: :failed do |state, _|
if state.mirror? if state.mirror?
state.last_update_at = Time.now state.last_update_at = Time.current
state.increment_retry_count state.increment_retry_count
state.set_next_execution_timestamp state.set_next_execution_timestamp
end end
...@@ -49,7 +49,7 @@ module EE ...@@ -49,7 +49,7 @@ module EE
before_transition started: :finished do |state, _| before_transition started: :finished do |state, _|
if state.mirror? if state.mirror?
timestamp = Time.now timestamp = Time.current
state.last_update_at = timestamp state.last_update_at = timestamp
state.last_successful_update_at = timestamp state.last_successful_update_at = timestamp
...@@ -101,7 +101,7 @@ module EE ...@@ -101,7 +101,7 @@ module EE
return false if hard_failed? return false if hard_failed?
return false if updating_mirror? return false if updating_mirror?
next_execution_timestamp <= Time.now next_execution_timestamp <= Time.current
end end
def last_update_status def last_update_status
...@@ -137,7 +137,7 @@ module EE ...@@ -137,7 +137,7 @@ module EE
# We schedule the next sync time based on the duration of the # We schedule the next sync time based on the duration of the
# last mirroring period and add it a fixed backoff period with a random jitter # last mirroring period and add it a fixed backoff period with a random jitter
def set_next_execution_timestamp def set_next_execution_timestamp
timestamp = Time.now timestamp = Time.current
retry_factor = [1, self.retry_count].max retry_factor = [1, self.retry_count].max
delay = [base_delay(timestamp), ::Gitlab::Mirror.min_delay].max delay = [base_delay(timestamp), ::Gitlab::Mirror.min_delay].max
delay = [delay * retry_factor, ::Gitlab::Mirror.max_delay].min delay = [delay * retry_factor, ::Gitlab::Mirror.max_delay].min
...@@ -159,7 +159,7 @@ module EE ...@@ -159,7 +159,7 @@ module EE
def set_next_execution_to_now(prioritized: false) def set_next_execution_to_now(prioritized: false)
return unless mirror? return unless mirror?
self.next_execution_timestamp = prioritized ? 5.minutes.ago : Time.now self.next_execution_timestamp = prioritized ? 5.minutes.ago : Time.current
end end
def retry_limit_exceeded? def retry_limit_exceeded?
......
...@@ -306,7 +306,7 @@ module EE ...@@ -306,7 +306,7 @@ module EE
end end
def admin_unsubscribe! def admin_unsubscribe!
update_column :admin_email_unsubscribed_at, Time.now update_column :admin_email_unsubscribed_at, Time.current
end end
override :allow_password_authentication_for_web? override :allow_password_authentication_for_web?
......
...@@ -20,7 +20,7 @@ class ElasticsearchIndexedNamespace < ApplicationRecord ...@@ -20,7 +20,7 @@ class ElasticsearchIndexedNamespace < ApplicationRecord
def self.index_first_n_namespaces_of_plan(plan, number_of_namespaces) def self.index_first_n_namespaces_of_plan(plan, number_of_namespaces)
indexed_namespaces = self.select(:namespace_id) indexed_namespaces = self.select(:namespace_id)
now = Time.now now = Time.current
ids = GitlabSubscription ids = GitlabSubscription
.with_hosted_plan(plan) .with_hosted_plan(plan)
......
...@@ -8,7 +8,7 @@ class Geo::ContainerRepositoryRegistry < Geo::BaseRegistry ...@@ -8,7 +8,7 @@ class Geo::ContainerRepositoryRegistry < Geo::BaseRegistry
scope :repository_id_not_in, -> (ids) { where.not(container_repository_id: ids) } scope :repository_id_not_in, -> (ids) { where.not(container_repository_id: ids) }
scope :failed, -> { with_state(:failed) } scope :failed, -> { with_state(:failed) }
scope :synced, -> { with_state(:synced) } scope :synced, -> { with_state(:synced) }
scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.now))) } scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.current))) }
state_machine :state, initial: :pending do state_machine :state, initial: :pending do
state :started state :started
...@@ -17,7 +17,7 @@ class Geo::ContainerRepositoryRegistry < Geo::BaseRegistry ...@@ -17,7 +17,7 @@ class Geo::ContainerRepositoryRegistry < Geo::BaseRegistry
state :pending state :pending
before_transition any => :started do |registry, _| before_transition any => :started do |registry, _|
registry.last_synced_at = Time.now registry.last_synced_at = Time.current
end end
before_transition any => :pending do |registry, _| before_transition any => :pending do |registry, _|
......
...@@ -10,7 +10,7 @@ class Geo::DesignRegistry < Geo::BaseRegistry ...@@ -10,7 +10,7 @@ class Geo::DesignRegistry < Geo::BaseRegistry
scope :pending, -> { with_state(:pending) } scope :pending, -> { with_state(:pending) }
scope :failed, -> { with_state(:failed) } scope :failed, -> { with_state(:failed) }
scope :synced, -> { with_state(:synced) } scope :synced, -> { with_state(:synced) }
scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.now))) } scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.current))) }
state_machine :state, initial: :pending do state_machine :state, initial: :pending do
state :started state :started
...@@ -19,7 +19,7 @@ class Geo::DesignRegistry < Geo::BaseRegistry ...@@ -19,7 +19,7 @@ class Geo::DesignRegistry < Geo::BaseRegistry
state :pending state :pending
before_transition any => :started do |registry, _| before_transition any => :started do |registry, _|
registry.last_synced_at = Time.now registry.last_synced_at = Time.current
end end
before_transition any => :pending do |registry, _| before_transition any => :pending do |registry, _|
......
...@@ -20,7 +20,7 @@ class Geo::PackageFileRegistry < Geo::BaseRegistry ...@@ -20,7 +20,7 @@ class Geo::PackageFileRegistry < Geo::BaseRegistry
scope :never, -> { where(last_synced_at: nil) } scope :never, -> { where(last_synced_at: nil) }
scope :failed, -> { with_state(:failed) } scope :failed, -> { with_state(:failed) }
scope :synced, -> { with_state(:synced) } scope :synced, -> { with_state(:synced) }
scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.now))) } scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.current))) }
scope :ordered, -> { order(:id) } scope :ordered, -> { order(:id) }
state_machine :state, initial: :pending do state_machine :state, initial: :pending do
...@@ -30,7 +30,7 @@ class Geo::PackageFileRegistry < Geo::BaseRegistry ...@@ -30,7 +30,7 @@ class Geo::PackageFileRegistry < Geo::BaseRegistry
state :failed, value: STATE_VALUES[:failed] state :failed, value: STATE_VALUES[:failed]
before_transition any => :started do |registry, _| before_transition any => :started do |registry, _|
registry.last_synced_at = Time.now registry.last_synced_at = Time.current
end end
before_transition any => :pending do |registry, _| before_transition any => :pending do |registry, _|
......
...@@ -68,8 +68,8 @@ class Geo::ProjectRegistry < Geo::BaseRegistry ...@@ -68,8 +68,8 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
def self.retry_due def self.retry_due
where( where(
arel_table[:repository_retry_at].lt(Time.now) arel_table[:repository_retry_at].lt(Time.current)
.or(arel_table[:wiki_retry_at].lt(Time.now)) .or(arel_table[:wiki_retry_at].lt(Time.current))
.or(arel_table[:repository_retry_at].eq(nil)) .or(arel_table[:repository_retry_at].eq(nil))
.or(arel_table[:wiki_retry_at].eq(nil)) .or(arel_table[:wiki_retry_at].eq(nil))
) )
...@@ -180,7 +180,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry ...@@ -180,7 +180,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
repository_checksum_mismatch: false, repository_checksum_mismatch: false,
last_repository_verification_failure: nil, last_repository_verification_failure: nil,
repository_verification_retry_count: nil, repository_verification_retry_count: nil,
resync_repository_was_scheduled_at: Time.now, resync_repository_was_scheduled_at: Time.current,
repository_retry_count: nil, repository_retry_count: nil,
repository_retry_at: nil repository_retry_at: nil
) )
...@@ -223,7 +223,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry ...@@ -223,7 +223,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
ensure_valid_type!(type) ensure_valid_type!(type)
update!( update!(
"last_#{type}_synced_at" => Time.now, "last_#{type}_synced_at" => Time.current,
"#{type}_retry_count" => retry_count(type)) "#{type}_retry_count" => retry_count(type))
end end
...@@ -235,7 +235,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry ...@@ -235,7 +235,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
ensure_valid_type!(type) ensure_valid_type!(type)
update!( update!(
# Indicate that the sync succeeded (but separately mark as synced atomically) # Indicate that the sync succeeded (but separately mark as synced atomically)
"last_#{type}_successful_sync_at" => Time.now, "last_#{type}_successful_sync_at" => Time.current,
"#{type}_retry_count" => nil, "#{type}_retry_count" => nil,
"#{type}_retry_at" => nil, "#{type}_retry_at" => nil,
"force_to_redownload_#{type}" => false, "force_to_redownload_#{type}" => false,
...@@ -404,7 +404,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry ...@@ -404,7 +404,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
# #
# This operation happens only in the database and the resync will be triggered after by the cron job # This operation happens only in the database and the resync will be triggered after by the cron job
def flag_repository_for_resync! def flag_repository_for_resync!
repository_updated!(:repository, Time.now) repository_updated!(:repository, Time.current)
end end
# Flag the repository to perform a full re-download # Flag the repository to perform a full re-download
......
...@@ -246,7 +246,7 @@ class GeoNodeStatus < ApplicationRecord ...@@ -246,7 +246,7 @@ class GeoNodeStatus < ApplicationRecord
latest_event = Geo::EventLog.latest_event latest_event = Geo::EventLog.latest_event
self.last_event_id = latest_event&.id self.last_event_id = latest_event&.id
self.last_event_date = latest_event&.created_at self.last_event_date = latest_event&.created_at
self.last_successful_status_check_at = Time.now self.last_successful_status_check_at = Time.current
self.storage_shards = StorageShard.all self.storage_shards = StorageShard.all
self.storage_configuration_digest = StorageShard.build_digest self.storage_configuration_digest = StorageShard.build_digest
......
...@@ -29,7 +29,7 @@ module Gitlab ...@@ -29,7 +29,7 @@ module Gitlab
end end
def default_date def default_date
Time.now.utc.yesterday.to_date Time.current.utc.yesterday.to_date
end end
def default_key def default_key
......
...@@ -40,11 +40,11 @@ module Vulnerabilities ...@@ -40,11 +40,11 @@ module Vulnerabilities
state :failed state :failed
before_transition created: :running do |export| before_transition created: :running do |export|
export.started_at = Time.now export.started_at = Time.current
end end
before_transition any => [:finished, :failed] do |export| before_transition any => [:finished, :failed] do |export|
export.finished_at = Time.now export.finished_at = Time.current
end end
end end
......
...@@ -40,8 +40,8 @@ describe MergeRequest::Metrics do ...@@ -40,8 +40,8 @@ describe MergeRequest::Metrics do
end end
context 'when MR is not merged' do context 'when MR is not merged' do
it 'is Time.now' do it 'is Time.current' do
expect(subject.review_end_at).to be_like_time(Time.now) expect(subject.review_end_at).to be_like_time(Time.current)
end end
end end
end end
......
...@@ -345,7 +345,7 @@ describe Epic do ...@@ -345,7 +345,7 @@ describe Epic do
end end
it_behaves_like 'within_timeframe scope' do it_behaves_like 'within_timeframe scope' do
let_it_be(:now) { Time.now } let_it_be(:now) { Time.current }
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:resource_1) { create(:epic, group: group, start_date: now - 1.day, end_date: now + 1.day) } let_it_be(:resource_1) { create(:epic, group: group, start_date: now - 1.day, end_date: now + 1.day) }
let_it_be(:resource_2) { create(:epic, group: group, start_date: now + 2.days, end_date: now + 3.days) } let_it_be(:resource_2) { create(:epic, group: group, start_date: now + 2.days, end_date: now + 3.days) }
...@@ -458,7 +458,7 @@ describe Epic do ...@@ -458,7 +458,7 @@ describe Epic do
describe '#close' do describe '#close' do
subject(:epic) { create(:epic, state: 'opened') } subject(:epic) { create(:epic, state: 'opened') }
it 'sets closed_at to Time.now when an epic is closed' do it 'sets closed_at to Time.current when an epic is closed' do
expect { epic.close }.to change { epic.closed_at }.from(nil) expect { epic.close }.to change { epic.closed_at }.from(nil)
end end
...@@ -468,7 +468,7 @@ describe Epic do ...@@ -468,7 +468,7 @@ describe Epic do
end end
describe '#reopen' do describe '#reopen' do
subject(:epic) { create(:epic, state: 'closed', closed_at: Time.now, closed_by: user) } subject(:epic) { create(:epic, state: 'closed', closed_at: Time.current, closed_by: user) }
it 'sets closed_at to nil when an epic is reopend' do it 'sets closed_at to nil when an epic is reopend' do
expect { epic.reopen }.to change { epic.closed_at }.to(nil) expect { epic.reopen }.to change { epic.closed_at }.to(nil)
......
...@@ -284,7 +284,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -284,7 +284,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
describe '#repository_sync_due?' do describe '#repository_sync_due?' do
where(:last_synced_at, :resync, :retry_at, :expected) do where(:last_synced_at, :resync, :retry_at, :expected) do
now = Time.now now = Time.current
past = now - 1.year past = now - 1.year
future = now + 1.year future = now + 1.year
...@@ -313,13 +313,13 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -313,13 +313,13 @@ describe Geo::ProjectRegistry, :geo_fdw do
) )
end end
it { expect(registry.repository_sync_due?(Time.now)).to eq(expected) } it { expect(registry.repository_sync_due?(Time.current)).to eq(expected) }
end end
end end
describe '#wiki_sync_due?' do describe '#wiki_sync_due?' do
where(:last_synced_at, :resync, :retry_at, :expected) do where(:last_synced_at, :resync, :retry_at, :expected) do
now = Time.now now = Time.current
past = now - 1.year past = now - 1.year
future = now + 1.year future = now + 1.year
...@@ -348,7 +348,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -348,7 +348,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
) )
end end
it { expect(registry.wiki_sync_due?(Time.now)).to eq(expected) } it { expect(registry.wiki_sync_due?(Time.current)).to eq(expected) }
end end
end end
...@@ -405,7 +405,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -405,7 +405,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
it 'sets last_repository_synced_at to now' do it 'sets last_repository_synced_at to now' do
subject.start_sync!(type) subject.start_sync!(type)
expect(subject.last_repository_synced_at).to be_like_time(Time.now) expect(subject.last_repository_synced_at).to be_like_time(Time.current)
end end
context 'when repository_retry_count is nil' do context 'when repository_retry_count is nil' do
...@@ -423,7 +423,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -423,7 +423,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
it 'sets last_wiki_synced_at to now' do it 'sets last_wiki_synced_at to now' do
subject.start_sync!(type) subject.start_sync!(type)
expect(subject.last_wiki_synced_at).to be_like_time(Time.now) expect(subject.last_wiki_synced_at).to be_like_time(Time.current)
end end
context 'when wiki_retry_count is nil' do context 'when wiki_retry_count is nil' do
...@@ -456,7 +456,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -456,7 +456,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
Timecop.freeze do Timecop.freeze do
subject.finish_sync!(type) subject.finish_sync!(type)
expect(subject.reload.last_repository_successful_sync_at).to be_within(1).of(Time.now) expect(subject.reload.last_repository_successful_sync_at).to be_within(1).of(Time.current)
end end
end end
...@@ -551,7 +551,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -551,7 +551,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
Timecop.freeze do Timecop.freeze do
subject.finish_sync!(type) subject.finish_sync!(type)
expect(subject.reload.last_wiki_successful_sync_at).to be_within(1).of(Time.now) expect(subject.reload.last_wiki_successful_sync_at).to be_within(1).of(Time.current)
end end
end end
...@@ -645,7 +645,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -645,7 +645,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
subject.fail_sync!(type, message, error) subject.fail_sync!(type, message, error)
expect(subject.repository_retry_at > Time.now).to be(true) expect(subject.repository_retry_at > Time.current).to be(true)
end end
it 'ensures repository_retry_at is capped at one hour' do it 'ensures repository_retry_at is capped at one hour' do
...@@ -730,7 +730,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -730,7 +730,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
subject.fail_sync!(type, message, error) subject.fail_sync!(type, message, error)
expect(subject.wiki_retry_at > Time.now).to be(true) expect(subject.wiki_retry_at > Time.current).to be(true)
end end
it 'ensures wiki_retry_at is capped at one hour' do it 'ensures wiki_retry_at is capped at one hour' do
...@@ -840,7 +840,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -840,7 +840,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
repository_retry_count: 1, repository_retry_count: 1,
repository_verification_retry_count: 1) repository_verification_retry_count: 1)
subject.repository_updated!(event.source, Time.now) subject.repository_updated!(event.source, Time.current)
end end
it 'resets sync state' do it 'resets sync state' do
...@@ -851,7 +851,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -851,7 +851,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
force_to_redownload_repository: nil, force_to_redownload_repository: nil,
last_repository_sync_failure: nil, last_repository_sync_failure: nil,
repository_missing_on_primary: nil, repository_missing_on_primary: nil,
resync_repository_was_scheduled_at: be_within(1.minute).of(Time.now) resync_repository_was_scheduled_at: be_within(1.minute).of(Time.current)
) )
end end
...@@ -878,7 +878,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -878,7 +878,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
wiki_retry_count: 1, wiki_retry_count: 1,
wiki_verification_retry_count: 1) wiki_verification_retry_count: 1)
subject.repository_updated!(event.source, Time.now) subject.repository_updated!(event.source, Time.current)
end end
it 'resets sync state' do it 'resets sync state' do
...@@ -889,7 +889,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -889,7 +889,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
force_to_redownload_wiki: nil, force_to_redownload_wiki: nil,
last_wiki_sync_failure: nil, last_wiki_sync_failure: nil,
wiki_missing_on_primary: nil, wiki_missing_on_primary: nil,
resync_wiki_was_scheduled_at: be_within(1.minute).of(Time.now) resync_wiki_was_scheduled_at: be_within(1.minute).of(Time.current)
) )
end end
...@@ -1098,7 +1098,7 @@ describe Geo::ProjectRegistry, :geo_fdw do ...@@ -1098,7 +1098,7 @@ describe Geo::ProjectRegistry, :geo_fdw do
context 'when repository has successfully synced' do context 'when repository has successfully synced' do
it 'returns true' do it 'returns true' do
registry = create(:geo_project_registry, last_repository_successful_sync_at: Time.now) registry = create(:geo_project_registry, last_repository_successful_sync_at: Time.current)
expect(registry.repository_has_successfully_synced?).to be_truthy expect(registry.repository_has_successfully_synced?).to be_truthy
end end
......
...@@ -1077,7 +1077,7 @@ describe GeoNodeStatus, :geo, :geo_fdw do ...@@ -1077,7 +1077,7 @@ describe GeoNodeStatus, :geo, :geo_fdw do
shared_examples 'timestamp parameters' do |timestamp_column, date_column| shared_examples 'timestamp parameters' do |timestamp_column, date_column|
it 'returns the value it was assigned via UNIX timestamp' do it 'returns the value it was assigned via UNIX timestamp' do
now = Time.now.beginning_of_day.utc now = Time.current.beginning_of_day.utc
subject.update_attribute(timestamp_column, now.to_i) subject.update_attribute(timestamp_column, now.to_i)
expect(subject.public_send(date_column)).to eq(now) expect(subject.public_send(date_column)).to eq(now)
......
...@@ -45,7 +45,7 @@ describe HistoricalData do ...@@ -45,7 +45,7 @@ describe HistoricalData do
context 'with multiple historical data points for the current license' do context 'with multiple historical data points for the current license' do
before do before do
(1..3).each do |i| (1..3).each do |i|
described_class.create!(date: Time.now - i.days, active_user_count: i * 100) described_class.create!(date: Time.current - i.days, active_user_count: i * 100)
end end
end end
......
...@@ -13,7 +13,7 @@ describe IssuablesAnalytics do ...@@ -13,7 +13,7 @@ describe IssuablesAnalytics do
end end
before do before do
Timecop.freeze(Time.now) do Timecop.freeze(Time.current) do
seed.each_pair do |months_back, issues_count| seed.each_pair do |months_back, issues_count|
create_list(:issue, issues_count, project: project, created_at: months_back.months.ago) create_list(:issue, issues_count, project: project, created_at: months_back.months.ago)
end end
......
...@@ -29,7 +29,7 @@ describe ProjectFeatureUsage, type: :model do ...@@ -29,7 +29,7 @@ describe ProjectFeatureUsage, type: :model do
subject.log_jira_dvcs_integration_usage subject.log_jira_dvcs_integration_usage
expect(subject.jira_dvcs_server_last_sync_at).to be_nil expect(subject.jira_dvcs_server_last_sync_at).to be_nil
expect(subject.jira_dvcs_cloud_last_sync_at).to be_like_time(Time.now) expect(subject.jira_dvcs_cloud_last_sync_at).to be_like_time(Time.current)
end end
end end
...@@ -37,7 +37,7 @@ describe ProjectFeatureUsage, type: :model do ...@@ -37,7 +37,7 @@ describe ProjectFeatureUsage, type: :model do
Timecop.freeze do Timecop.freeze do
subject.log_jira_dvcs_integration_usage(cloud: false) subject.log_jira_dvcs_integration_usage(cloud: false)
expect(subject.jira_dvcs_server_last_sync_at).to be_like_time(Time.now) expect(subject.jira_dvcs_server_last_sync_at).to be_like_time(Time.current)
expect(subject.jira_dvcs_cloud_last_sync_at).to be_nil expect(subject.jira_dvcs_cloud_last_sync_at).to be_nil
end end
end end
......
...@@ -59,7 +59,7 @@ describe ProjectImportState, type: :model do ...@@ -59,7 +59,7 @@ describe ProjectImportState, type: :model do
end end
context 'with index status' do context 'with index status' do
let(:index_status) { IndexStatus.create!(project: project, indexed_at: Time.now, last_commit: 'foo') } let(:index_status) { IndexStatus.create!(project: project, indexed_at: Time.current, last_commit: 'foo') }
it 'schedules a full index of the repository' do it 'schedules a full index of the repository' do
expect(ElasticCommitIndexerWorker).to receive(:perform_async).with(import_state.project_id) expect(ElasticCommitIndexerWorker).to receive(:perform_async).with(import_state.project_id)
...@@ -73,10 +73,10 @@ describe ProjectImportState, type: :model do ...@@ -73,10 +73,10 @@ describe ProjectImportState, type: :model do
describe 'when create' do describe 'when create' do
it 'sets next execution timestamp to now' do it 'sets next execution timestamp to now' do
Timecop.freeze(Time.now) do Timecop.freeze(Time.current) do
import_state = create(:import_state, :mirror) import_state = create(:import_state, :mirror)
expect(import_state.next_execution_timestamp).to be_like_time(Time.now) expect(import_state.next_execution_timestamp).to be_like_time(Time.current)
end end
end end
end end
...@@ -223,7 +223,7 @@ describe ProjectImportState, type: :model do ...@@ -223,7 +223,7 @@ describe ProjectImportState, type: :model do
:finished, :finished,
:mirror, :mirror,
:repository, :repository,
next_execution_timestamp: Time.now - 2.minutes) next_execution_timestamp: Time.current - 2.minutes)
expect(import_state.mirror_update_due?).to be true expect(import_state.mirror_update_due?).to be true
end end
...@@ -235,7 +235,7 @@ describe ProjectImportState, type: :model do ...@@ -235,7 +235,7 @@ describe ProjectImportState, type: :model do
:finished, :finished,
:mirror, :mirror,
:repository, :repository,
next_execution_timestamp: Time.now - 2.minutes) next_execution_timestamp: Time.current - 2.minutes)
end end
before do before do
...@@ -250,7 +250,7 @@ describe ProjectImportState, type: :model do ...@@ -250,7 +250,7 @@ describe ProjectImportState, type: :model do
context 'when mirror has no content' do context 'when mirror has no content' do
it 'returns false' do it 'returns false' do
import_state = create(:import_state, :finished, :mirror) import_state = create(:import_state, :finished, :mirror)
import_state.next_execution_timestamp = Time.now - 2.minutes import_state.next_execution_timestamp = Time.current - 2.minutes
expect(import_state.mirror_update_due?).to be false expect(import_state.mirror_update_due?).to be false
end end
...@@ -301,7 +301,7 @@ describe ProjectImportState, type: :model do ...@@ -301,7 +301,7 @@ describe ProjectImportState, type: :model do
end end
context 'when mirror has updated' do context 'when mirror has updated' do
let(:timestamp) { Time.now } let(:timestamp) { Time.current }
before do before do
import_state.last_update_at = timestamp import_state.last_update_at = timestamp
...@@ -341,15 +341,15 @@ describe ProjectImportState, type: :model do ...@@ -341,15 +341,15 @@ describe ProjectImportState, type: :model do
end end
it 'returns false when first update failed' do it 'returns false when first update failed' do
import_state.last_update_at = Time.now import_state.last_update_at = Time.current
expect(import_state.ever_updated_successfully?).to be_falsey expect(import_state.ever_updated_successfully?).to be_falsey
end end
it 'returns true when a successful update timestamp exists' do it 'returns true when a successful update timestamp exists' do
# It does not matter if the last update was successful or not # It does not matter if the last update was successful or not
import_state.last_update_at = Time.now import_state.last_update_at = Time.current
import_state.last_successful_update_at = Time.now - 5.minutes import_state.last_successful_update_at = Time.current - 5.minutes
expect(import_state.ever_updated_successfully?).to be_truthy expect(import_state.ever_updated_successfully?).to be_truthy
end end
...@@ -358,7 +358,7 @@ describe ProjectImportState, type: :model do ...@@ -358,7 +358,7 @@ describe ProjectImportState, type: :model do
describe '#set_next_execution_timestamp' do describe '#set_next_execution_timestamp' do
let(:import_state) { create(:import_state, :mirror, :finished) } let(:import_state) { create(:import_state, :mirror, :finished) }
let!(:timestamp) { Time.now.change(usec: 0) } let!(:timestamp) { Time.current.change(usec: 0) }
let!(:jitter) { 2.seconds } let!(:jitter) { 2.seconds }
before do before do
...@@ -458,7 +458,7 @@ describe ProjectImportState, type: :model do ...@@ -458,7 +458,7 @@ describe ProjectImportState, type: :model do
import_state = create(:import_state, import_state = create(:import_state,
:repository, :repository,
:mirror, :mirror,
next_execution_timestamp: Time.now - 2.minutes) next_execution_timestamp: Time.current - 2.minutes)
expect(import_state.force_import_job!).to be_nil expect(import_state.force_import_job!).to be_nil
end end
...@@ -470,7 +470,7 @@ describe ProjectImportState, type: :model do ...@@ -470,7 +470,7 @@ describe ProjectImportState, type: :model do
end end
it 'sets next execution timestamp to 5 minutes ago and schedules UpdateAllMirrorsWorker' do it 'sets next execution timestamp to 5 minutes ago and schedules UpdateAllMirrorsWorker' do
timestamp = Time.now timestamp = Time.current
import_state = create(:import_state, :mirror) import_state = create(:import_state, :mirror)
expect(UpdateAllMirrorsWorker).to receive(:perform_async) expect(UpdateAllMirrorsWorker).to receive(:perform_async)
...@@ -482,7 +482,7 @@ describe ProjectImportState, type: :model do ...@@ -482,7 +482,7 @@ describe ProjectImportState, type: :model do
context 'when mirror is hard failed' do context 'when mirror is hard failed' do
it 'resets retry count and schedules a mirroring worker' do it 'resets retry count and schedules a mirroring worker' do
timestamp = Time.now timestamp = Time.current
import_state = create(:import_state, :mirror, :hard_failed) import_state = create(:import_state, :mirror, :hard_failed)
expect(UpdateAllMirrorsWorker).to receive(:perform_async) expect(UpdateAllMirrorsWorker).to receive(:perform_async)
......
...@@ -322,7 +322,7 @@ describe Project do ...@@ -322,7 +322,7 @@ describe Project do
project.save project.save
end.to change { ProjectImportState.count }.by(1) end.to change { ProjectImportState.count }.by(1)
expect(project.import_state.next_execution_timestamp).to be_like_time(Time.now) expect(project.import_state.next_execution_timestamp).to be_like_time(Time.current)
end end
end end
end end
...@@ -337,7 +337,7 @@ describe Project do ...@@ -337,7 +337,7 @@ describe Project do
project.update(mirror: true, mirror_user_id: project.creator.id, import_url: generate(:url)) project.update(mirror: true, mirror_user_id: project.creator.id, import_url: generate(:url))
end.to change { ProjectImportState.count }.by(1) end.to change { ProjectImportState.count }.by(1)
expect(project.import_state.next_execution_timestamp).to be_like_time(Time.now) expect(project.import_state.next_execution_timestamp).to be_like_time(Time.current)
end end
end end
end end
...@@ -351,7 +351,7 @@ describe Project do ...@@ -351,7 +351,7 @@ describe Project do
project.update(mirror: true, mirror_user_id: project.creator.id) project.update(mirror: true, mirror_user_id: project.creator.id)
end.not_to change { ProjectImportState.count } end.not_to change { ProjectImportState.count }
expect(project.import_state.next_execution_timestamp).to be_like_time(Time.now) expect(project.import_state.next_execution_timestamp).to be_like_time(Time.current)
end end
end end
end end
...@@ -359,7 +359,7 @@ describe Project do ...@@ -359,7 +359,7 @@ describe Project do
end end
describe '.mirrors_to_sync' do describe '.mirrors_to_sync' do
let(:timestamp) { Time.now } let(:timestamp) { Time.current }
context 'when mirror is scheduled' do context 'when mirror is scheduled' do
it 'returns empty' do it 'returns empty' do
......
...@@ -236,7 +236,7 @@ describe User do ...@@ -236,7 +236,7 @@ describe User do
end end
describe '#forget_me!' do describe '#forget_me!' do
subject { create(:user, remember_created_at: Time.now) } subject { create(:user, remember_created_at: Time.current) }
it 'clears remember_created_at' do it 'clears remember_created_at' do
subject.forget_me! subject.forget_me!
......
...@@ -84,7 +84,7 @@ describe Vulnerabilities::Export do ...@@ -84,7 +84,7 @@ describe Vulnerabilities::Export do
vulnerability_export.start! vulnerability_export.start!
end end
it { is_expected.to have_attributes(status: 'running', started_at: Time.now) } it { is_expected.to have_attributes(status: 'running', started_at: Time.current) }
end end
context 'when the export is running' do context 'when the export is running' do
...@@ -95,7 +95,7 @@ describe Vulnerabilities::Export do ...@@ -95,7 +95,7 @@ describe Vulnerabilities::Export do
vulnerability_export.finish! vulnerability_export.finish!
end end
it { is_expected.to have_attributes(status: 'finished', finished_at: Time.now) } it { is_expected.to have_attributes(status: 'finished', finished_at: Time.current) }
end end
context 'and it fails' do context 'and it fails' do
...@@ -105,7 +105,7 @@ describe Vulnerabilities::Export do ...@@ -105,7 +105,7 @@ describe Vulnerabilities::Export do
vulnerability_export.failed! vulnerability_export.failed!
end end
it { is_expected.to have_attributes(status: 'failed', finished_at: Time.now) } it { is_expected.to have_attributes(status: 'failed', finished_at: Time.current) }
end end
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