Commit ed22ac30 authored by Tetiana Chupryna's avatar Tetiana Chupryna

Merge branch 'ajk-forbid-time-now' into 'master'

Enable Rails/TimeZone in feature specs

See merge request gitlab-org/gitlab!81096
parents 42b0fdec 4dc3f0e7
......@@ -604,6 +604,8 @@ Rails/TimeZone:
- 'ee/spec/workers/**/*'
- 'ee/lib/**/*'
- 'ee/spec/lib/**/*'
- 'spec/features/**/*'
- 'ee/spec/features/**/*'
# WIP: See https://gitlab.com/gitlab-org/gitlab/-/issues/220040
Rails/SaveBang:
......
......@@ -19,7 +19,7 @@ RSpec.describe 'Reset namespace pipeline minutes', :js do
end
it 'resets pipeline minutes' do
time = Time.now
time = Time.zone.now
travel_to(time) do
click_button 'Reset pipeline minutes'
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe 'Iterations list', :js do
let_it_be(:now) { Time.now }
let_it_be(:now) { Time.zone.now }
let_it_be(:group) { create(:group) }
let_it_be(:subgroup) { create(:group, parent: group) }
let_it_be(:user) { create(:user) }
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe 'User creates iteration in a cadence', :js do
let_it_be(:now) { Time.now }
let_it_be(:now) { Time.zone.now }
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:group_member, :maintainer, user: create(:user), group: group ).user }
let_it_be(:cadence) { create(:iterations_cadence, group: group, automatic: false, duration_in_weeks: 0) }
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe 'User edits iteration' do
let_it_be(:now) { Time.now }
let_it_be(:now) { Time.zone.now }
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:group_member, :maintainer, user: create(:user), group: group ).user }
let_it_be(:guest_user) { create(:group_member, :guest, user: create(:user), group: group ).user }
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe 'User views iteration' do
let_it_be(:now) { Time.now }
let_it_be(:now) { Time.zone.now }
let_it_be(:group) { create(:group) }
let_it_be(:sub_group) { create(:group, :private, parent: group) }
let_it_be(:project) { create(:project, group: group) }
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe 'Iterations list', :js do
let_it_be(:now) { Time.now }
let_it_be(:now) { Time.zone.now }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :public, group: group) }
let_it_be(:user) { create(:user) }
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe 'User views iteration' do
let_it_be(:now) { Time.now }
let_it_be(:now) { Time.zone.now }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:project_2) { create(:project, group: group) }
......
......@@ -44,7 +44,7 @@ RSpec.describe 'Project mirror', :js do
end
context 'with Update now button' do
let(:timestamp) { Time.now }
let(:timestamp) { Time.zone.now }
before do
import_state.update!(last_update_at: 6.minutes.ago, next_execution_timestamp: timestamp + 10.minutes)
......
......@@ -23,7 +23,7 @@ RSpec.describe "Admin Runners" do
context "when there are runners" do
it 'has all necessary texts' do
create(:ci_runner, :instance, created_at: 1.year.ago, contacted_at: Time.now)
create(:ci_runner, :instance, created_at: 1.year.ago, contacted_at: Time.zone.now)
create(:ci_runner, :instance, created_at: 1.year.ago, contacted_at: 1.week.ago)
create(:ci_runner, :instance, created_at: 1.year.ago, contacted_at: 1.year.ago)
......@@ -158,9 +158,9 @@ RSpec.describe "Admin Runners" do
let!(:never_contacted) { create(:ci_runner, :instance, description: 'runner-never-contacted', contacted_at: nil) }
before do
create(:ci_runner, :instance, description: 'runner-1', contacted_at: Time.now)
create(:ci_runner, :instance, description: 'runner-2', contacted_at: Time.now)
create(:ci_runner, :instance, description: 'runner-paused', active: false, contacted_at: Time.now)
create(:ci_runner, :instance, description: 'runner-1', contacted_at: Time.zone.now)
create(:ci_runner, :instance, description: 'runner-2', contacted_at: Time.zone.now)
create(:ci_runner, :instance, description: 'runner-paused', active: false, contacted_at: Time.zone.now)
visit admin_runners_path
end
......
......@@ -54,7 +54,7 @@ RSpec.describe "Admin::Users" do
visit admin_users_path(tab: 'cohorts')
expect(page).to have_content("#{Time.now.strftime('%b %Y')} 3 0")
expect(page).to have_content("#{Time.zone.now.strftime('%b %Y')} 3 0")
end
end
......
......@@ -43,7 +43,7 @@ RSpec.describe 'Admin uses repository checks', :request_store do
project = create(:project)
project.update_columns(
last_repository_check_failed: true,
last_repository_check_at: Time.now
last_repository_check_at: Time.zone.now
)
visit_admin_project_page(project)
......
......@@ -220,7 +220,7 @@ RSpec.describe 'Admin::Users::User' do
context 'a user with an expired password' do
before do
another_user.update!(password_expires_at: Time.now - 5.minutes)
another_user.update!(password_expires_at: Time.zone.now - 5.minutes)
end
it 'does not redirect to password change page' do
......@@ -255,7 +255,7 @@ RSpec.describe 'Admin::Users::User' do
context 'a user with an expired password' do
before do
another_user.update!(password_expires_at: Time.now - 5.minutes)
another_user.update!(password_expires_at: Time.zone.now - 5.minutes)
end
it 'is redirected back to the impersonated users page in the admin after stopping' do
......
......@@ -574,7 +574,7 @@ RSpec.describe 'Admin::Users' do
user.reload
expect(user.name).to eq('Big Bang')
expect(user.admin?).to be_truthy
expect(user.password_expires_at).to be <= Time.now
expect(user.password_expires_at).to be <= Time.zone.now
end
end
......
......@@ -48,7 +48,7 @@ RSpec.describe 'Dashboard Projects' do
context 'when last_repository_updated_at, last_activity_at and update_at are present' do
it 'shows the last_repository_updated_at attribute as the update date' do
project.update!(last_repository_updated_at: Time.now, last_activity_at: 1.hour.ago)
project.update!(last_repository_updated_at: Time.zone.now, last_activity_at: 1.hour.ago)
visit dashboard_projects_path
......@@ -56,7 +56,7 @@ RSpec.describe 'Dashboard Projects' do
end
it 'shows the last_activity_at attribute as the update date' do
project.update!(last_repository_updated_at: 1.hour.ago, last_activity_at: Time.now)
project.update!(last_repository_updated_at: 1.hour.ago, last_activity_at: Time.zone.now)
visit dashboard_projects_path
......
......@@ -9,9 +9,9 @@ RSpec.describe "User sorts issues" do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project_empty_repo, :public, group: group) }
let_it_be(:issue1, reload: true) { create(:issue, title: 'foo', created_at: Time.now, project: project) }
let_it_be(:issue2, reload: true) { create(:issue, title: 'bar', created_at: Time.now - 60, project: project) }
let_it_be(:issue3, reload: true) { create(:issue, title: 'baz', created_at: Time.now - 120, project: project) }
let_it_be(:issue1, reload: true) { create(:issue, title: 'foo', created_at: Time.zone.now, project: project) }
let_it_be(:issue2, reload: true) { create(:issue, title: 'bar', created_at: Time.zone.now - 60, project: project) }
let_it_be(:issue3, reload: true) { create(:issue, title: 'baz', created_at: Time.zone.now - 120, project: project) }
let_it_be(:newer_due_milestone) { create(:milestone, project: project, due_date: '2013-12-11') }
let_it_be(:later_due_milestone) { create(:milestone, project: project, due_date: '2013-12-12') }
......@@ -75,7 +75,7 @@ RSpec.describe "User sorts issues" do
end
it 'sorts by most recently updated', :js do
issue3.updated_at = Time.now + 100
issue3.updated_at = Time.zone.now + 100
issue3.save!
visit project_issues_path(project, sort: sort_value_recently_updated)
......
......@@ -183,7 +183,7 @@ RSpec.describe 'Editing file blob', :js do
freeze_time do
visit project_edit_blob_path(project, tree_join(protected_branch, file_path))
epoch = Time.now.strftime('%s%L').last(5)
epoch = Time.zone.now.strftime('%s%L').last(5)
expect(find('.js-branch-name').value).to eq "#{user.username}-protected-branch-patch-#{epoch}"
end
......
......@@ -26,7 +26,7 @@ RSpec.describe 'Projects > Files > Project owner creates a license file', :js do
file_content = first('.file-editor')
expect(file_content).to have_content('MIT License')
expect(file_content).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
expect(file_content).to have_content("Copyright (c) #{Time.zone.now.year} #{project.namespace.human_name}")
fill_in :commit_message, with: 'Add a LICENSE file', visible: true
click_button 'Commit changes'
......@@ -34,7 +34,7 @@ RSpec.describe 'Projects > Files > Project owner creates a license file', :js do
expect(current_path).to eq(
project_blob_path(project, 'master/LICENSE'))
expect(page).to have_content('MIT License')
expect(page).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
expect(page).to have_content("Copyright (c) #{Time.zone.now.year} #{project.namespace.human_name}")
end
it 'project maintainer creates a license file from the "Add license" link' do
......@@ -50,7 +50,7 @@ RSpec.describe 'Projects > Files > Project owner creates a license file', :js do
file_content = first('.file-editor')
expect(file_content).to have_content('MIT License')
expect(file_content).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
expect(file_content).to have_content("Copyright (c) #{Time.zone.now.year} #{project.namespace.human_name}")
fill_in :commit_message, with: 'Add a LICENSE file', visible: true
click_button 'Commit changes'
......@@ -58,7 +58,7 @@ RSpec.describe 'Projects > Files > Project owner creates a license file', :js do
expect(current_path).to eq(
project_blob_path(project, 'master/LICENSE'))
expect(page).to have_content('MIT License')
expect(page).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
expect(page).to have_content("Copyright (c) #{Time.zone.now.year} #{project.namespace.human_name}")
end
def select_template(template)
......
......@@ -23,7 +23,7 @@ RSpec.describe 'Projects > Files > Project owner sees a link to create a license
select_template('MIT License')
expect(ide_editor_value).to have_content('MIT License')
expect(ide_editor_value).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
expect(ide_editor_value).to have_content("Copyright (c) #{Time.zone.now.year} #{project.namespace.human_name}")
ide_commit
......@@ -33,7 +33,7 @@ RSpec.describe 'Projects > Files > Project owner sees a link to create a license
license_file = project.repository.blob_at('master', 'LICENSE').data
expect(license_file).to have_content('MIT License')
expect(license_file).to have_content("Copyright (c) #{Time.now.year} #{project.namespace.human_name}")
expect(license_file).to have_content("Copyright (c) #{Time.zone.now.year} #{project.namespace.human_name}")
end
def select_template(template)
......
......@@ -384,7 +384,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do
end
context 'when expire date is defined' do
let(:expire_at) { Time.now + 7.days }
let(:expire_at) { Time.zone.now + 7.days }
context 'when user has ability to update job' do
context 'when artifacts are unlocked' do
......@@ -423,7 +423,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state do
end
context 'when artifacts expired' do
let(:expire_at) { Time.now - 7.days }
let(:expire_at) { Time.zone.now - 7.days }
context 'when artifacts are unlocked' do
before do
......
......@@ -414,7 +414,7 @@ RSpec.describe 'Pipelines', :js do
it "has link to the delayed job's action" do
find('[data-testid="pipelines-manual-actions-dropdown"]').click
time_diff = [0, delayed_job.scheduled_at - Time.now].max
time_diff = [0, delayed_job.scheduled_at - Time.zone.now].max
expect(page).to have_button('delayed job 1')
expect(page).to have_content(Time.at(time_diff).utc.strftime("%H:%M:%S"))
end
......
......@@ -25,7 +25,7 @@ RSpec.describe 'Project remote mirror', :feature do
context 'when last_error and last_update_at are present' do
it 'renders error message with timestamp' do
remote_mirror.update!(last_error: 'Some new error', last_update_at: Time.now - 5.minutes)
remote_mirror.update!(last_error: 'Some new error', last_update_at: Time.zone.now - 5.minutes)
visit project_mirror_path(project)
......
......@@ -437,7 +437,7 @@ RSpec.describe 'Login', :clean_gitlab_redis_sessions do
context 'when the users password is expired' do
before do
user.update!(password_expires_at: Time.parse('2018-05-08 11:29:46 UTC'))
user.update!(password_expires_at: Time.zone.parse('2018-05-08 11:29:46 UTC'))
end
it 'asks for a new password' do
......@@ -860,7 +860,7 @@ RSpec.describe 'Login', :clean_gitlab_redis_sessions do
context 'when the users password is expired' do
before do
user.update!(password_expires_at: Time.parse('2018-05-08 11:29:46 UTC'))
user.update!(password_expires_at: Time.zone.parse('2018-05-08 11:29:46 UTC'))
end
it 'asks the user to accept the terms before setting a new password' do
......
......@@ -426,7 +426,7 @@ RSpec.describe 'User page' do
end
context 'structured markup' do
let_it_be(:user) { create(:user, website_url: 'https://gitlab.com', organization: 'GitLab', job_title: 'Frontend Engineer', email: 'public@example.com', public_email: 'public@example.com', location: 'Country', created_at: Time.now, updated_at: Time.now) }
let_it_be(:user) { create(:user, website_url: 'https://gitlab.com', organization: 'GitLab', job_title: 'Frontend Engineer', email: 'public@example.com', public_email: 'public@example.com', location: 'Country', created_at: Time.zone.now, updated_at: Time.zone.now) }
it 'shows Person structured markup' do
subject
......
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