Commit ef914070 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'ali/replace-timecop-freeze-with-travel-to' into 'master'

[RUN AS-IF-FOSS] Replace calls to `Timecop.freeze` with `travel_to`

See merge request gitlab-org/gitlab!43466
parents 91fa8e8b 1c9243a8
......@@ -18,7 +18,7 @@ RSpec.describe Resolvers::VulnerabilitiesCountPerDayResolver do
let(:args) { { start_date: start_date, end_date: end_date } }
it 'fetches historical vulnerability data from the start date to the end date' do
Timecop.freeze(Date.new(2019, 10, 31)) do
travel_to(Date.new(2019, 10, 31)) do
create(:vulnerability_historical_statistic, date: start_date + 1.day, total: 2, critical: 1, high: 1, project: project)
create(:vulnerability_historical_statistic, date: start_date + 2.days, total: 3, critical: 2, high: 1, project: project)
create(:vulnerability_historical_statistic, date: start_date + 4.days, total: 1, critical: 1, high: 0, project: project_2)
......
......@@ -15,7 +15,7 @@ RSpec.describe Resolvers::VulnerabilitiesHistoryResolver do
let(:args) { { start_date: Date.parse('2019-10-15'), end_date: Date.parse('2019-10-21') } }
it "fetches historical vulnerability data from the start date to the end date" do
Timecop.freeze(Date.parse('2019-10-31')) do
travel_to(Date.parse('2019-10-31')) do
create(:vulnerability, :critical, created_at: 15.days.ago, dismissed_at: 10.days.ago, project: project)
create(:vulnerability, :high, created_at: 15.days.ago, dismissed_at: 11.days.ago, project: project)
create(:vulnerability, :critical, created_at: 14.days.ago, resolved_at: 12.days.ago, project: project)
......
......@@ -74,7 +74,7 @@ RSpec.describe Analytics::GroupActivityCalculator do
let(:old_member) { create(:user, created_at: 102.days.ago) }
before do
Timecop.freeze(100.days.ago) do
travel_to(100.days.ago) do
subgroup.add_developer old_member
end
end
......
......@@ -13,10 +13,10 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
describe "#new_issues" do
context 'with from date' do
before do
Timecop.freeze(5.days.ago) { create(:issue, project: project) }
Timecop.freeze(5.days.ago) { create(:issue, project: project_2) }
Timecop.freeze(5.days.from_now) { create(:issue, project: project) }
Timecop.freeze(5.days.from_now) { create(:issue, project: project_2) }
travel_to(5.days.ago) { create(:issue, project: project) }
travel_to(5.days.ago) { create(:issue, project: project_2) }
travel_to(5.days.from_now) { create(:issue, project: project) }
travel_to(5.days.from_now) { create(:issue, project: project_2) }
end
it "finds the number of issues created after it" do
......@@ -31,7 +31,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
context 'with subgroups' do
before do
Timecop.freeze(5.days.from_now) { create(:issue, project: create(:project, namespace: create(:group, parent: group))) }
travel_to(5.days.from_now) { create(:issue, project: create(:project, namespace: create(:group, parent: group))) }
end
it "finds issues from them" do
......@@ -41,7 +41,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
context 'with projects specified in options' do
before do
Timecop.freeze(5.days.from_now) { create(:issue, project: create(:project, namespace: group)) }
travel_to(5.days.from_now) { create(:issue, project: create(:project, namespace: group)) }
end
subject { described_class.new(group, options: { from: Time.now, current_user: user, projects: [project.id, project_2.id] }).data }
......@@ -112,9 +112,9 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
context 'with other projects' do
before do
Timecop.freeze(5.days.from_now) { create(:issue, project: create(:project, namespace: create(:group))) }
Timecop.freeze(5.days.from_now) { create(:issue, project: project) }
Timecop.freeze(5.days.from_now) { create(:issue, project: project_2) }
travel_to(5.days.from_now) { create(:issue, project: create(:project, namespace: create(:group))) }
travel_to(5.days.from_now) { create(:issue, project: project) }
travel_to(5.days.from_now) { create(:issue, project: project_2) }
end
it "doesn't find issues from them" do
......@@ -126,10 +126,10 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
describe "#deploys" do
context 'with from date' do
before do
Timecop.freeze(5.days.ago) { create(:deployment, :success, project: project) }
Timecop.freeze(5.days.from_now) { create(:deployment, :success, project: project) }
Timecop.freeze(5.days.ago) { create(:deployment, :success, project: project_2) }
Timecop.freeze(5.days.from_now) { create(:deployment, :success, project: project_2) }
travel_to(5.days.ago) { create(:deployment, :success, project: project) }
travel_to(5.days.from_now) { create(:deployment, :success, project: project) }
travel_to(5.days.ago) { create(:deployment, :success, project: project_2) }
travel_to(5.days.from_now) { create(:deployment, :success, project: project_2) }
end
it "finds the number of deploys made created after it" do
......@@ -144,7 +144,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
context 'with subgroups' do
before do
Timecop.freeze(5.days.from_now) do
travel_to(5.days.from_now) do
create(:deployment, :success, project: create(:project, :repository, namespace: create(:group, parent: group)))
end
end
......@@ -156,7 +156,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
context 'with projects specified in options' do
before do
Timecop.freeze(5.days.from_now) do
travel_to(5.days.from_now) do
create(:deployment, :success, project: create(:project, :repository, namespace: group, name: 'not_applicable'))
end
end
......@@ -179,7 +179,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
context 'with other projects' do
before do
Timecop.freeze(5.days.from_now) do
travel_to(5.days.from_now) do
create(:deployment, :success, project: create(:project, :repository, namespace: create(:group)))
end
end
......@@ -207,7 +207,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
end
before do
Timecop.freeze(5.days.ago) do
travel_to(5.days.ago) do
create(:deployment, :success, project: project)
end
end
......@@ -224,7 +224,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary d
let(:to) { 10.days.from_now }
before do
Timecop.freeze(5.days.from_now) do
travel_to(5.days.from_now) do
create(:deployment, :success, project: project)
end
end
......
......@@ -29,7 +29,7 @@ RSpec.describe Gitlab::ExpiringSubscriptionMessage do
end
around do |example|
Timecop.freeze(today) do
travel_to(today) do
example.run
end
end
......
......@@ -6,7 +6,7 @@ RSpec.describe Gitlab::Insights::Finders::IssuableFinder do
using RSpec::Parameterized::TableSyntax
around do |example|
Timecop.freeze(Time.utc(2019, 3, 5)) { example.run }
travel_to(Time.utc(2019, 3, 5)) { example.run }
end
let(:base_query) do
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Prometheus::Queries::AdditionalMetricsDeploymentQuery do
around do |example|
Timecop.freeze(Time.local(2008, 9, 1, 12, 0, 0)) { example.run }
travel_to(Time.local(2008, 9, 1, 12, 0, 0)) { example.run }
end
include_examples 'additional custom metrics query' do
......
......@@ -415,7 +415,7 @@ RSpec.describe Vulnerability do
end
it 'returns the count of unresolved, undismissed vulnerabilities for each severity for each day from the start date to the end date' do
Timecop.freeze(Time.zone.parse('2019-10-31')) do
travel_to(Time.zone.parse('2019-10-31')) do
create(:vulnerability, created_at: 5.days.ago, dismissed_at: Date.current, severity: :critical)
create(:vulnerability, created_at: 5.days.ago, dismissed_at: 1.day.ago, severity: :high)
create(:vulnerability, created_at: 4.days.ago, resolved_at: 2.days.ago, severity: :critical)
......
......@@ -15,7 +15,7 @@ RSpec.describe GitlabSubscription do
describe 'default values' do
it do
Timecop.freeze(Date.today + 30) do
travel_to(Date.today + 30) do
expect(subject.start_date).to eq(Date.today)
end
end
......
......@@ -13,7 +13,7 @@ RSpec.describe IssuablesAnalytics do
end
before do
Timecop.freeze(Time.current) do
travel_to(Time.current) do
seed.each_pair do |months_back, issues_count|
create_list(:issue, issues_count, project: project, created_at: months_back.months.ago)
end
......
......@@ -116,7 +116,7 @@ RSpec.describe ProjectImportState, type: :model do
describe 'when create' do
it 'sets next execution timestamp to now' do
Timecop.freeze(Time.current) do
travel_to(Time.current) do
import_state = create(:import_state, :mirror)
expect(import_state.next_execution_timestamp).to be_like_time(Time.current)
......@@ -488,7 +488,7 @@ RSpec.describe ProjectImportState, type: :model do
end
def expect_next_execution_timestamp(import_state, new_timestamp)
Timecop.freeze(timestamp) do
travel_to(timestamp) do
expect do
import_state.set_next_execution_timestamp
end.to change { import_state.next_execution_timestamp }.to eq(new_timestamp)
......@@ -518,7 +518,7 @@ RSpec.describe ProjectImportState, type: :model do
expect(UpdateAllMirrorsWorker).to receive(:perform_async)
Timecop.freeze(timestamp) do
travel_to(timestamp) do
expect { import_state.force_import_job! }.to change(import_state, :next_execution_timestamp).to(5.minutes.ago)
end
end
......@@ -530,7 +530,7 @@ RSpec.describe ProjectImportState, type: :model do
expect(UpdateAllMirrorsWorker).to receive(:perform_async)
Timecop.freeze(timestamp) do
travel_to(timestamp) do
expect { import_state.force_import_job! }.to change(import_state, :retry_count).to(0)
expect(import_state.next_execution_timestamp).to be_like_time(5.minutes.ago)
end
......
......@@ -24,7 +24,7 @@ RSpec.describe SubscriptionPresenter do
it 'remaining days more than 30 is false' do
allow(subscription).to receive(:end_date).and_return(Time.utc(2020, 4, 9, 10).to_date)
Timecop.freeze(today) do
travel_to(today) do
expect(subject).to be false
end
end
......@@ -32,7 +32,7 @@ RSpec.describe SubscriptionPresenter do
it 'remaining days less than 30 is true' do
allow(subscription).to receive(:end_date).and_return(Time.utc(2020, 3, 9, 10).to_date)
Timecop.freeze(today) do
travel_to(today) do
expect(subject).to be true
end
end
......@@ -77,7 +77,7 @@ RSpec.describe SubscriptionPresenter do
let(:end_date) { today + 1.day }
it 'is false' do
Timecop.freeze(today) do
travel_to(today) do
expect(subject).to be false
end
end
......@@ -88,7 +88,7 @@ RSpec.describe SubscriptionPresenter do
let(:end_date) { today - 13.days }
it 'is false' do
Timecop.freeze(today) do
travel_to(today) do
expect(subject).to be false
end
end
......@@ -98,7 +98,7 @@ RSpec.describe SubscriptionPresenter do
let(:end_date) { today - 15.days }
it 'is true' do
Timecop.freeze(today) do
travel_to(today) do
expect(subject).to be true
end
end
......@@ -136,7 +136,7 @@ RSpec.describe SubscriptionPresenter do
it 'returns the number of days between end_date and today' do
allow(subscription).to receive(:end_date).and_return(Time.utc(2020, 3, 9, 10).to_date)
Timecop.freeze(today) do
travel_to(today) do
expect(subject).to eq(2)
end
end
......@@ -144,7 +144,7 @@ RSpec.describe SubscriptionPresenter do
it 'is 0 if expired' do
allow(subscription).to receive(:end_date).and_return(Time.utc(2020, 3, 1, 10).to_date)
Timecop.freeze(today) do
travel_to(today) do
expect(subject).to eq(0)
end
end
......
......@@ -32,7 +32,7 @@ RSpec.describe 'group(fullPath).vulnerabilitiesCountByDayAndSeverity' do
end
it "fetches historical vulnerability data from the start date to the end date for projects in the group and its subgroups" do
Timecop.freeze(Time.zone.parse('2019-10-31')) do
travel_to(Time.zone.parse('2019-10-31')) do
project.add_developer(current_user)
create(:vulnerability, :critical, created_at: 15.days.ago, dismissed_at: 10.days.ago, project: project)
......
......@@ -28,7 +28,7 @@ RSpec.describe 'Query' do
end
it "fetches historical vulnerability data from the start date to the end date for projects on the current user's instance security dashboard" do
Timecop.freeze(Time.zone.parse('2019-10-31')) do
travel_to(Time.zone.parse('2019-10-31')) do
project = create(:project)
current_user = create(:user)
current_user.security_dashboard_projects << project
......
......@@ -13,7 +13,7 @@ RSpec.describe Ci::RetryBuildService do
subject(:service) { described_class.new(project, user) }
let(:new_build) do
Timecop.freeze(1.second.from_now) do
travel_to(1.second.from_now) do
service.reprocess!(build)
end
end
......
......@@ -36,7 +36,7 @@ RSpec.describe EE::AuditEvents::BulkInsertService do
describe '#execute' do
it 'persists audit events' do
Timecop.freeze(timestamp) { service.execute }
travel_to(timestamp) { service.execute }
events_attributes = AuditEvent.all.map { |event| event.attributes.deep_symbolize_keys }
......
......@@ -40,7 +40,7 @@ RSpec.describe EE::AuditEvents::RepositoryPushAuditEventService do
let(:updated_ref) { 'master' }
it 'returns audit event attributes' do
Timecop.freeze(timestamp) do
travel_to(timestamp) do
expect(service.attributes).to eq(attrs)
end
end
......@@ -51,7 +51,7 @@ RSpec.describe EE::AuditEvents::RepositoryPushAuditEventService do
let(:updated_ref) { 'v1.0' }
it 'returns audit event attributes' do
Timecop.freeze(timestamp) do
travel_to(timestamp) do
expect(service.attributes).to eq(attrs)
end
end
......
......@@ -31,7 +31,7 @@ RSpec.describe StartPullMirroringService do
context 'when project mirror has been updated in the last 5 minutes' do
it 'schedules next execution' do
Timecop.freeze(Time.current) do
travel_to(Time.current) do
import_state.update(last_update_at: 3.minutes.ago, last_successful_update_at: 10.minutes.ago)
expect { execute }
......
......@@ -109,7 +109,7 @@ RSpec.describe Admin::SessionsController, :do_not_mock_admin_mode do
# triggering the auth form will request admin mode
get :new
Timecop.freeze(Gitlab::Auth::CurrentUserMode::ADMIN_MODE_REQUESTED_GRACE_PERIOD.from_now) do
travel_to(Gitlab::Auth::CurrentUserMode::ADMIN_MODE_REQUESTED_GRACE_PERIOD.from_now) do
post :create, params: { user: { password: user.password } }
expect(response).to redirect_to(new_admin_session_path)
......
......@@ -416,13 +416,13 @@ RSpec.describe ApplicationController do
end
it 'returns false if the grace period has expired' do
Timecop.freeze(3.hours.from_now) do
travel_to(3.hours.from_now) do
expect(subject).to be_falsey
end
end
it 'returns true if the grace period is still active' do
Timecop.freeze(1.hour.from_now) do
travel_to(1.hour.from_now) do
expect(subject).to be_truthy
end
end
......
......@@ -180,7 +180,7 @@ RSpec.describe 'Contributions Calendar', :js do
before do
push_code_contribution
Timecop.freeze(Date.yesterday) do
travel_to(Date.yesterday) do
Issues::CreateService.new(contributed_project, user, issue_params).execute
end
end
......
......@@ -21,11 +21,11 @@ RSpec.describe 'Branches' do
before do
# Add 4 stale branches
(1..4).reverse_each do |i|
Timecop.freeze((threshold + i).ago) { create_file(message: "a commit in stale-#{i}", branch_name: "stale-#{i}") }
travel_to((threshold + i).ago) { create_file(message: "a commit in stale-#{i}", branch_name: "stale-#{i}") }
end
# Add 6 active branches
(1..6).each do |i|
Timecop.freeze((threshold - i).ago) { create_file(message: "a commit in active-#{i}", branch_name: "active-#{i}") }
travel_to((threshold - i).ago) { create_file(message: "a commit in active-#{i}", branch_name: "active-#{i}") }
end
end
......
......@@ -30,7 +30,7 @@ RSpec.describe Backup::Files do
let(:timestamp) { Time.utc(2017, 3, 22) }
around do |example|
Timecop.freeze(timestamp) { example.run }
travel_to(timestamp) { example.run }
end
describe 'folders with permission' do
......
......@@ -32,7 +32,7 @@ RSpec.describe Banzai::Filter::InlineGrafanaMetricsFilter do
it_behaves_like 'a metrics embed filter'
around do |example|
Timecop.freeze(Time.utc(2019, 3, 17, 13, 10)) { example.run }
travel_to(Time.utc(2019, 3, 17, 13, 10)) { example.run }
end
context 'when grafana is not configured' do
......
......@@ -46,7 +46,7 @@ RSpec.describe Gitlab::AlertManagement::Payload::Generic do
subject { parsed_payload.starts_at }
around do |example|
Timecop.freeze(current_time) { example.run }
travel_to(current_time) { example.run }
end
context 'without start_time' do
......@@ -99,7 +99,7 @@ RSpec.describe Gitlab::AlertManagement::Payload::Generic do
subject { parsed_payload.ends_at }
around do |example|
Timecop.freeze(current_time) { example.run }
travel_to(current_time) { example.run }
end
context 'without end_time' do
......
......@@ -19,7 +19,7 @@ RSpec.describe Gitlab::Analytics::UniqueVisits, :clean_gitlab_redis_shared_state
# Without freezing the time, the test may behave inconsistently
# depending on which day of the week test is run.
reference_time = Time.utc(2020, 6, 1)
Timecop.freeze(reference_time) { example.run }
travel_to(reference_time) { example.run }
end
describe '#track_visit' do
......
......@@ -121,7 +121,7 @@ RSpec.describe Gitlab::Auth::CurrentUserMode, :do_not_mock_admin_mode, :request_
subject.enable_admin_mode!(password: user.password)
expect(subject.admin_mode?).to be(true), 'admin mode is not active in the present'
Timecop.freeze(Gitlab::Auth::CurrentUserMode::MAX_ADMIN_MODE_TIME.from_now) do
travel_to(Gitlab::Auth::CurrentUserMode::MAX_ADMIN_MODE_TIME.from_now) do
# in the future this will be a new request, simulate by clearing the RequestStore
Gitlab::SafeRequestStore.clear!
......
......@@ -312,7 +312,7 @@ RSpec.describe Gitlab::BitbucketImport::Importer do
# attributes later.
existing_label.reload
Timecop.freeze(Time.now + 1.minute) do
travel_to(Time.now + 1.minute) do
importer.execute
label_after_import = project.labels.find(existing_label.id)
......
......@@ -82,7 +82,7 @@ RSpec.describe Gitlab::Ci::CronParser do
context 'when PST (Pacific Standard Time)' do
it 'converts time in server time zone' do
Timecop.freeze(Time.utc(2017, 1, 1)) do
travel_to(Time.utc(2017, 1, 1)) do
expect(subject.hour).to eq(hour_in_utc)
end
end
......@@ -90,7 +90,7 @@ RSpec.describe Gitlab::Ci::CronParser do
context 'when PDT (Pacific Daylight Time)' do
it 'converts time in server time zone' do
Timecop.freeze(Time.utc(2017, 6, 1)) do
travel_to(Time.utc(2017, 6, 1)) do
expect(subject.hour).to eq(hour_in_utc)
end
end
......@@ -117,7 +117,7 @@ RSpec.describe Gitlab::Ci::CronParser do
context 'when CET (Central European Time)' do
it 'converts time in server time zone' do
Timecop.freeze(Time.utc(2017, 1, 1)) do
travel_to(Time.utc(2017, 1, 1)) do
expect(subject.hour).to eq(hour_in_utc)
end
end
......@@ -125,7 +125,7 @@ RSpec.describe Gitlab::Ci::CronParser do
context 'when CEST (Central European Summer Time)' do
it 'converts time in server time zone' do
Timecop.freeze(Time.utc(2017, 6, 1)) do
travel_to(Time.utc(2017, 6, 1)) do
expect(subject.hour).to eq(hour_in_utc)
end
end
......@@ -152,7 +152,7 @@ RSpec.describe Gitlab::Ci::CronParser do
context 'when EST (Eastern Standard Time)' do
it 'converts time in server time zone' do
Timecop.freeze(Time.utc(2017, 1, 1)) do
travel_to(Time.utc(2017, 1, 1)) do
expect(subject.hour).to eq(hour_in_utc)
end
end
......@@ -160,7 +160,7 @@ RSpec.describe Gitlab::Ci::CronParser do
context 'when EDT (Eastern Daylight Time)' do
it 'converts time in server time zone' do
Timecop.freeze(Time.utc(2017, 6, 1)) do
travel_to(Time.utc(2017, 6, 1)) do
expect(subject.hour).to eq(hour_in_utc)
end
end
......@@ -174,7 +174,7 @@ RSpec.describe Gitlab::Ci::CronParser do
# (e.g. America/Chicago) at the start of the test. Stubbing
# TZ doesn't appear to be enough.
it 'generates day without TZInfo::AmbiguousTime error' do
Timecop.freeze(Time.utc(2020, 1, 1)) do
travel_to(Time.utc(2020, 1, 1)) do
expect(subject.year).to eq(year)
expect(subject.month).to eq(12)
expect(subject.day).to eq(1)
......
......@@ -7,7 +7,7 @@ require 'gitlab/danger/roulette'
RSpec.describe Gitlab::Danger::Roulette do
around do |example|
Timecop.freeze(Time.utc(2020, 06, 22, 10)) { example.run }
travel_to(Time.utc(2020, 06, 22, 10)) { example.run }
end
let(:backend_available) { true }
......
......@@ -149,7 +149,7 @@ RSpec.describe Gitlab::Danger::Teammate do
describe '#local_hour' do
around do |example|
Timecop.freeze(Time.utc(2020, 6, 23, 10)) { example.run }
travel_to(Time.utc(2020, 6, 23, 10)) { example.run }
end
context 'when author is given' do
......
......@@ -85,7 +85,7 @@ RSpec.describe Gitlab::Database::BackgroundMigrationJob do
let!(:job1) { create(:background_migration_job, :succeeded, created_at: initial_time, updated_at: initial_time) }
it 'does not update non-pending jobs' do
Timecop.freeze(initial_time + 1.day) do
travel_to(initial_time + 1.day) do
expect { described_class.mark_all_as_succeeded('TestJob', [1, 100]) }
.to change { described_class.succeeded.count }.from(1).to(2)
end
......
......@@ -52,7 +52,7 @@ RSpec.describe Gitlab::Database::ObsoleteIgnoredColumns do
describe '#execute' do
it 'returns a list of class names and columns pairs' do
Timecop.freeze(REMOVE_DATE) do
travel_to(REMOVE_DATE) do
expect(subject.execute).to eq([
['Testing::A', {
'unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0'),
......
......@@ -47,7 +47,7 @@ RSpec.describe Gitlab::Database::Partitioning::MonthlyStrategy do
let(:partitioning_key) { :created_at }
around do |example|
Timecop.freeze(Date.parse('2020-08-22')) { example.run }
travel_to(Date.parse('2020-08-22')) { example.run }
end
context 'with existing partitions' do
......
......@@ -213,7 +213,7 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe
it 'creates partitions including the next month from today' do
today = Date.new(2020, 5, 8)
Timecop.freeze(today) do
travel_to(today) do
migration.partition_table_by_date source_table, partition_column, min_date: min_date
expect_range_partitions_for(partitioned_table, {
......@@ -233,7 +233,7 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHe
context 'without min_date, max_date' do
it 'creates partitions for the current and next month' do
current_date = Date.new(2020, 05, 22)
Timecop.freeze(current_date.to_time) do
travel_to(current_date.to_time) do
migration.partition_table_by_date source_table, partition_column
expect_range_partitions_for(partitioned_table, {
......
......@@ -85,9 +85,9 @@ RSpec.describe Gitlab::Git::Branch, :seed_helper do
}
end
let(:stale_sha) { Timecop.freeze(Gitlab::Git::Branch::STALE_BRANCH_THRESHOLD.ago - 5.days) { create_commit } }
let(:active_sha) { Timecop.freeze(Gitlab::Git::Branch::STALE_BRANCH_THRESHOLD.ago + 5.days) { create_commit } }
let(:future_sha) { Timecop.freeze(100.days.since) { create_commit } }
let(:stale_sha) { travel_to(Gitlab::Git::Branch::STALE_BRANCH_THRESHOLD.ago - 5.days) { create_commit } }
let(:active_sha) { travel_to(Gitlab::Git::Branch::STALE_BRANCH_THRESHOLD.ago + 5.days) { create_commit } }
let(:future_sha) { travel_to(100.days.since) { create_commit } }
before do
repository.create_branch('stale-1', stale_sha)
......
......@@ -26,7 +26,7 @@ RSpec.describe Gitlab::GrapeLogging::Loggers::QueueDurationLogger do
end
it 'returns the correct duration in seconds' do
Timecop.freeze(start_time) do
travel_to(start_time) do
subject.before
expect(subject.parameters(mock_request, nil)).to eq( { 'queue_duration_s': 1.hour.to_f })
......
......@@ -104,7 +104,7 @@ RSpec.describe Gitlab::LfsToken, :clean_gitlab_redis_shared_state do
# Needs to be at least LfsToken::DEFAULT_EXPIRE_TIME + 60 seconds
# in order to check whether it is valid 1 minute after it has expired
Timecop.freeze(Time.now + described_class::DEFAULT_EXPIRE_TIME + 60) do
travel_to(Time.now + described_class::DEFAULT_EXPIRE_TIME + 60) do
expect(lfs_token.token_valid?(expired_token)).to be false
end
end
......
......@@ -38,7 +38,7 @@ RSpec.describe Gitlab::Middleware::RailsQueueDuration do
expect(transaction).to receive(:observe).with(:gitlab_rails_queue_duration_seconds, 1)
Timecop.freeze(Time.at(3)) do
travel_to(Time.at(3)) do
expect(middleware.call(env)).to eq('yay')
end
end
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Prometheus::Queries::AdditionalMetricsDeploymentQuery do
around do |example|
Timecop.freeze(Time.local(2008, 9, 1, 12, 0, 0)) { example.run }
travel_to(Time.local(2008, 9, 1, 12, 0, 0)) { example.run }
end
include_examples 'additional metrics query' do
......
......@@ -11,7 +11,7 @@ RSpec.describe Gitlab::Prometheus::Queries::DeploymentQuery do
around do |example|
time_without_subsecond_values = Time.local(2008, 9, 1, 12, 0, 0)
Timecop.freeze(time_without_subsecond_values) { example.run }
travel_to(time_without_subsecond_values) { example.run }
end
it 'sends appropriate queries to prometheus' do
......
......@@ -47,7 +47,7 @@ RSpec.describe Gitlab::Tracking do
end
around do |example|
Timecop.freeze(timestamp) { example.run }
travel_to(timestamp) { example.run }
end
before do
......
......@@ -15,7 +15,7 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
# depending on which day of the week test is run.
# Monday 6th of June
reference_time = Time.utc(2020, 6, 1)
Timecop.freeze(reference_time) { example.run }
travel_to(reference_time) { example.run }
end
describe '.categories' do
......
......@@ -7,7 +7,7 @@ RSpec.describe Grafana::TimeWindow do
let(:to) { '1552828200000' }
around do |example|
Timecop.freeze(Time.utc(2019, 3, 17, 13, 10)) { example.run }
travel_to(Time.utc(2019, 3, 17, 13, 10)) { example.run }
end
describe '#formatted' do
......@@ -37,7 +37,7 @@ RSpec.describe Grafana::RangeWithDefaults do
let(:to) { Grafana::Timestamp.from_ms_since_epoch('1552828200000') }
around do |example|
Timecop.freeze(Time.utc(2019, 3, 17, 13, 10)) { example.run }
travel_to(Time.utc(2019, 3, 17, 13, 10)) { example.run }
end
describe '#to_hash' do
......@@ -82,7 +82,7 @@ RSpec.describe Grafana::Timestamp do
let(:timestamp) { Time.at(1552799400) }
around do |example|
Timecop.freeze(Time.utc(2019, 3, 17, 13, 10)) { example.run }
travel_to(Time.utc(2019, 3, 17, 13, 10)) { example.run }
end
describe '#formatted' do
......
......@@ -37,7 +37,7 @@ RSpec.describe BackfillStatusPagePublishedIncidents, :migration do
end
it 'creates a StatusPage::PublishedIncident record for each published issue' do
Timecop.freeze(current_time) do
travel_to(current_time) do
expect(incidents.all).to be_empty
migrate!
......
......@@ -11,7 +11,7 @@ RSpec.describe Ci::FreezePeriodStatus do
shared_examples 'within freeze period' do |time|
it 'is frozen' do
Timecop.freeze(time) do
travel_to(time) do
expect(subject).to be_truthy
end
end
......@@ -19,7 +19,7 @@ RSpec.describe Ci::FreezePeriodStatus do
shared_examples 'outside freeze period' do |time|
it 'is not frozen' do
Timecop.freeze(time) do
travel_to(time) do
expect(subject).to be_falsy
end
end
......
......@@ -56,7 +56,7 @@ RSpec.describe Ci::PipelineSchedule do
subject { described_class.runnable_schedules }
let!(:pipeline_schedule) do
Timecop.freeze(1.day.ago) do
travel_to(1.day.ago) do
create(:ci_pipeline_schedule, :hourly)
end
end
......@@ -118,7 +118,7 @@ RSpec.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.zone.parse("2019-06-01 12:18:00+0000")) do
travel_to(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
......
......@@ -45,7 +45,7 @@ RSpec.describe CiPlatformMetric do
let(:tomorrow) { today + 1.day }
it 'inserts platform target counts for that day' do
Timecop.freeze(today) do
travel_to(today) do
create(:ci_variable, key: described_class::CI_VARIABLE_KEY, value: 'ECS')
create(:ci_variable, key: described_class::CI_VARIABLE_KEY, value: 'ECS')
create(:ci_variable, key: described_class::CI_VARIABLE_KEY, value: 'FARGATE')
......@@ -53,7 +53,7 @@ RSpec.describe CiPlatformMetric do
create(:ci_variable, key: described_class::CI_VARIABLE_KEY, value: 'FARGATE')
described_class.insert_auto_devops_platform_targets!
end
Timecop.freeze(tomorrow) do
travel_to(tomorrow) do
create(:ci_variable, key: described_class::CI_VARIABLE_KEY, value: 'FARGATE')
described_class.insert_auto_devops_platform_targets!
end
......@@ -69,7 +69,7 @@ RSpec.describe CiPlatformMetric do
let(:today) { Time.zone.local(1982, 4, 24) }
it 'ignores those values' do
Timecop.freeze(today) do
travel_to(today) do
create(:ci_variable, key: described_class::CI_VARIABLE_KEY, value: 'ECS')
create(:ci_variable, key: described_class::CI_VARIABLE_KEY, value: 'FOO')
create(:ci_variable, key: described_class::CI_VARIABLE_KEY, value: 'BAR')
......
......@@ -553,13 +553,13 @@ RSpec.describe Discussion, ResolvableDiscussion do
let(:time) { Time.current.utc }
before do
Timecop.freeze(time - 1.second) do
travel_to(time - 1.second) do
first_note.resolve!(current_user)
end
Timecop.freeze(time) do
travel_to(time) do
third_note.resolve!(current_user)
end
Timecop.freeze(time + 1.second) do
travel_to(time + 1.second) do
second_note.resolve!(current_user)
end
end
......
......@@ -35,7 +35,7 @@ RSpec.describe Schedulable do
context 'for a pipeline_schedule' do
# let! is used to reset the next_run_at value before each spec
let(:object) do
Timecop.freeze(1.day.ago) do
travel_to(1.day.ago) do
create(:ci_pipeline_schedule, :hourly)
end
end
......
......@@ -16,7 +16,7 @@ RSpec.describe ImportFailure do
it 'orders hard failures by newest first' do
older_failure = hard_failure.dup
Timecop.freeze(1.day.before(hard_failure.created_at)) do
travel_to(1.day.before(hard_failure.created_at)) do
older_failure.save!
expect(ImportFailure.hard_failures_by_correlation_id(correlation_id)).to eq([hard_failure, older_failure])
......
......@@ -38,7 +38,7 @@ RSpec.describe Issue::Metrics do
context "milestones" do
it "records the first time an issue is associated with a milestone" do
time = Time.current
Timecop.freeze(time) { subject.update(milestone: create(:milestone, project: project)) }
travel_to(time) { subject.update(milestone: create(:milestone, project: project)) }
metrics = subject.metrics
expect(metrics).to be_present
......@@ -47,9 +47,9 @@ RSpec.describe Issue::Metrics do
it "does not record the second time an issue is associated with a milestone" do
time = Time.current
Timecop.freeze(time) { subject.update(milestone: create(:milestone, project: project)) }
Timecop.freeze(time + 2.hours) { subject.update(milestone: nil) }
Timecop.freeze(time + 6.hours) { subject.update(milestone: create(:milestone, project: project)) }
travel_to(time) { subject.update(milestone: create(:milestone, project: project)) }
travel_to(time + 2.hours) { subject.update(milestone: nil) }
travel_to(time + 6.hours) { subject.update(milestone: create(:milestone, project: project)) }
metrics = subject.metrics
expect(metrics).to be_present
......@@ -61,7 +61,7 @@ RSpec.describe Issue::Metrics do
it "records the first time an issue is associated with a list label" do
list_label = create(:list).label
time = Time.current
Timecop.freeze(time) { subject.update(label_ids: [list_label.id]) }
travel_to(time) { subject.update(label_ids: [list_label.id]) }
metrics = subject.metrics
expect(metrics).to be_present
......@@ -71,9 +71,9 @@ RSpec.describe Issue::Metrics do
it "does not record the second time an issue is associated with a list label" do
time = Time.current
first_list_label = create(:list).label
Timecop.freeze(time) { subject.update(label_ids: [first_list_label.id]) }
travel_to(time) { subject.update(label_ids: [first_list_label.id]) }
second_list_label = create(:list).label
Timecop.freeze(time + 5.hours) { subject.update(label_ids: [second_list_label.id]) }
travel_to(time + 5.hours) { subject.update(label_ids: [second_list_label.id]) }
metrics = subject.metrics
expect(metrics).to be_present
......
......@@ -48,7 +48,7 @@ RSpec.describe ProjectFeatureUsage, type: :model do
feature_usage.log_jira_dvcs_integration_usage
first_logged_at = feature_usage.jira_dvcs_cloud_last_sync_at
Timecop.freeze(1.hour.from_now) do
travel_to(1.hour.from_now) do
ProjectFeatureUsage.new(project_id: project.id).log_jira_dvcs_integration_usage
end
......
......@@ -443,7 +443,7 @@ RSpec.describe Todo do
it 'updates updated_at' do
create(:todo, :pending)
Timecop.freeze(1.day.from_now) do
travel_to(1.day.from_now) do
expected_update_date = Time.current.utc
ids = described_class.batch_update(state: :done)
......
......@@ -3902,7 +3902,7 @@ RSpec.describe User do
it 'changes the namespace (just to compare to when username is not changed)' do
expect do
Timecop.freeze(1.second.from_now) do
travel_to(1.second.from_now) do
user.update!(username: new_username)
end
end.to change { user.namespace.updated_at }
......
......@@ -259,7 +259,7 @@ RSpec.describe API::Releases do
end
it '#collected_at' do
Timecop.freeze(Time.now.round) do
travel_to(Time.now.round) do
get api("/projects/#{project.id}/releases/v0.1", maintainer)
expect(json_response['evidences'].first['collected_at'].to_datetime.to_i).to be_within(1.minute).of(release.evidences.first.created_at.to_i)
......@@ -476,7 +476,7 @@ RSpec.describe API::Releases do
it 'sets the released_at to the current time if the released_at parameter is not provided' do
now = Time.zone.parse('2015-08-25 06:00:00Z')
Timecop.freeze(now) do
travel_to(now) do
post api("/projects/#{project.id}/releases", maintainer), params: params
expect(project.releases.last.released_at).to eq(now)
......
......@@ -12,7 +12,7 @@ RSpec.describe 'value stream analytics events' do
project.add_developer(user)
3.times do |count|
Timecop.freeze(Time.now + count.days) do
travel_to(Time.now + count.days) do
create_cycle
end
end
......
......@@ -24,7 +24,7 @@ RSpec.describe 'Request Profiler' do
time = Time.now
path = "/#{project.full_path}"
Timecop.freeze(time) do
travel_to(time) do
get path, params: {}, headers: { 'X-Profile-Token' => Gitlab::RequestProfiler.profile_token, 'X-Profile-Mode' => profile_type }
end
......
......@@ -154,7 +154,7 @@ RSpec.describe Ci::RetryBuildService do
describe '#execute' do
let(:new_build) do
Timecop.freeze(1.second.from_now) do
travel_to(1.second.from_now) do
service.execute(build)
end
end
......@@ -257,7 +257,7 @@ RSpec.describe Ci::RetryBuildService do
describe '#reprocess' do
let(:new_build) do
Timecop.freeze(1.second.from_now) do
travel_to(1.second.from_now) do
service.reprocess!(build)
end
end
......
......@@ -269,14 +269,14 @@ RSpec.describe Deployments::AfterCreateService do
it "does not overwrite the older 'first_deployed_to_production_at' time" do
# Previous deploy
time = 5.minutes.from_now
Timecop.freeze(time) { service.execute }
travel_to(time) { service.execute }
expect(merge_request.reload.metrics.merged_at).to be < merge_request.reload.metrics.first_deployed_to_production_at
previous_time = merge_request.reload.metrics.first_deployed_to_production_at
# Current deploy
Timecop.freeze(time + 12.hours) { service.execute }
travel_to(time + 12.hours) { service.execute }
expect(merge_request.reload.metrics.first_deployed_to_production_at).to eq(previous_time)
end
......
......@@ -650,7 +650,7 @@ RSpec.describe Issues::UpdateService, :mailer do
context 'when the labels change' do
before do
Timecop.freeze(1.minute.from_now) do
travel_to(1.minute.from_now) do
update_issue(label_ids: [label.id])
end
end
......
......@@ -8,7 +8,7 @@ RSpec.describe Keys::LastUsedService do
key = create(:key, last_used_at: 1.year.ago)
time = Time.zone.now
Timecop.freeze(time) { described_class.new(key).execute }
travel_to(time) { described_class.new(key).execute }
expect(key.reload.last_used_at).to be_like_time(time)
end
......
......@@ -583,7 +583,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
context 'when the labels change' do
before do
Timecop.freeze(1.minute.from_now) do
travel_to(1.minute.from_now) do
update_merge_request({ label_ids: [label.id] })
end
end
......
......@@ -437,7 +437,7 @@ RSpec.describe Notes::CreateService do
expect do
existing_note
Timecop.freeze(Time.current + 1.minute) { subject }
travel_to(Time.current + 1.minute) { subject }
existing_note.reload
end.to change { existing_note.type }.from(nil).to('DiscussionNote')
......
......@@ -42,7 +42,7 @@ RSpec.describe Notes::UpdateService do
end
it 'does not update the note when params is blank' do
Timecop.freeze(1.day.from_now) do
travel_to(1.day.from_now) do
expect { update_note({}) }.not_to change { note.reload.updated_at }
end
end
......
......@@ -59,7 +59,7 @@ RSpec.shared_examples 'known sign in' do
it 'notifies the user when the cookie is expired' do
stub_cookie
Timecop.freeze((KnownSignIn::KNOWN_SIGN_IN_COOKIE_EXPIRY + 1.day).from_now) do
travel_to((KnownSignIn::KNOWN_SIGN_IN_COOKIE_EXPIRY + 1.day).from_now) do
expect_next_instance_of(NotificationService) do |instance|
expect(instance).to receive(:unknown_sign_in)
end
......
......@@ -13,8 +13,8 @@ RSpec.shared_examples 'throttled touch' do
first_updated_at = Time.zone.now - (ThrottledTouch::TOUCH_INTERVAL * 2)
second_updated_at = Time.zone.now - (ThrottledTouch::TOUCH_INTERVAL * 1.5)
Timecop.freeze(first_updated_at) { subject.touch }
Timecop.freeze(second_updated_at) { subject.touch }
travel_to(first_updated_at) { subject.touch }
travel_to(second_updated_at) { subject.touch }
expect(subject.updated_at).to be_like_time(first_updated_at)
end
......
......@@ -290,7 +290,7 @@ RSpec.describe PostReceive do
# MySQL drops milliseconds in the timestamps, so advance at least
# a second to ensure we see changes.
Timecop.freeze(1.second.from_now) do
travel_to(1.second.from_now) do
expect do
perform
project.reload
......
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