Commit f41c5b4f authored by Stan Hu's avatar Stan Hu

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

Enable Rails/TimeZone for controllers

See merge request gitlab-org/gitlab!32277
parents d065f8b3 99049b4e
......@@ -466,8 +466,12 @@ Rails/TimeZone:
Enabled: true
EnforcedStyle: 'flexible'
Include:
- 'app/controllers/**/*'
- 'app/services/**/*'
- 'spec/controllers/**/*'
- 'spec/services/**/*'
- 'ee/app/controllers/**/*'
- 'ee/app/services/**/*'
- 'ee/spec/controllers/**/*'
- 'ee/spec/services/**/*'
......@@ -144,7 +144,7 @@ class Import::GithubController < Import::BaseController
end
def provider_rate_limit(exception)
reset_time = Time.at(exception.response_headers['x-ratelimit-reset'].to_i)
reset_time = Time.zone.at(exception.response_headers['x-ratelimit-reset'].to_i)
session[access_token_key] = nil
redirect_to new_import_url,
alert: _("GitHub API rate limit exceeded. Try again after %{reset_time}") % { reset_time: reset_time }
......
......@@ -58,7 +58,7 @@ class ProjectsController < Projects::ApplicationController
@project = ::Projects::CreateService.new(current_user, project_params(attributes: project_params_create_attributes)).execute
if @project.saved?
cookies[:issue_board_welcome_hidden] = { path: project_path(@project), value: nil, expires: Time.at(0) }
cookies[:issue_board_welcome_hidden] = { path: project_path(@project), value: nil, expires: Time.zone.at(0) }
redirect_to(
project_path(@project, custom_import_params),
......
......@@ -17,8 +17,8 @@ module Projects
result = adapter.query(
:packet_flow, environment.deployment_namespace,
params[:interval] || "minute",
(Time.parse(params[:from]) rescue 1.hour.ago).to_s,
(Time.parse(params[:to]) rescue Time.current).to_s
parse_time(params[:from], 1.hour.ago).to_s,
parse_time(params[:to], Time.current).to_s
)
respond_to do |format|
......@@ -35,6 +35,12 @@ module Projects
private
def parse_time(params, fallback)
Time.zone.parse(params) || fallback
rescue
fallback
end
def environment
@environment ||= project.environments.find(params[:environment_id])
end
......
......@@ -41,7 +41,7 @@ describe Projects::Security::NetworkPoliciesController do
expect(adapter).to(
receive(:query)
.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.zone.at(0).to_i, 10]], ops_total: 10 } })
)
subject
end
......@@ -55,14 +55,14 @@ describe Projects::Security::NetworkPoliciesController do
let(:action_params) do
{
project_id: project, namespace_id: project.namespace, environment_id: environment,
interval: "day", from: Time.at(0), to: Time.at(100)
interval: "day", from: Time.zone.at(0), to: Time.zone.at(100)
}
end
it 'queries with requested arguments' do
expect(adapter).to(
receive(:query)
.with(:packet_flow, kubernetes_namespace, "day", Time.at(0).to_s, Time.at(100).to_s)
.with(:packet_flow, kubernetes_namespace, "day", Time.zone.at(0).to_s, Time.zone.at(100).to_s)
.and_return({ success: true, data: {} })
)
subject
......
......@@ -14,7 +14,7 @@ describe ApplicationController do
end
it 'redirects if the user is over their password expiry' do
user.password_expires_at = Time.new(2002)
user.password_expires_at = Time.zone.local(2002)
expect(user.ldap_user?).to be_falsey
allow(controller).to receive(:current_user).and_return(user)
......@@ -35,7 +35,7 @@ describe ApplicationController do
end
it 'does not redirect if the user is over their password expiry but they are an ldap user' do
user.password_expires_at = Time.new(2002)
user.password_expires_at = Time.zone.local(2002)
allow(user).to receive(:ldap_user?).and_return(true)
allow(controller).to receive(:current_user).and_return(user)
......@@ -47,7 +47,7 @@ describe ApplicationController do
it 'does not redirect if the user is over their password expiry but password authentication is disabled for the web interface' do
stub_application_setting(password_authentication_enabled_for_web: false)
stub_application_setting(password_authentication_enabled_for_git: false)
user.password_expires_at = Time.new(2002)
user.password_expires_at = Time.zone.local(2002)
allow(controller).to receive(:current_user).and_return(user)
expect(controller).not_to receive(:redirect_to)
......
......@@ -56,7 +56,7 @@ describe Groups::Settings::RepositoryController do
'id' => be_a(Integer),
'name' => deploy_token_params[:name],
'username' => deploy_token_params[:username],
'expires_at' => Time.parse(deploy_token_params[:expires_at]),
'expires_at' => Time.zone.parse(deploy_token_params[:expires_at]),
'token' => be_a(String),
'scopes' => deploy_token_params.inject([]) do |scopes, kv|
key, value = kv
......
......@@ -48,8 +48,8 @@ describe Projects::GraphsController do
expect(assigns[:daily_coverage_options]).to eq(
base_params: {
start_date: Time.now.to_date - 90.days,
end_date: Time.now.to_date,
start_date: Time.current.to_date - 90.days,
end_date: Time.current.to_date,
ref_path: project.repository.expand_ref('master'),
param_type: 'coverage'
},
......
......@@ -73,7 +73,7 @@ describe Projects::Settings::RepositoryController do
'id' => be_a(Integer),
'name' => deploy_token_params[:name],
'username' => deploy_token_params[:username],
'expires_at' => Time.parse(deploy_token_params[:expires_at]),
'expires_at' => Time.zone.parse(deploy_token_params[:expires_at]),
'token' => be_a(String),
'scopes' => deploy_token_params.inject([]) do |scopes, kv|
key, value = kv
......
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