diff --git a/.rubocop/default.yml b/.rubocop/default.yml index c3725f7ed..f98a42305 100644 --- a/.rubocop/default.yml +++ b/.rubocop/default.yml @@ -189,6 +189,10 @@ Rails/SkipsModelValidations: - "**/*_spec.rb" - "**/*_examples.rb" +Rails/ReversibleMigration: + Description: This cop checks whether the change method of the migration file is reversible. + Enabled: false + Style/ClassAndModuleChildren: Description: 'Checks style of children classes and modules.' Enabled: false diff --git a/Gemfile.lock b/Gemfile.lock index dff98dbe9..bcb88ee1e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -523,7 +523,7 @@ GEM rubocop-performance (1.13.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) - rubocop-rails (2.12.4) + rubocop-rails (2.13.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.7.0, < 2.0) @@ -644,7 +644,7 @@ GEM writeexcel (1.0.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.5.1) + zeitwerk (2.5.2) zendesk_api (1.33.0) faraday (>= 0.9.0, < 2.0.0) hashie (>= 3.5.2, < 5.0.0) diff --git a/app/controllers/application_controller/handles_devices.rb b/app/controllers/application_controller/handles_devices.rb index 02db0d8be..91e7e9558 100644 --- a/app/controllers/application_controller/handles_devices.rb +++ b/app/controllers/application_controller/handles_devices.rb @@ -24,9 +24,9 @@ module ApplicationController::HandlesDevices if user_device_updated_at # check if entry exists / only if write action - diff = Time.zone.now - 10.minutes + diff = 10.minutes.ago if %w[GET OPTIONS HEAD].include?(request.method) - diff = Time.zone.now - 30.minutes + diff = 30.minutes.ago end # only update if needed diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb index d85d743aa..2460680e3 100644 --- a/app/controllers/monitoring_controller.rb +++ b/app/controllers/monitoring_controller.rb @@ -34,7 +34,7 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX actions = Set.new # channel check - last_run_tolerance = Time.zone.now - 1.hour + last_run_tolerance = 1.hour.ago options_keys = %w[host user uid] Channel.where(active: true).each do |channel| @@ -124,7 +124,7 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX end # job count check - total_jobs = Delayed::Job.where('created_at < ?', Time.zone.now - 15.minutes).count + total_jobs = Delayed::Job.where('created_at < ?', 15.minutes.ago).count if total_jobs > 8000 issues.push "#{total_jobs} background jobs in queue" end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 174ce4d94..d95d43bd2 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -151,7 +151,7 @@ class ReportsController < ApplicationController case params[:timeRange] when 'realtime' - start_at = (Time.zone.now - 60.minutes) + start_at = 60.minutes.ago stop_at = Time.zone.now range = 'minute' when 'day' diff --git a/app/controllers/user_devices_controller.rb b/app/controllers/user_devices_controller.rb index bc69d29dd..172eab4bc 100644 --- a/app/controllers/user_devices_controller.rb +++ b/app/controllers/user_devices_controller.rb @@ -17,7 +17,7 @@ class UserDevicesController < ApplicationController attributes.delete('fingerprint') # mark current device to prevent killing own session via user preferences device management - if session[:user_device_fingerprint] == device.fingerprint && device.updated_at > Time.zone.now - 30.minutes + if session[:user_device_fingerprint] == device.fingerprint && device.updated_at > 30.minutes.ago attributes['current'] = true end devices_full.push attributes diff --git a/app/models/channel/driver/facebook.rb b/app/models/channel/driver/facebook.rb index 2ab79c93b..00688e1d7 100644 --- a/app/models/channel/driver/facebook.rb +++ b/app/models/channel/driver/facebook.rb @@ -56,7 +56,7 @@ class Channel::Driver::Facebook # only fetch once in 5 minutes return true if !channel.preferences return true if !channel.preferences[:last_fetch] - return false if channel.preferences[:last_fetch] > Time.zone.now - 5.minutes + return false if channel.preferences[:last_fetch] > 5.minutes.ago true end diff --git a/app/models/channel/driver/imap.rb b/app/models/channel/driver/imap.rb index c58b34f1a..736802c9e 100644 --- a/app/models/channel/driver/imap.rb +++ b/app/models/channel/driver/imap.rb @@ -437,7 +437,7 @@ returns Rails.logger.error e return true end - return true if verify_time < Time.zone.now - 30.minutes + return true if verify_time < 30.minutes.ago Rails.logger.info " - ignore message #{count}/#{count_all} - because message has a verify message" diff --git a/app/models/channel/driver/pop3.rb b/app/models/channel/driver/pop3.rb index c111a5d6d..253daccf2 100644 --- a/app/models/channel/driver/pop3.rb +++ b/app/models/channel/driver/pop3.rb @@ -152,7 +152,7 @@ returns if mail.match?(%r{(X-Zammad-Ignore: true|X-Zammad-Verify: true)}) && mail =~ %r{X-Zammad-Verify-Time:\s(.+?)\s} begin verify_time = Time.zone.parse($1) - if verify_time > Time.zone.now - 30.minutes + if verify_time > 30.minutes.ago info = " - ignore message #{count}/#{count_all} - because it's a verify message" Rails.logger.info info next diff --git a/app/models/channel/driver/twitter.rb b/app/models/channel/driver/twitter.rb index 7e4190d41..0d66a0ca3 100644 --- a/app/models/channel/driver/twitter.rb +++ b/app/models/channel/driver/twitter.rb @@ -80,7 +80,7 @@ returns # only fetch once in 30 minutes return true if !channel.preferences return true if !channel.preferences[:last_fetch] - return false if channel.preferences[:last_fetch] > Time.zone.now - 20.minutes + return false if channel.preferences[:last_fetch] > 20.minutes.ago true end diff --git a/app/models/chat.rb b/app/models/chat.rb index 87413df2d..9fa70b070 100644 --- a/app/models/chat.rb +++ b/app/models/chat.rb @@ -507,7 +507,7 @@ optional you can ignore it for dedicated user def self.broadcast_agent_state_update(chat_ids, ignore_user_id = nil) # send broadcast to agents - Chat::Agent.where('active = ? OR updated_at > ?', true, Time.zone.now - 8.hours).each do |item| + Chat::Agent.where('active = ? OR updated_at > ?', true, 8.hours.ago).each do |item| next if item.updated_by_id == ignore_user_id user = User.lookup(id: item.updated_by_id) diff --git a/app/models/job.rb b/app/models/job.rb index 879a9fbc8..42914e884 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -68,10 +68,10 @@ job.run(true) return false if !active # only execute jobs older than 1 min to give admin time to make last-minute changes - return false if updated_at > Time.zone.now - 1.minute + return false if updated_at > 1.minute.ago # check if job got stuck - return false if running == true && last_run_at && Time.zone.now - 1.day < last_run_at + return false if running == true && last_run_at && 1.day.ago < last_run_at # check if jobs need to be executed # ignore if job was running within last 10 min. diff --git a/app/models/knowledge_base/answer.rb b/app/models/knowledge_base/answer.rb index a5f8b24b3..2fd0a28f8 100644 --- a/app/models/knowledge_base/answer.rb +++ b/app/models/knowledge_base/answer.rb @@ -18,8 +18,6 @@ class KnowledgeBase::Answer < ApplicationModel acts_as_list scope: :category, top_of_list: 0 - validates :category, presence: true - # provide consistent naming with KB category alias_attribute :parent, :category diff --git a/app/models/knowledge_base/answer/translation.rb b/app/models/knowledge_base/answer/translation.rb index 9461109e4..29f1e323f 100644 --- a/app/models/knowledge_base/answer/translation.rb +++ b/app/models/knowledge_base/answer/translation.rb @@ -19,7 +19,6 @@ class KnowledgeBase::Answer::Translation < ApplicationModel accepts_nested_attributes_for :content, update_only: true validates :title, presence: true, length: { maximum: 250 } - validates :content, presence: true validates :kb_locale_id, uniqueness: { case_sensitive: true, scope: :answer_id } scope :neighbours_of, ->(translation) { joins(:answer).where(knowledge_base_answers: { category_id: translation.answer&.category_id }) } diff --git a/app/models/knowledge_base/category/translation.rb b/app/models/knowledge_base/category/translation.rb index 9cd29c78c..04cd1d214 100644 --- a/app/models/knowledge_base/category/translation.rb +++ b/app/models/knowledge_base/category/translation.rb @@ -9,10 +9,8 @@ class KnowledgeBase::Category::Translation < ApplicationModel AGENT_ALLOWED_ATTRIBUTES = %i[title kb_locale_id].freeze belongs_to :kb_locale, class_name: 'KnowledgeBase::Locale', inverse_of: :category_translations - validates :kb_locale, presence: true belongs_to :category, class_name: 'KnowledgeBase::Category', inverse_of: :translations, touch: true - validates :category, presence: true validates :title, presence: true validates :kb_locale_id, uniqueness: { case_sensitive: true, scope: :category_id } diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb index 7af7aeee3..2b7b6de6a 100644 --- a/app/models/online_notification.rb +++ b/app/models/online_notification.rb @@ -225,7 +225,7 @@ with dedicated times =end - def self.cleanup(max_age = Time.zone.now - 9.months, max_own_seen = Time.zone.now - 10.minutes, max_auto_seen = Time.zone.now - 8.hours) + def self.cleanup(max_age = Time.zone.now - 9.months, max_own_seen = 10.minutes.ago, max_auto_seen = 8.hours.ago) OnlineNotification.where('created_at < ?', max_age).delete_all OnlineNotification.where('seen = ? AND updated_at < ?', true, max_own_seen).each do |notification| diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 1e1af831c..8cbdceffd 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -186,7 +186,7 @@ returns result = [] # fetch all escalated and soon to be escalating tickets - where('escalation_at <= ?', Time.zone.now + 15.minutes).find_each(batch_size: 500) do |ticket| + where('escalation_at <= ?', 15.minutes.from_now).find_each(batch_size: 500) do |ticket| article_id = nil article = Ticket::Article.last_customer_agent_article(ticket.id) diff --git a/app/models/token.rb b/app/models/token.rb index d3d21c4e5..5da61061d 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -93,7 +93,7 @@ cleanup old token =end def self.cleanup - Token.where('persistent IS ? AND created_at < ?', nil, Time.zone.now - 30.days).delete_all + Token.where('persistent IS ? AND created_at < ?', nil, 30.days.ago).delete_all true end diff --git a/app/models/transaction/karma.rb b/app/models/transaction/karma.rb index 02015d106..83394a7a0 100644 --- a/app/models/transaction/karma.rb +++ b/app/models/transaction/karma.rb @@ -54,7 +54,7 @@ class Transaction::Karma if @item[:type] == 'reminder_reached' return if ticket.owner_id == 1 - return if ticket.pending_time && ticket.pending_time > Time.zone.now - 2.days + return if ticket.pending_time && ticket.pending_time > 2.days.ago Karma::ActivityLog.add('ticket reminder overdue (+2 days)', ticket.owner, 'Ticket', ticket.id) return diff --git a/app/models/user/avatar.rb b/app/models/user/avatar.rb index fa5aa670d..de84421d6 100644 --- a/app/models/user/avatar.rb +++ b/app/models/user/avatar.rb @@ -27,7 +27,7 @@ class User email_address_validation = EmailAddressValidation.new(email) return if !email_address_validation.valid_format? - return if !saved_change_to_attribute?('email') && updated_at > Time.zone.now - 10.days + return if !saved_change_to_attribute?('email') && updated_at > 10.days.ago avatar_auto_detection end diff --git a/db/migrate/20170912123300_remove_network.rb b/db/migrate/20170912123300_remove_network.rb index 1e562679b..389327a69 100644 --- a/db/migrate/20170912123300_remove_network.rb +++ b/db/migrate/20170912123300_remove_network.rb @@ -6,7 +6,6 @@ class RemoveNetwork < ActiveRecord::Migration[5.0] def change return if !ActiveRecord::Base.connection.table_exists? 'networks' - # rubocop:disable Rails/ReversibleMigration drop_table :networks drop_table :network_category_types drop_table :network_privacies @@ -17,6 +16,5 @@ class RemoveNetwork < ActiveRecord::Migration[5.0] drop_table :network_item_plus drop_table :network_category_subscriptions drop_table :network_item_subscriptions - # rubocop:enable Rails/ReversibleMigration end end diff --git a/lib/external_credential/microsoft365.rb b/lib/external_credential/microsoft365.rb index 21c251dc9..0da4f3e23 100644 --- a/lib/external_credential/microsoft365.rb +++ b/lib/external_credential/microsoft365.rb @@ -222,7 +222,7 @@ class ExternalCredential::Microsoft365 end def self.refresh_token(token) - return token if token[:created_at] >= Time.zone.now - 50.minutes + return token if token[:created_at] >= 50.minutes.ago params = refresh_token_params(token) uri = refresh_token_uri(token) diff --git a/lib/session_helper.rb b/lib/session_helper.rb index 429fd36f5..af194fd14 100644 --- a/lib/session_helper.rb +++ b/lib/session_helper.rb @@ -41,10 +41,10 @@ module SessionHelper def self.cleanup_expired # delete temp. sessions - ActiveRecord::SessionStore::Session.where('persistent IS NULL AND updated_at < ?', Time.zone.now - 2.hours).delete_all + ActiveRecord::SessionStore::Session.where('persistent IS NULL AND updated_at < ?', 2.hours.ago).delete_all # web sessions not updated the last x days - ActiveRecord::SessionStore::Session.where('updated_at < ?', Time.zone.now - 60.days).delete_all + ActiveRecord::SessionStore::Session.where('updated_at < ?', 60.days.ago).delete_all end diff --git a/lib/stats/ticket_in_process.rb b/lib/stats/ticket_in_process.rb index b01d77ea5..5f10a4fba 100644 --- a/lib/stats/ticket_in_process.rb +++ b/lib/stats/ticket_in_process.rb @@ -16,14 +16,14 @@ class Stats::TicketInProcess closed_state_ids = Ticket::State.by_category(:closed).pluck(:id) closed_ticket_ids = Ticket.select('id').where( 'owner_id = ? AND state_id IN (?) AND close_at > ?', - user.id, closed_state_ids, Time.zone.now - 1.day + user.id, closed_state_ids, 1.day.ago ).limit(100).pluck(:id) # get all tickets which I changed to pending action pending_action_state_ids = Ticket::State.by_category(:pending_action).pluck(:id) pending_action_ticket_ids = Ticket.select('id').where( 'owner_id = ? AND state_id IN (?) AND updated_at > ?', - user.id, pending_action_state_ids, Time.zone.now - 1.day + user.id, pending_action_state_ids, 1.day.ago ).limit(100).pluck(:id) all_ticket_ids = own_ticket_ids.concat(closed_ticket_ids).concat(pending_action_ticket_ids).uniq @@ -31,7 +31,7 @@ class Stats::TicketInProcess # get count where user worked on history_object = History::Object.lookup(name: 'Ticket') count = History.select('DISTINCT(o_id)').where( - 'histories.created_at >= ? AND histories.history_object_id = ? AND histories.created_by_id = ? AND histories.o_id IN (?)', Time.zone.now - 1.day, history_object.id, user.id, all_ticket_ids + 'histories.created_at >= ? AND histories.history_object_id = ? AND histories.created_by_id = ? AND histories.o_id IN (?)', 1.day.ago, history_object.id, user.id, all_ticket_ids ).count total = all_ticket_ids.count diff --git a/lib/stats/ticket_reopen.rb b/lib/stats/ticket_reopen.rb index abb3a8a7e..281832d02 100644 --- a/lib/stats/ticket_reopen.rb +++ b/lib/stats/ticket_reopen.rb @@ -7,7 +7,7 @@ class Stats::TicketReopen # get my closed tickets total = Ticket.select('id').where( 'owner_id = ? AND close_at > ?', - user.id, Time.zone.now - 7.days + user.id, 7.days.ago ).count # get count of reopens diff --git a/lib/stats/ticket_response_time.rb b/lib/stats/ticket_response_time.rb index 566d4b3bb..af008e7a5 100644 --- a/lib/stats/ticket_response_time.rb +++ b/lib/stats/ticket_response_time.rb @@ -22,7 +22,7 @@ class Stats::TicketResponseTime end def self.generate(user) - items = StatsStore.where('created_at > ? AND created_at < ?', Time.zone.now - 7.days, Time.zone.now).where(key: 'ticket:response_time') + items = StatsStore.where('created_at > ? AND created_at < ?', 7.days.ago, Time.zone.now).where(key: 'ticket:response_time') total = 0 count_own = 0 own = 0 diff --git a/lib/twitter_sync.rb b/lib/twitter_sync.rb index ca17245d5..33993be20 100644 --- a/lib/twitter_sync.rb +++ b/lib/twitter_sync.rb @@ -551,7 +551,7 @@ create a tweet or direct message from an article max_count = 120 max_count *= factor type_id = Ticket::Article::Type.lookup(name: 'twitter status').id - created_at = Time.zone.now - 15.minutes + created_at = 15.minutes.ago created_count = Ticket::Article.where('created_at > ? AND type_id = ?', created_at, type_id).count if created_count > max_count Rails.logger.info "Tweet limit of #{created_count}/#{max_count} reached, ignored tweed id (#{tweet.id})" diff --git a/spec/lib/escalation/ticket_biz_break_spec.rb b/spec/lib/escalation/ticket_biz_break_spec.rb index a6f7682a9..da9f22573 100644 --- a/spec/lib/escalation/ticket_biz_break_spec.rb +++ b/spec/lib/escalation/ticket_biz_break_spec.rb @@ -132,7 +132,7 @@ RSpec.describe Escalation::TicketBizBreak, time_zone: 'Europe/Berlin' do let(:second_value) { result.values.second } it { expect(result.keys.count).to be(6) } - it { expect(result.keys).to eq ((Time.current - 5.days).to_date..Time.current).to_a } + it { expect(result.keys).to eq (5.days.ago.to_date..Time.current).to_a } it { expect(result.values[0].keys).to eq %w[12:00] } it { expect(result.values[0]['12:00']).to eq '24:00' } it { expect(result.values[1].keys).to eq %w[00:00] } @@ -257,7 +257,7 @@ RSpec.describe Escalation::TicketBizBreak, time_zone: 'Europe/Berlin' do let(:history_to) { mock_state_hash(ticket.created_at + 2.days, 'pending close', 'closed') } it { expect(result).to be_a Hash } - it { expect(result.keys).to eq [Time.current.to_date, Time.current.tomorrow.to_date, (Time.current + 2.days).to_date] } + it { expect(result.keys).to eq [Time.current.to_date, Time.current.tomorrow.to_date, 2.days.from_now.to_date] } it { expect(result.values.first).to eq({ '13:30' => '24:00' }) } it { expect(result.values.second).to eq({ '00:00' => '24:00' }) } it { expect(result.values.third).to eq({ '00:00' => '12:00' }) } diff --git a/spec/lib/stats/ticket_waiting_time_spec.rb b/spec/lib/stats/ticket_waiting_time_spec.rb index f000eb98d..9d1147d00 100644 --- a/spec/lib/stats/ticket_waiting_time_spec.rb +++ b/spec/lib/stats/ticket_waiting_time_spec.rb @@ -28,8 +28,8 @@ RSpec.describe Stats::TicketWaitingTime do let(:ticket) { create(:ticket, group: group) } before do - create(:ticket_article, sender_name: 'Customer', ticket: ticket, created_at: Time.current + 1.hour) - create(:ticket_article, sender_name: 'Agent', ticket: ticket, created_at: Time.current + 2.hours) + create(:ticket_article, sender_name: 'Customer', ticket: ticket, created_at: 1.hour.from_now) + create(:ticket_article, sender_name: 'Agent', ticket: ticket, created_at: 2.hours.from_now) end it 'returns a hash with 1-day average ticket wait time across user’s groups (in minutes)' do @@ -42,8 +42,8 @@ RSpec.describe Stats::TicketWaitingTime do let(:ticket) { create(:ticket, group: group, owner_id: user.id) } before do - create(:ticket_article, sender_name: 'Customer', ticket: ticket, created_at: Time.current + 1.hour) - create(:ticket_article, sender_name: 'Agent', ticket: ticket, created_at: Time.current + 2.hours) + create(:ticket_article, sender_name: 'Customer', ticket: ticket, created_at: 1.hour.from_now) + create(:ticket_article, sender_name: 'Agent', ticket: ticket, created_at: 2.hours.from_now) end it 'returns a hash with 1-day average ticket wait time for user (in minutes)' do @@ -66,8 +66,8 @@ RSpec.describe Stats::TicketWaitingTime do let(:other_ticket) { create(:ticket, group: group) } before do - create(:ticket_article, sender_name: 'Customer', ticket: other_ticket, created_at: Time.current + 1.hour) - create(:ticket_article, sender_name: 'Agent', ticket: other_ticket, created_at: Time.current + 3.hours) + create(:ticket_article, sender_name: 'Customer', ticket: other_ticket, created_at: 1.hour.from_now) + create(:ticket_article, sender_name: 'Agent', ticket: other_ticket, created_at: 3.hours.from_now) end it 'returns a hash with 1-day average ticket wait time across user’s groups (in minutes)' do diff --git a/spec/models/channel/filter/import_archive_spec.rb b/spec/models/channel/filter/import_archive_spec.rb index 6b11df816..b6b91f70b 100644 --- a/spec/models/channel/filter/import_archive_spec.rb +++ b/spec/models/channel/filter/import_archive_spec.rb @@ -124,7 +124,7 @@ RSpec.describe Channel::Filter::ImportArchive do context 'when initial ticket (import till outdated)' do let(:channel_as_model) do - Channel.new(options: { inbound: { options: { archive: true, archive_till: (Time.zone.now - 1.day).to_s } } }) + Channel.new(options: { inbound: { options: { archive: true, archive_till: 1.day.ago.to_s } } }) end include_examples 'notification sent checks', 1 @@ -132,7 +132,7 @@ RSpec.describe Channel::Filter::ImportArchive do context 'when initial ticket (import till matched)' do let(:channel_as_model) do - Channel.new(options: { inbound: { options: { archive: true, archive_till: (Time.zone.now + 1.day).to_s } } }) + Channel.new(options: { inbound: { options: { archive: true, archive_till: 1.day.from_now.to_s } } }) end include_examples 'notification sent checks', 0 @@ -156,7 +156,7 @@ RSpec.describe Channel::Filter::ImportArchive do context 'when initial ticket (import till outdated) with channel hash' do let(:channel_as_hash) do - { options: { inbound: { options: { archive: true, archive_till: (Time.zone.now - 1.day).to_s } } } } + { options: { inbound: { options: { archive: true, archive_till: 1.day.ago.to_s } } } } end include_examples 'notification sent checks', 1, true @@ -164,7 +164,7 @@ RSpec.describe Channel::Filter::ImportArchive do context 'when initial ticket (import till matched) with channel hash' do let(:channel_as_hash) do - { options: { inbound: { options: { archive: true, archive_till: (Time.zone.now + 1.day).to_s } } } } + { options: { inbound: { options: { archive: true, archive_till: 1.day.from_now.to_s } } } } end include_examples 'notification sent checks', 0, true diff --git a/spec/models/concerns/checks_core_workflow_examples.rb b/spec/models/concerns/checks_core_workflow_examples.rb index c4b38838a..ae053c85c 100644 --- a/spec/models/concerns/checks_core_workflow_examples.rb +++ b/spec/models/concerns/checks_core_workflow_examples.rb @@ -10,7 +10,7 @@ RSpec.shared_examples 'ChecksCoreWorkflow' do end context 'when creation of closed tickets are only allowed by type set' do - subject(:ticket) { create(:ticket, group: agent_group, screen: 'create_middle', state: Ticket::State.find_by(name: 'open'), pending_time: Time.zone.now + 5.days) } + subject(:ticket) { create(:ticket, group: agent_group, screen: 'create_middle', state: Ticket::State.find_by(name: 'open'), pending_time: 5.days.from_now) } before do create(:core_workflow, @@ -29,7 +29,7 @@ RSpec.shared_examples 'ChecksCoreWorkflow' do end context 'when creation of closed tickets are only allowed by type remove' do - subject(:ticket) { create(:ticket, group: agent_group, screen: 'create_middle', state: Ticket::State.find_by(name: 'open'), pending_time: Time.zone.now + 5.days) } + subject(:ticket) { create(:ticket, group: agent_group, screen: 'create_middle', state: Ticket::State.find_by(name: 'open'), pending_time: 5.days.from_now) } before do create(:core_workflow, @@ -48,7 +48,7 @@ RSpec.shared_examples 'ChecksCoreWorkflow' do end context 'when creation of closed tickets are only allowed by type add' do - subject(:ticket) { create(:ticket, group: agent_group, screen: 'create_middle', state: Ticket::State.find_by(name: 'open'), pending_time: Time.zone.now + 5.days) } + subject(:ticket) { create(:ticket, group: agent_group, screen: 'create_middle', state: Ticket::State.find_by(name: 'open'), pending_time: 5.days.from_now) } before do create(:core_workflow, diff --git a/spec/models/core_workflow/attributes_spec.rb b/spec/models/core_workflow/attributes_spec.rb index b0a24fa0d..21b8a38da 100644 --- a/spec/models/core_workflow/attributes_spec.rb +++ b/spec/models/core_workflow/attributes_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe CoreWorkflow::Attributes, type: :model do - let!(:ticket) { create(:ticket, state: Ticket::State.find_by(name: 'pending reminder'), pending_time: Time.zone.now + 5.days) } + let!(:ticket) { create(:ticket, state: Ticket::State.find_by(name: 'pending reminder'), pending_time: 5.days.from_now) } let!(:base_payload) do { 'event' => 'core_workflow', diff --git a/spec/models/core_workflow_spec.rb b/spec/models/core_workflow_spec.rb index 4bb468d8b..4b35060f7 100644 --- a/spec/models/core_workflow_spec.rb +++ b/spec/models/core_workflow_spec.rb @@ -4,7 +4,7 @@ require 'rails_helper' RSpec.describe CoreWorkflow, type: :model do let(:group) { create(:group) } - let!(:ticket) { create(:ticket, state: Ticket::State.find_by(name: 'pending reminder'), pending_time: Time.zone.now + 5.days, group: group) } + let!(:ticket) { create(:ticket, state: Ticket::State.find_by(name: 'pending reminder'), pending_time: 5.days.from_now, group: group) } let!(:base_payload) do { 'event' => 'core_workflow', diff --git a/spec/requests/integration/monitoring_spec.rb b/spec/requests/integration/monitoring_spec.rb index fe2835846..acbaebdb2 100644 --- a/spec/requests/integration/monitoring_spec.rb +++ b/spec/requests/integration/monitoring_spec.rb @@ -393,7 +393,7 @@ RSpec.describe 'Monitoring', type: :request do # health_check - scheduler may not run scheduler = Scheduler.where(active: true).last - scheduler.last_run = Time.zone.now - 20.minutes + scheduler.last_run = 20.minutes.ago scheduler.period = 600 scheduler.save! @@ -408,7 +408,7 @@ RSpec.describe 'Monitoring', type: :request do # health_check - scheduler may not run scheduler = Scheduler.where(active: true).last - scheduler.last_run = Time.zone.now - 1.day + scheduler.last_run = 1.day.ago scheduler.period = 600 scheduler.save! diff --git a/spec/requests/integration/user_device_spec.rb b/spec/requests/integration/user_device_spec.rb index bb07372e5..f2ec8395d 100644 --- a/spec/requests/integration/user_device_spec.rb +++ b/spec/requests/integration/user_device_spec.rb @@ -138,7 +138,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do user_device_last = UserDevice.last expect(user_device_first.updated_at.to_s).to eq(user_device_last.updated_at.to_s) - ENV['USER_DEVICE_UPDATED_AT'] = (Time.zone.now - 4.hours).to_s + ENV['USER_DEVICE_UPDATED_AT'] = 4.hours.ago.to_s params = {} get '/api/v1/users', params: params, as: :json expect(response).to have_http_status(:ok) @@ -393,7 +393,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do expect(user_device_first.id).to eq(user_device_last.id) expect(user_device_first.updated_at.to_s).to eq(user_device_last.updated_at.to_s) - user_device_last.updated_at = Time.zone.now - 4.hours + user_device_last.updated_at = 4.hours.ago user_device_last.save! params = {} @@ -567,7 +567,7 @@ RSpec.describe 'User Device', type: :request, sends_notification_emails: true do expect(UserDevice.where(user_id: agent.id).count).to eq(0) - ENV['USER_DEVICE_UPDATED_AT'] = (Time.zone.now - 4.hours).to_s + ENV['USER_DEVICE_UPDATED_AT'] = 4.hours.ago.to_s params = {} get '/api/v1/users', params: params, as: :json expect(response).to have_http_status(:ok) diff --git a/test/integration/slack_test.rb b/test/integration/slack_test.rb index d312320bf..9ca2f9f7c 100644 --- a/test/integration/slack_test.rb +++ b/test/integration/slack_test.rb @@ -126,7 +126,7 @@ class SlackTest < ActiveSupport::TestCase assert_equal(1, slack_check(channel, hash)) ticket2.state = Ticket::State.find_by(name: 'pending reminder') - ticket2.pending_time = Time.zone.now - 2.days + ticket2.pending_time = 2.days.ago ticket2.save TransactionDispatcher.commit diff --git a/test/unit/karma_test.rb b/test/unit/karma_test.rb index 4d924c29a..56f9b83e0 100644 --- a/test/unit/karma_test.rb +++ b/test/unit/karma_test.rb @@ -52,8 +52,8 @@ class KarmaTest < ActiveSupport::TestCase priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: agent1.id, created_by_id: agent1.id, - updated_at: Time.zone.now - 10.hours, - created_at: Time.zone.now - 10.hours, + updated_at: 10.hours.ago, + created_at: 10.hours.ago, ) Ticket::Article.create!( ticket_id: ticket1.id, @@ -67,8 +67,8 @@ class KarmaTest < ActiveSupport::TestCase type: Ticket::Article::Type.lookup(name: 'phone'), updated_by_id: agent1.id, created_by_id: agent1.id, - updated_at: Time.zone.now - 10.hours, - created_at: Time.zone.now - 10.hours, + updated_at: 10.hours.ago, + created_at: 10.hours.ago, ) assert(ticket1) @@ -90,8 +90,8 @@ class KarmaTest < ActiveSupport::TestCase ticket1.state = Ticket::State.lookup(name: 'pending reminder') ticket1.updated_by_id = agent1.id - ticket1.updated_at = Time.zone.now - 9.hours - ticket1.created_at = Time.zone.now - 9.hours + ticket1.updated_at = 9.hours.ago + ticket1.created_at = 9.hours.ago ticket1.save! # execute object transaction @@ -112,8 +112,8 @@ class KarmaTest < ActiveSupport::TestCase ticket1.state = Ticket::State.lookup(name: 'pending close') ticket1.updated_by_id = agent1.id - ticket1.updated_at = Time.zone.now - 9.hours - ticket1.created_at = Time.zone.now - 9.hours + ticket1.updated_at = 9.hours.ago + ticket1.created_at = 9.hours.ago ticket1.save! # execute object transaction @@ -126,8 +126,8 @@ class KarmaTest < ActiveSupport::TestCase ticket1.state = Ticket::State.lookup(name: 'closed') ticket1.updated_by_id = agent2.id - ticket1.updated_at = Time.zone.now - 9.hours - ticket1.created_at = Time.zone.now - 9.hours + ticket1.updated_at = 9.hours.ago + ticket1.created_at = 9.hours.ago ticket1.save! # execute object transaction @@ -192,8 +192,8 @@ class KarmaTest < ActiveSupport::TestCase type: Ticket::Article::Type.lookup(name: 'phone'), updated_by_id: customer1.id, created_by_id: customer1.id, - updated_at: Time.zone.now - 8.hours, - created_at: Time.zone.now - 8.hours, + updated_at: 8.hours.ago, + created_at: 8.hours.ago, ) # execute object transaction @@ -264,8 +264,8 @@ class KarmaTest < ActiveSupport::TestCase type: Ticket::Article::Type.lookup(name: 'phone'), updated_by_id: customer1.id, created_by_id: customer1.id, - updated_at: Time.zone.now - 7.hours, - created_at: Time.zone.now - 7.hours, + updated_at: 7.hours.ago, + created_at: 7.hours.ago, ) # execute object transaction @@ -356,8 +356,8 @@ class KarmaTest < ActiveSupport::TestCase priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: agent1.id, created_by_id: agent1.id, - updated_at: Time.zone.now - 10.hours, - created_at: Time.zone.now - 10.hours, + updated_at: 10.hours.ago, + created_at: 10.hours.ago, ) Ticket::Article.create!( ticket_id: ticket2.id, @@ -371,8 +371,8 @@ class KarmaTest < ActiveSupport::TestCase type: Ticket::Article::Type.lookup(name: 'phone'), updated_by_id: agent1.id, created_by_id: agent1.id, - updated_at: Time.zone.now - 2.hours, - created_at: Time.zone.now - 2.hours, + updated_at: 2.hours.ago, + created_at: 2.hours.ago, ) assert(ticket2) @@ -385,7 +385,7 @@ class KarmaTest < ActiveSupport::TestCase assert_equal(0, Karma.score_by_user(customer1)) ticket2.state = Ticket::State.lookup(name: 'pending reminder') - ticket2.pending_time = Time.zone.now - 1.day + ticket2.pending_time = 1.day.ago ticket2.save! Ticket.process_pending @@ -395,7 +395,7 @@ class KarmaTest < ActiveSupport::TestCase assert_equal(0, Karma.score_by_user(customer1)) ticket2.state = Ticket::State.lookup(name: 'pending reminder') - ticket2.pending_time = Time.zone.now - 3.days + ticket2.pending_time = 3.days.ago ticket2.save! Ticket.process_pending diff --git a/test/unit/online_notifiaction_test.rb b/test/unit/online_notifiaction_test.rb index c1b034228..f4faa8031 100644 --- a/test/unit/online_notifiaction_test.rb +++ b/test/unit/online_notifiaction_test.rb @@ -582,8 +582,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase user_id: @agent_user1.id, created_by_id: 1, updated_by_id: 1, - created_at: Time.zone.now - 2.days, - updated_at: Time.zone.now - 2.days, + created_at: 2.days.ago, + updated_at: 2.days.ago, ) online_notification4 = OnlineNotification.add( type: 'create', @@ -593,8 +593,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase user_id: @agent_user1.id, created_by_id: @agent_user1.id, updated_by_id: @agent_user1.id, - created_at: Time.zone.now - 2.days, - updated_at: Time.zone.now - 2.days, + created_at: 2.days.ago, + updated_at: 2.days.ago, ) online_notification5 = OnlineNotification.add( type: 'create', @@ -604,8 +604,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase user_id: @agent_user1.id, created_by_id: @agent_user2.id, updated_by_id: @agent_user2.id, - created_at: Time.zone.now - 2.days, - updated_at: Time.zone.now - 2.days, + created_at: 2.days.ago, + updated_at: 2.days.ago, ) online_notification6 = OnlineNotification.add( type: 'create', @@ -615,8 +615,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase user_id: @agent_user1.id, created_by_id: @agent_user1.id, updated_by_id: @agent_user1.id, - created_at: Time.zone.now - 5.minutes, - updated_at: Time.zone.now - 5.minutes, + created_at: 5.minutes.ago, + updated_at: 5.minutes.ago, ) online_notification7 = OnlineNotification.add( type: 'create', @@ -626,8 +626,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase user_id: @agent_user1.id, created_by_id: @agent_user2.id, updated_by_id: @agent_user2.id, - created_at: Time.zone.now - 5.minutes, - updated_at: Time.zone.now - 5.minutes, + created_at: 5.minutes.ago, + updated_at: 5.minutes.ago, ) OnlineNotification.cleanup diff --git a/test/unit/ticket_overview_out_of_office_test.rb b/test/unit/ticket_overview_out_of_office_test.rb index 83a00694c..70bfc6873 100644 --- a/test/unit/ticket_overview_out_of_office_test.rb +++ b/test/unit/ticket_overview_out_of_office_test.rb @@ -169,8 +169,8 @@ class TicketOverviewOutOfOfficeTest < ActiveSupport::TestCase assert_equal(1, result.count) assert_equal('My Tickets', result[0].name) @agent1.out_of_office = true - @agent1.out_of_office_start_at = Time.zone.now - 2.days - @agent1.out_of_office_end_at = Time.zone.now + 2.days + @agent1.out_of_office_start_at = 2.days.ago + @agent1.out_of_office_end_at = 2.days.from_now @agent1.out_of_office_replacement_id = @agent2.id @agent1.save! @@ -220,8 +220,8 @@ class TicketOverviewOutOfOfficeTest < ActiveSupport::TestCase assert(result[0][:tickets].blank?) @agent1.out_of_office = true - @agent1.out_of_office_start_at = Time.zone.now - 2.days - @agent1.out_of_office_end_at = Time.zone.now + 2.days + @agent1.out_of_office_start_at = 2.days.ago + @agent1.out_of_office_end_at = 2.days.from_now @agent1.out_of_office_replacement_id = @agent2.id @agent1.save! diff --git a/test/unit/ticket_selector_test.rb b/test/unit/ticket_selector_test.rb index 27b9b49c1..3da9a5924 100644 --- a/test/unit/ticket_selector_test.rb +++ b/test/unit/ticket_selector_test.rb @@ -465,7 +465,7 @@ class TicketSelectorTest < ActiveSupport::TestCase }, 'ticket.updated_at' => { operator: 'before (absolute)', - value: (Time.zone.now + 1.day).iso8601, + value: 1.day.from_now.iso8601, }, } ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1) @@ -487,7 +487,7 @@ class TicketSelectorTest < ActiveSupport::TestCase }, 'ticket.updated_at' => { operator: 'before (absolute)', - value: (Time.zone.now - 1.day).iso8601, + value: 1.day.ago.iso8601, }, } ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1) @@ -509,7 +509,7 @@ class TicketSelectorTest < ActiveSupport::TestCase }, 'ticket.updated_at' => { operator: 'after (absolute)', - value: (Time.zone.now + 1.day).iso8601, + value: 1.day.from_now.iso8601, }, } ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1) @@ -531,7 +531,7 @@ class TicketSelectorTest < ActiveSupport::TestCase }, 'ticket.updated_at' => { operator: 'after (absolute)', - value: (Time.zone.now - 1.day).iso8601, + value: 1.day.ago.iso8601, }, } ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)