diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-19 09:08:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-19 09:08:03 +0300 |
commit | 4e81d9c050bfea4c866329155c17b929d7381340 (patch) | |
tree | 70fd5d3445f0b285650e068a6e99e970ceee5e00 /spec/services | |
parent | fdfde5a37a82274d7babf2519fc802c03e728622 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
25 files changed, 40 insertions, 38 deletions
diff --git a/spec/services/auth/container_registry_authentication_service_spec.rb b/spec/services/auth/container_registry_authentication_service_spec.rb index 75ffdd80268..70eb35f0826 100644 --- a/spec/services/auth/container_registry_authentication_service_spec.rb +++ b/spec/services/auth/container_registry_authentication_service_spec.rb @@ -35,11 +35,11 @@ describe Auth::ContainerRegistryAuthenticationService do it { expect(payload).to include('access') } context 'a expirable' do - let(:expires_at) { Time.at(payload['exp']) } + let(:expires_at) { Time.zone.at(payload['exp']) } let(:expire_delay) { 10 } context 'for default configuration' do - it { expect(expires_at).not_to be_within(2.seconds).of(Time.now + expire_delay.minutes) } + it { expect(expires_at).not_to be_within(2.seconds).of(Time.current + expire_delay.minutes) } end context 'for changed configuration' do @@ -47,7 +47,7 @@ describe Auth::ContainerRegistryAuthenticationService do stub_application_setting(container_registry_token_expire_delay: expire_delay) end - it { expect(expires_at).to be_within(2.seconds).of(Time.now + expire_delay.minutes) } + it { expect(expires_at).to be_within(2.seconds).of(Time.current + expire_delay.minutes) } end end end diff --git a/spec/services/boards/issues/list_service_spec.rb b/spec/services/boards/issues/list_service_spec.rb index 33538703e92..c46ab004af6 100644 --- a/spec/services/boards/issues/list_service_spec.rb +++ b/spec/services/boards/issues/list_service_spec.rb @@ -87,7 +87,7 @@ describe Boards::Issues::ListService do let!(:opened_issue1) { create(:labeled_issue, project: project, milestone: m1, title: 'Issue 1', labels: [bug]) } let!(:opened_issue2) { create(:labeled_issue, project: project, milestone: m2, title: 'Issue 2', labels: [p2, p2_project]) } let!(:opened_issue3) { create(:labeled_issue, project: project_archived, milestone: m1, title: 'Issue 3', labels: [bug]) } - let!(:reopened_issue1) { create(:issue, state: 'opened', project: project, title: 'Reopened Issue 1', closed_at: Time.now ) } + let!(:reopened_issue1) { create(:issue, state: 'opened', project: project, title: 'Reopened Issue 1', closed_at: Time.current ) } let!(:list1_issue1) { create(:labeled_issue, project: project, milestone: m1, labels: [p2, p2_project, development]) } let!(:list1_issue2) { create(:labeled_issue, project: project, milestone: m2, labels: [development]) } diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb index 2da1350e2af..c0f854df9b7 100644 --- a/spec/services/ci/register_job_service_spec.rb +++ b/spec/services/ci/register_job_service_spec.rb @@ -571,7 +571,7 @@ module Ci end describe '#register_success' do - let!(:current_time) { Time.new(2018, 4, 5, 14, 0, 0) } + let!(:current_time) { Time.zone.local(2018, 4, 5, 14, 0, 0) } let!(:attempt_counter) { double('Gitlab::Metrics::NullMetric') } let!(:job_queue_duration_seconds) { double('Gitlab::Metrics::NullMetric') } diff --git a/spec/services/clusters/applications/schedule_update_service_spec.rb b/spec/services/clusters/applications/schedule_update_service_spec.rb index 0764f5b6a97..eb1006ce8e0 100644 --- a/spec/services/clusters/applications/schedule_update_service_spec.rb +++ b/spec/services/clusters/applications/schedule_update_service_spec.rb @@ -13,10 +13,10 @@ describe Clusters::Applications::ScheduleUpdateService do context 'when application is able to be updated' do context 'when the application was recently scheduled' do it 'schedules worker with a backoff delay' do - application = create(:clusters_applications_prometheus, :installed, last_update_started_at: Time.now + 5.minutes) + application = create(:clusters_applications_prometheus, :installed, last_update_started_at: Time.current + 5.minutes) service = described_class.new(application, project) - expect(::ClusterUpdateAppWorker).to receive(:perform_in).with(described_class::BACKOFF_DELAY, application.name, application.id, project.id, Time.now).once + expect(::ClusterUpdateAppWorker).to receive(:perform_in).with(described_class::BACKOFF_DELAY, application.name, application.id, project.id, Time.current).once service.execute end @@ -27,7 +27,7 @@ describe Clusters::Applications::ScheduleUpdateService do application = create(:clusters_applications_prometheus, :installed) service = described_class.new(application, project) - expect(::ClusterUpdateAppWorker).to receive(:perform_async).with(application.name, application.id, project.id, Time.now).once + expect(::ClusterUpdateAppWorker).to receive(:perform_async).with(application.name, application.id, project.id, Time.current).once service.execute end diff --git a/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb b/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb index 9238f7debd0..e9f7f015293 100644 --- a/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb +++ b/spec/services/clusters/kubernetes/configure_istio_ingress_service_spec.rb @@ -120,8 +120,8 @@ describe Clusters::Kubernetes::ConfigureIstioIngressService, '#execute' do expect(certificate.subject.to_s).to include(serverless_domain_cluster.knative.hostname) - expect(certificate.not_before).to be_within(1.minute).of(Time.now) - expect(certificate.not_after).to be_within(1.minute).of(Time.now + 1000.years) + expect(certificate.not_before).to be_within(1.minute).of(Time.current) + expect(certificate.not_after).to be_within(1.minute).of(Time.current + 1000.years) expect(WebMock).to have_requested(:put, api_url + '/api/v1/namespaces/istio-system/secrets/istio-ingressgateway-ca-certs').with( body: hash_including( diff --git a/spec/services/cohorts_service_spec.rb b/spec/services/cohorts_service_spec.rb index 38f441fbc4d..b2f82a1153c 100644 --- a/spec/services/cohorts_service_spec.rb +++ b/spec/services/cohorts_service_spec.rb @@ -13,7 +13,7 @@ describe CohortsService do 6.times do |months_ago| months_ago_time = (months_ago * 2).months.ago - create(:user, created_at: months_ago_time, last_activity_on: Time.now) + create(:user, created_at: months_ago_time, last_activity_on: Time.current) create(:user, created_at: months_ago_time, last_activity_on: months_ago_time) end diff --git a/spec/services/git/branch_push_service_spec.rb b/spec/services/git/branch_push_service_spec.rb index d5ffe4d4536..6ecc1a62ff3 100644 --- a/spec/services/git/branch_push_service_spec.rb +++ b/spec/services/git/branch_push_service_spec.rb @@ -315,7 +315,7 @@ describe Git::BranchPushService, services: true do let(:issue) { create :issue, project: project } let(:commit_author) { create :user } let(:commit) { project.commit } - let(:commit_time) { Time.now } + let(:commit_time) { Time.current } before do project.add_developer(commit_author) diff --git a/spec/services/incident_management/create_issue_service_spec.rb b/spec/services/incident_management/create_issue_service_spec.rb index bef8b2e5de0..5a3721f00b8 100644 --- a/spec/services/incident_management/create_issue_service_spec.rb +++ b/spec/services/incident_management/create_issue_service_spec.rb @@ -6,7 +6,7 @@ describe IncidentManagement::CreateIssueService do let(:project) { create(:project, :repository, :private) } let_it_be(:user) { User.alert_bot } let(:service) { described_class.new(project, alert_payload) } - let(:alert_starts_at) { Time.now } + let(:alert_starts_at) { Time.current } let(:alert_title) { 'TITLE' } let(:alert_annotations) { { title: alert_title } } @@ -302,7 +302,7 @@ describe IncidentManagement::CreateIssueService do private - def build_alert_payload(annotations: {}, starts_at: Time.now) + def build_alert_payload(annotations: {}, starts_at: Time.current) { 'annotations' => annotations.stringify_keys }.tap do |payload| diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb index 86377e054c1..6fc1928d47b 100644 --- a/spec/services/issues/close_service_spec.rb +++ b/spec/services/issues/close_service_spec.rb @@ -146,7 +146,7 @@ describe Issues::CloseService do context 'when `metrics.first_mentioned_in_commit_at` is already set' do before do - issue.metrics.update!(first_mentioned_in_commit_at: Time.now) + issue.metrics.update!(first_mentioned_in_commit_at: Time.current) end it 'does not update the metrics' do diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 556a0d605d5..80039049bc3 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -510,7 +510,7 @@ describe Issues::UpdateService, :mailer do end it 'updates updated_at' do - expect(issue.reload.updated_at).to be > Time.now + expect(issue.reload.updated_at).to be > Time.current end end end diff --git a/spec/services/merge_requests/merge_service_spec.rb b/spec/services/merge_requests/merge_service_spec.rb index fa7f745d8a0..bcad822b1dc 100644 --- a/spec/services/merge_requests/merge_service_spec.rb +++ b/spec/services/merge_requests/merge_service_spec.rb @@ -118,7 +118,7 @@ describe MergeRequests::MergeService do it 'closes GitLab issue tracker issues' do issue = create :issue, project: project - commit = instance_double('commit', safe_message: "Fixes #{issue.to_reference}", date: Time.now, authored_date: Time.now) + commit = instance_double('commit', safe_message: "Fixes #{issue.to_reference}", date: Time.current, authored_date: Time.current) allow(merge_request).to receive(:commits).and_return([commit]) merge_request.cache_merge_request_closes_issues! diff --git a/spec/services/merge_requests/refresh_service_spec.rb b/spec/services/merge_requests/refresh_service_spec.rb index 3e252212cdb..94e65d895ac 100644 --- a/spec/services/merge_requests/refresh_service_spec.rb +++ b/spec/services/merge_requests/refresh_service_spec.rb @@ -635,7 +635,7 @@ describe MergeRequests::RefreshService do references: [issue], author_name: commit_author.name, author_email: commit_author.email, - committed_date: Time.now + committed_date: Time.current ) allow_any_instance_of(MergeRequest).to receive(:commits).and_return(CommitCollection.new(@project, [commit], 'feature')) diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb index bcc7a27802d..2b934b24757 100644 --- a/spec/services/merge_requests/update_service_spec.rb +++ b/spec/services/merge_requests/update_service_spec.rb @@ -453,7 +453,7 @@ describe MergeRequests::UpdateService, :mailer do end it 'updates updated_at' do - expect(merge_request.reload.updated_at).to be > Time.now + expect(merge_request.reload.updated_at).to be > Time.current end end diff --git a/spec/services/note_summary_spec.rb b/spec/services/note_summary_spec.rb index aa4e41f4d8c..038e0cdb703 100644 --- a/spec/services/note_summary_spec.rb +++ b/spec/services/note_summary_spec.rb @@ -25,18 +25,18 @@ describe NoteSummary do it 'returns note hash' do Timecop.freeze do expect(create_note_summary.note).to eq(noteable: noteable, project: project, author: user, note: 'note', - created_at: Time.now) + created_at: Time.current) end end context 'when noteable is a commit' do - let(:noteable) { build(:commit, system_note_timestamp: Time.at(43)) } + let(:noteable) { build(:commit, system_note_timestamp: Time.zone.at(43)) } it 'returns note hash specific to commit' do expect(create_note_summary.note).to eq( noteable: nil, project: project, author: user, note: 'note', noteable_type: 'Commit', commit_id: noteable.id, - created_at: Time.at(43) + created_at: Time.zone.at(43) ) end end diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 2ae4fbeb900..39d6fd26e31 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -425,7 +425,7 @@ describe Notes::CreateService do expect do existing_note - Timecop.freeze(Time.now + 1.minute) { subject } + Timecop.freeze(Time.current + 1.minute) { subject } existing_note.reload end.to change { existing_note.type }.from(nil).to('DiscussionNote') diff --git a/spec/services/pages_domains/obtain_lets_encrypt_certificate_service_spec.rb b/spec/services/pages_domains/obtain_lets_encrypt_certificate_service_spec.rb index 63fd0978c97..22fcc6b9a79 100644 --- a/spec/services/pages_domains/obtain_lets_encrypt_certificate_service_spec.rb +++ b/spec/services/pages_domains/obtain_lets_encrypt_certificate_service_spec.rb @@ -119,7 +119,7 @@ describe PagesDomains::ObtainLetsEncryptCertificateService do cert = OpenSSL::X509::Certificate.new cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject) - cert.not_before = Time.now + cert.not_before = Time.current cert.not_after = 1.year.from_now cert.public_key = key.public_key cert.serial = 0x0 diff --git a/spec/services/projects/alerting/notify_service_spec.rb b/spec/services/projects/alerting/notify_service_spec.rb index 5ef276e1f02..b88f0ef5149 100644 --- a/spec/services/projects/alerting/notify_service_spec.rb +++ b/spec/services/projects/alerting/notify_service_spec.rb @@ -72,7 +72,7 @@ describe Projects::Alerting::NotifyService do describe '#execute' do let(:token) { 'invalid-token' } - let(:starts_at) { Time.now.change(usec: 0) } + let(:starts_at) { Time.current.change(usec: 0) } let(:service) { described_class.new(project, nil, payload) } let(:payload_raw) do { @@ -121,7 +121,7 @@ describe Projects::Alerting::NotifyService do expect(last_alert_attributes).to match( project_id: project.id, title: payload_raw.fetch(:title), - started_at: Time.parse(payload_raw.fetch(:start_time)), + started_at: Time.zone.parse(payload_raw.fetch(:start_time)), severity: payload_raw.fetch(:severity), status: AlertManagement::Alert::STATUSES[:triggered], events: 1, @@ -154,7 +154,7 @@ describe Projects::Alerting::NotifyService do expect(last_alert_attributes).to match( project_id: project.id, title: payload_raw.fetch(:title), - started_at: Time.parse(payload_raw.fetch(:start_time)), + started_at: Time.zone.parse(payload_raw.fetch(:start_time)), severity: 'critical', status: AlertManagement::Alert::STATUSES[:triggered], events: 1, diff --git a/spec/services/projects/hashed_storage/base_attachment_service_spec.rb b/spec/services/projects/hashed_storage/base_attachment_service_spec.rb index 34c37be6703..070dd5fc1b8 100644 --- a/spec/services/projects/hashed_storage/base_attachment_service_spec.rb +++ b/spec/services/projects/hashed_storage/base_attachment_service_spec.rb @@ -31,7 +31,7 @@ describe Projects::HashedStorage::BaseAttachmentService do expect(Dir.exist?(target_path)).to be_truthy Timecop.freeze do - suffix = Time.now.utc.to_i + suffix = Time.current.utc.to_i subject.send(:discard_path!, target_path) expected_renamed_path = "#{target_path}-#{suffix}" diff --git a/spec/services/projects/prometheus/alerts/create_events_service_spec.rb b/spec/services/projects/prometheus/alerts/create_events_service_spec.rb index 1d726db6ce3..35f23afd7a2 100644 --- a/spec/services/projects/prometheus/alerts/create_events_service_spec.rb +++ b/spec/services/projects/prometheus/alerts/create_events_service_spec.rb @@ -50,7 +50,7 @@ describe Projects::Prometheus::Alerts::CreateEventsService do let(:events) { service.execute } context 'with a firing payload' do - let(:started_at) { truncate_to_second(Time.now) } + let(:started_at) { truncate_to_second(Time.current) } let(:firing_event) { alert_payload(status: 'firing', started_at: started_at) } let(:alerts_payload) { { 'alerts' => [firing_event] } } @@ -87,7 +87,7 @@ describe Projects::Prometheus::Alerts::CreateEventsService do end context 'with a resolved payload' do - let(:started_at) { truncate_to_second(Time.now) } + let(:started_at) { truncate_to_second(Time.current) } let(:ended_at) { started_at + 1 } let(:payload_key) { PrometheusAlertEvent.payload_key_for(alert.prometheus_metric_id, utc_rfc3339(started_at)) } let(:resolved_event) { alert_payload(status: 'resolved', started_at: started_at, ended_at: ended_at) } @@ -285,7 +285,7 @@ describe Projects::Prometheus::Alerts::CreateEventsService do private - def alert_payload(status: 'firing', started_at: Time.now, ended_at: Time.now, gitlab_alert_id: alert.prometheus_metric_id, title: nil, environment: nil) + def alert_payload(status: 'firing', started_at: Time.current, ended_at: Time.current, gitlab_alert_id: alert.prometheus_metric_id, title: nil, environment: nil) payload = {} payload['status'] = status if status diff --git a/spec/services/projects/update_repository_storage_service_spec.rb b/spec/services/projects/update_repository_storage_service_spec.rb index 4d63216d1c8..28b79bc61d9 100644 --- a/spec/services/projects/update_repository_storage_service_spec.rb +++ b/spec/services/projects/update_repository_storage_service_spec.rb @@ -8,7 +8,7 @@ describe Projects::UpdateRepositoryStorageService do subject { described_class.new(repository_storage_move) } describe "#execute" do - let(:time) { Time.now } + let(:time) { Time.current } before do allow(Time).to receive(:now).and_return(time) diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 36f9966c0ef..a9de0a747f6 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -361,7 +361,7 @@ describe QuickActions::InterpretService do expect(updates).to eq(spend_time: { duration: 3600, user_id: developer.id, - spent_at: DateTime.now.to_date + spent_at: DateTime.current.to_date }) end @@ -379,7 +379,7 @@ describe QuickActions::InterpretService do expect(updates).to eq(spend_time: { duration: -1800, user_id: developer.id, - spent_at: DateTime.now.to_date + spent_at: DateTime.current.to_date }) end end diff --git a/spec/services/repository_archive_clean_up_service_spec.rb b/spec/services/repository_archive_clean_up_service_spec.rb index c0b286ac675..80b177a0174 100644 --- a/spec/services/repository_archive_clean_up_service_spec.rb +++ b/spec/services/repository_archive_clean_up_service_spec.rb @@ -110,6 +110,8 @@ describe RepositoryArchiveCleanUpService do def create_temporary_files(dir, extensions, mtime) FileUtils.mkdir_p(dir) + # rubocop: disable Rails/TimeZone FileUtils.touch(extensions.map { |ext| File.join(dir, "sample.#{ext}") }, mtime: Time.now - mtime) + # rubocop: enable Rails/TimeZone end end diff --git a/spec/services/resource_events/merge_into_notes_service_spec.rb b/spec/services/resource_events/merge_into_notes_service_spec.rb index 6bad1b86fca..2664a27244d 100644 --- a/spec/services/resource_events/merge_into_notes_service_spec.rb +++ b/spec/services/resource_events/merge_into_notes_service_spec.rb @@ -21,7 +21,7 @@ describe ResourceEvents::MergeIntoNotesService do let_it_be(:resource) { create(:issue, project: project) } let_it_be(:label) { create(:label, project: project) } let_it_be(:label2) { create(:label, project: project) } - let(:time) { Time.now } + let(:time) { Time.current } describe '#execute' do it 'merges label events into notes in order of created_at' do diff --git a/spec/services/update_merge_request_metrics_service_spec.rb b/spec/services/update_merge_request_metrics_service_spec.rb index bb07dfa1a0e..1aaf5e712f9 100644 --- a/spec/services/update_merge_request_metrics_service_spec.rb +++ b/spec/services/update_merge_request_metrics_service_spec.rb @@ -9,7 +9,7 @@ describe MergeRequestMetricsService do it 'updates metrics' do user = create(:user) service = described_class.new(metrics) - event = double(Event, author_id: user.id, created_at: Time.now) + event = double(Event, author_id: user.id, created_at: Time.current) service.merge(event) @@ -22,7 +22,7 @@ describe MergeRequestMetricsService do it 'updates metrics' do user = create(:user) service = described_class.new(metrics) - event = double(Event, author_id: user.id, created_at: Time.now) + event = double(Event, author_id: user.id, created_at: Time.current) service.close(event) diff --git a/spec/services/verify_pages_domain_service_spec.rb b/spec/services/verify_pages_domain_service_spec.rb index f2b3b44d223..3f08ae84c14 100644 --- a/spec/services/verify_pages_domain_service_spec.rb +++ b/spec/services/verify_pages_domain_service_spec.rb @@ -348,7 +348,7 @@ describe VerifyPagesDomainService do end it 'does not shorten any grace period' do - grace = Time.now + 1.year + grace = Time.current + 1.year domain.update!(enabled_until: grace) disallow_resolver! |