Commit 4c0f6a93 authored by Stan Hu's avatar Stan Hu

Merge branch '216527-time-zone-usage-controllers' into 'master'

Time.now => Time.current in controllers

See merge request gitlab-org/gitlab!31578
parents 81a1e155 ced4f681
...@@ -145,7 +145,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -145,7 +145,7 @@ class Admin::UsersController < Admin::ApplicationController
password_confirmation: params[:user][:password_confirmation] password_confirmation: params[:user][:password_confirmation]
} }
password_params[:password_expires_at] = Time.now unless changing_own_password? password_params[:password_expires_at] = Time.current unless changing_own_password?
user_params_with_pass.merge!(password_params) user_params_with_pass.merge!(password_params)
end end
......
...@@ -13,7 +13,7 @@ module NotesActions ...@@ -13,7 +13,7 @@ module NotesActions
end end
def index def index
current_fetched_at = Time.now.to_i current_fetched_at = Time.current.to_i
notes_json = { notes: [], last_fetched_at: current_fetched_at } notes_json = { notes: [], last_fetched_at: current_fetched_at }
......
...@@ -5,7 +5,7 @@ class UserCalloutsController < ApplicationController ...@@ -5,7 +5,7 @@ class UserCalloutsController < ApplicationController
callout = ensure_callout callout = ensure_callout
if callout.persisted? if callout.persisted?
callout.update(dismissed_at: Time.now) callout.update(dismissed_at: Time.current)
respond_to do |format| respond_to do |format|
format.json { head :ok } format.json { head :ok }
end end
......
...@@ -34,7 +34,7 @@ module EE ...@@ -34,7 +34,7 @@ module EE
if result[:status] == :success if result[:status] == :success
redirect_to group_path(group), redirect_to group_path(group),
status: :found, status: :found,
notice: "'#{group.name}' has been scheduled for removal on #{permanent_deletion_date(Time.now.utc)}." notice: "'#{group.name}' has been scheduled for removal on #{permanent_deletion_date(Time.current.utc)}."
else else
redirect_to edit_group_path(group), status: :found, alert: result[:message] redirect_to edit_group_path(group), status: :found, alert: result[:message]
end end
......
...@@ -90,7 +90,7 @@ module EE ...@@ -90,7 +90,7 @@ module EE
# If the known hosts data is being set, store details about who and when # If the known hosts data is being set, store details about who and when
if import_data[:ssh_known_hosts].present? if import_data[:ssh_known_hosts].present?
import_data[:ssh_known_hosts_verified_at] = Time.now import_data[:ssh_known_hosts_verified_at] = Time.current
import_data[:ssh_known_hosts_verified_by_id] = current_user.id import_data[:ssh_known_hosts_verified_by_id] = current_user.id
end end
end end
......
...@@ -18,7 +18,7 @@ module Projects ...@@ -18,7 +18,7 @@ module Projects
:packet_flow, environment.deployment_namespace, :packet_flow, environment.deployment_namespace,
params[:interval] || "minute", params[:interval] || "minute",
(Time.parse(params[:from]) rescue 1.hour.ago).to_s, (Time.parse(params[:from]) rescue 1.hour.ago).to_s,
(Time.parse(params[:to]) rescue Time.now).to_s (Time.parse(params[:to]) rescue Time.current).to_s
) )
respond_to do |format| respond_to do |format|
......
...@@ -240,7 +240,7 @@ describe Admin::ApplicationSettingsController do ...@@ -240,7 +240,7 @@ describe Admin::ApplicationSettingsController do
end end
context 'when an admin user attempts a request' do context 'when an admin user attempts a request' do
let_it_be(:yesterday) { Time.now.utc.yesterday.to_date } let_it_be(:yesterday) { Time.current.utc.yesterday.to_date }
let_it_be(:max_count) { 15 } let_it_be(:max_count) { 15 }
let_it_be(:current_count) { 10 } let_it_be(:current_count) { 10 }
......
...@@ -220,7 +220,7 @@ describe Analytics::CycleAnalytics::StagesController do ...@@ -220,7 +220,7 @@ describe Analytics::CycleAnalytics::StagesController do
subject { get :duration_chart, params: params } subject { get :duration_chart, params: params }
it 'matches the response schema' do it 'matches the response schema' do
fake_result = [double(MergeRequest, duration_in_seconds: 10, finished_at: Time.now)] fake_result = [double(MergeRequest, duration_in_seconds: 10, finished_at: Time.current)]
expect_any_instance_of(Gitlab::Analytics::CycleAnalytics::DataForDurationChart).to receive(:load).and_return(fake_result) expect_any_instance_of(Gitlab::Analytics::CycleAnalytics::DataForDurationChart).to receive(:load).and_return(fake_result)
subject subject
......
...@@ -220,7 +220,7 @@ describe Groups::Analytics::CycleAnalytics::StagesController do ...@@ -220,7 +220,7 @@ describe Groups::Analytics::CycleAnalytics::StagesController do
subject { get :duration_chart, params: params } subject { get :duration_chart, params: params }
it 'matches the response schema' do it 'matches the response schema' do
fake_result = [double(MergeRequest, duration_in_seconds: 10, finished_at: Time.now)] fake_result = [double(MergeRequest, duration_in_seconds: 10, finished_at: Time.current)]
expect_any_instance_of(Gitlab::Analytics::CycleAnalytics::DataForDurationChart).to receive(:load).and_return(fake_result) expect_any_instance_of(Gitlab::Analytics::CycleAnalytics::DataForDurationChart).to receive(:load).and_return(fake_result)
subject subject
......
...@@ -19,7 +19,7 @@ describe Groups::ContributionAnalyticsController do ...@@ -19,7 +19,7 @@ describe Groups::ContributionAnalyticsController do
action: action, action: action,
target: target, target: target,
author: author, author: author,
created_at: Time.now) created_at: Time.current)
end end
def create_push_event(author, project) def create_push_event(author, project)
......
...@@ -366,7 +366,7 @@ describe Groups::EpicsController do ...@@ -366,7 +366,7 @@ describe Groups::EpicsController do
context 'when state_event param is reopen' do context 'when state_event param is reopen' do
before do before do
epic.update!(state: 'closed', closed_at: Time.now, closed_by: user) epic.update!(state: 'closed', closed_at: Time.current, closed_by: user)
end end
it 'allows epic to be reopened' do it 'allows epic to be reopened' do
......
...@@ -73,7 +73,7 @@ describe OperationsController do ...@@ -73,7 +73,7 @@ describe OperationsController do
end end
describe 'GET #list' do describe 'GET #list' do
let(:now) { Time.now.change(usec: 0) } let(:now) { Time.current.change(usec: 0) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:commit) { project.commit } let(:commit) { project.commit }
let!(:environment) { create(:environment, name: 'production', project: project) } let!(:environment) { create(:environment, name: 'production', project: project) }
......
...@@ -18,7 +18,7 @@ describe Projects::BranchesController do ...@@ -18,7 +18,7 @@ describe Projects::BranchesController do
render_views render_views
before do before do
create(:import_state, :mirror, :finished, project: project, last_successful_update_at: Time.now) create(:import_state, :mirror, :finished, project: project, last_successful_update_at: Time.current)
allow(project.repository).to receive(:diverged_from_upstream?) { true } allow(project.repository).to receive(:diverged_from_upstream?) { true }
end end
......
...@@ -172,7 +172,7 @@ describe Projects::MirrorsController do ...@@ -172,7 +172,7 @@ describe Projects::MirrorsController do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
import_data = project.reload_import_data import_data = project.reload_import_data
expect(import_data.ssh_known_hosts_verified_at).to be_within(1.minute).of(Time.now) expect(import_data.ssh_known_hosts_verified_at).to be_within(1.minute).of(Time.current)
expect(import_data.ssh_known_hosts_verified_by).to eq(project.owner) expect(import_data.ssh_known_hosts_verified_by).to eq(project.owner)
end end
......
...@@ -40,7 +40,7 @@ describe Projects::Security::NetworkPoliciesController do ...@@ -40,7 +40,7 @@ describe Projects::Security::NetworkPoliciesController do
Timecop.freeze do Timecop.freeze do
expect(adapter).to( expect(adapter).to(
receive(:query) receive(:query)
.with(:packet_flow, kubernetes_namespace, "minute", 1.hour.ago.to_s, Time.now.to_s) .with(:packet_flow, kubernetes_namespace, "minute", 1.hour.ago.to_s, Time.current.to_s)
.and_return({ success: true, data: { ops_rate: [[Time.at(0).to_i, 10]], ops_total: 10 } }) .and_return({ success: true, data: { ops_rate: [[Time.at(0).to_i, 10]], ops_total: 10 } })
) )
subject subject
...@@ -81,7 +81,7 @@ describe Projects::Security::NetworkPoliciesController do ...@@ -81,7 +81,7 @@ describe Projects::Security::NetworkPoliciesController do
Timecop.freeze do Timecop.freeze do
expect(adapter).to( expect(adapter).to(
receive(:query) receive(:query)
.with(:packet_flow, kubernetes_namespace, "minute", 1.hour.ago.to_s, Time.now.to_s) .with(:packet_flow, kubernetes_namespace, "minute", 1.hour.ago.to_s, Time.current.to_s)
.and_return({ success: true, data: {} }) .and_return({ success: true, data: {} })
) )
subject subject
......
...@@ -27,7 +27,7 @@ describe Admin::RequestsProfilesController do ...@@ -27,7 +27,7 @@ describe Admin::RequestsProfilesController do
end end
context 'when loading HTML profile' do context 'when loading HTML profile' do
let(:basename) { "profile_#{Time.now.to_i}_execution.html" } let(:basename) { "profile_#{Time.current.to_i}_execution.html" }
let(:sample_data) do let(:sample_data) do
'<html> <body> <h1>Heading</h1> <p>paragraph.</p> </body> </html>' '<html> <body> <h1>Heading</h1> <p>paragraph.</p> </body> </html>'
...@@ -42,7 +42,7 @@ describe Admin::RequestsProfilesController do ...@@ -42,7 +42,7 @@ describe Admin::RequestsProfilesController do
end end
context 'when loading TXT profile' do context 'when loading TXT profile' do
let(:basename) { "profile_#{Time.now.to_i}_memory.txt" } let(:basename) { "profile_#{Time.current.to_i}_memory.txt" }
let(:sample_data) do let(:sample_data) do
<<~TXT <<~TXT
...@@ -60,7 +60,7 @@ describe Admin::RequestsProfilesController do ...@@ -60,7 +60,7 @@ describe Admin::RequestsProfilesController do
end end
context 'when loading PDF profile' do context 'when loading PDF profile' do
let(:basename) { "profile_#{Time.now.to_i}_anything.pdf" } let(:basename) { "profile_#{Time.current.to_i}_anything.pdf" }
let(:sample_data) { 'mocked pdf content' } let(:sample_data) { 'mocked pdf content' }
......
...@@ -296,7 +296,7 @@ describe Admin::UsersController do ...@@ -296,7 +296,7 @@ describe Admin::UsersController do
it 'sets the new password to expire immediately' do it 'sets the new password to expire immediately' do
expect { update_password(user, 'AValidPassword1') } expect { update_password(user, 'AValidPassword1') }
.to change { user.reload.password_expires_at }.to be_within(2.seconds).of(Time.now) .to change { user.reload.password_expires_at }.to be_within(2.seconds).of(Time.current)
end end
end end
......
...@@ -25,7 +25,7 @@ describe ApplicationController do ...@@ -25,7 +25,7 @@ describe ApplicationController do
end end
it 'does not redirect if the user is under their password expiry' do it 'does not redirect if the user is under their password expiry' do
user.password_expires_at = Time.now + 20010101 user.password_expires_at = Time.current + 20010101
expect(user.ldap_user?).to be_falsey expect(user.ldap_user?).to be_falsey
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
......
...@@ -27,7 +27,7 @@ describe Import::BitbucketController do ...@@ -27,7 +27,7 @@ describe Import::BitbucketController do
end end
it "updates access token" do it "updates access token" do
expires_at = Time.now + 1.day expires_at = Time.current + 1.day
expires_in = 1.day expires_in = 1.day
access_token = double(token: token, access_token = double(token: token,
secret: secret, secret: secret,
......
...@@ -609,7 +609,7 @@ describe Projects::IssuesController do ...@@ -609,7 +609,7 @@ describe Projects::IssuesController do
before do before do
project.add_developer(user) project.add_developer(user)
issue.update!(last_edited_by: deleted_user, last_edited_at: Time.now) issue.update!(last_edited_by: deleted_user, last_edited_at: Time.current)
deleted_user.destroy deleted_user.destroy
sign_in(user) sign_in(user)
......
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