Skip to content
Snippets Groups Projects
Unverified Commit 1c9243a8 authored by Alishan Ladhani's avatar Alishan Ladhani Committed by Peter Leitzen
Browse files

Replace calls to `Timecop.freeze` with `travel_to`

- In cases where `Timecop.freeze` is called with a
  specific time
- Only in spec directory
parent 73c45fac
No related branches found
No related tags found
No related merge requests found
Showing
with 48 additions and 48 deletions
Loading
Loading
@@ -18,7 +18,7 @@
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)
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@
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)
Loading
Loading
Loading
Loading
@@ -74,7 +74,7 @@
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
Loading
Loading
Loading
Loading
@@ -13,10 +13,10 @@
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
Loading
Loading
@@ -31,7 +31,7 @@
 
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
Loading
Loading
@@ -41,7 +41,7 @@
 
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 }
Loading
Loading
@@ -112,9 +112,9 @@
 
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
Loading
Loading
@@ -126,10 +126,10 @@
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
Loading
Loading
@@ -144,7 +144,7 @@
 
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
Loading
Loading
@@ -156,7 +156,7 @@
 
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
Loading
Loading
@@ -179,7 +179,7 @@
 
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
Loading
Loading
@@ -207,7 +207,7 @@
end
 
before do
Timecop.freeze(5.days.ago) do
travel_to(5.days.ago) do
create(:deployment, :success, project: project)
end
end
Loading
Loading
@@ -224,7 +224,7 @@
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
Loading
Loading
Loading
Loading
@@ -29,7 +29,7 @@
end
 
around do |example|
Timecop.freeze(today) do
travel_to(today) do
example.run
end
end
Loading
Loading
Loading
Loading
@@ -6,7 +6,7 @@
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
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@
 
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
Loading
Loading
Loading
Loading
@@ -415,7 +415,7 @@
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)
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@
 
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
Loading
Loading
Loading
Loading
@@ -13,7 +13,7 @@
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
Loading
Loading
Loading
Loading
@@ -116,7 +116,7 @@
 
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)
Loading
Loading
@@ -488,7 +488,7 @@
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)
Loading
Loading
@@ -518,7 +518,7 @@ def expect_next_execution_timestamp(import_state, new_timestamp)
 
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
Loading
Loading
@@ -530,7 +530,7 @@ def expect_next_execution_timestamp(import_state, new_timestamp)
 
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
Loading
Loading
Loading
Loading
@@ -24,7 +24,7 @@
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
Loading
Loading
@@ -32,7 +32,7 @@
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
Loading
Loading
@@ -77,7 +77,7 @@
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
Loading
Loading
@@ -88,7 +88,7 @@
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
Loading
Loading
@@ -98,7 +98,7 @@
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
Loading
Loading
@@ -136,7 +136,7 @@
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
Loading
Loading
@@ -144,7 +144,7 @@
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
Loading
Loading
Loading
Loading
@@ -32,7 +32,7 @@
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)
Loading
Loading
Loading
Loading
@@ -28,7 +28,7 @@
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
Loading
Loading
Loading
Loading
@@ -13,7 +13,7 @@
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
Loading
Loading
Loading
Loading
@@ -36,7 +36,7 @@
 
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 }
 
Loading
Loading
Loading
Loading
@@ -40,7 +40,7 @@
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
Loading
Loading
@@ -51,7 +51,7 @@
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
Loading
Loading
Loading
Loading
@@ -31,7 +31,7 @@
 
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 }
Loading
Loading
Loading
Loading
@@ -109,7 +109,7 @@
# 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)
Loading
Loading
Loading
Loading
@@ -416,13 +416,13 @@ def index
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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment