Maintenance: Activated rubocop rule Layout/ExtraSpacing.

This commit is contained in:
Thorsten Eckel 2020-06-22 11:57:45 +02:00
parent 0eedc58558
commit 9d4aff5eb0
65 changed files with 133 additions and 131 deletions

View file

@ -139,6 +139,14 @@ Layout/EmptyLinesAroundModuleBody:
Description: "Keeps track of empty lines around module bodies."
Enabled: false
Layout/ExtraSpacing:
Description: 'Do not use unnecessary spacing.'
Enabled: true
Exclude:
- 'config/routes/**/*'
- 'db/migrate/20120101000001_create_base.rb'
- 'db/migrate/20120101000010_create_ticket.rb'
Style/MultilineBlockChain:
Description: 'Avoid multi-line chains of blocks.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'

View file

@ -6,12 +6,6 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 163
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Enabled: false
# Offense count: 8
# Configuration parameters: MaximumRangeSize.
Lint/MissingCopEnableDirective:

View file

@ -53,9 +53,9 @@ class ChecksKbClientNotificationJob < ApplicationJob
.sessions
.map { |client_id| Sessions.get(client_id)&.dig(:user, 'id') }
.compact
.map { |user_id| User.find_by(id: user_id) }
.map { |user_id| User.find_by(id: user_id) }
.compact
.select { |user| user.permissions? "knowledge_base.#{permission_suffix}" }
.select { |user| user.permissions? "knowledge_base.#{permission_suffix}" }
end
def self.notify_later(object, event)

View file

@ -12,7 +12,7 @@ class TicketArticleCommunicateEmailJob < ApplicationJob
subject_prefix_mode = record.preferences[:subtype]
subject = ticket.subject_build(record.subject, subject_prefix_mode)
subject = ticket.subject_build(record.subject, subject_prefix_mode)
# set retry count
record.preferences['delivery_retry'] ||= 0

View file

@ -163,7 +163,7 @@ returns
# do lookup with == to handle case insensitive databases
records = if Rails.application.config.db_case_sensitive
where('LOWER(email) = LOWER(?)', data[:email])
where('LOWER(email) = LOWER(?)', data[:email])
else
where(email: data[:email])
end

View file

@ -48,8 +48,8 @@ returns
def find_and_save_to_cache_by(attr)
record = find_by(attr)
return nil if string_key?(attr.keys.first) && (record&.send(attr.keys.first) != attr.values.first) # enforce case-sensitivity on MySQL
return record if ActiveRecord::Base.connection.transaction_open? # rollbacks can invalidate cache entries
return nil if string_key?(attr.keys.first) && (record&.send(attr.keys.first) != attr.values.first) # enforce case-sensitivity on MySQL
return record if ActiveRecord::Base.connection.transaction_open? # rollbacks can invalidate cache entries
cache_set(attr.values.first, record)
record

View file

@ -4,7 +4,7 @@ class EmailAddress < ApplicationModel
include ChecksLatestChangeObserved
include HasCollectionUpdate
has_many :groups, after_add: :cache_update, after_remove: :cache_update
has_many :groups, after_add: :cache_update, after_remove: :cache_update
belongs_to :channel, optional: true
validates :realname, presence: true
validates :email, presence: true

View file

@ -2,5 +2,5 @@
class Karma::Activity < ApplicationModel
self.table_name = 'karma_activities'
validates :name, presence: true
validates :name, presence: true
end

View file

@ -10,7 +10,7 @@ class KnowledgeBase::Answer < ApplicationModel
AGENT_ALLOWED_ATTRIBUTES = %i[category_id promoted internal_note].freeze
AGENT_ALLOWED_NESTED_RELATIONS = %i[translations].freeze
belongs_to :category, class_name: 'KnowledgeBase::Category', inverse_of: :answers, touch: true
belongs_to :category, class_name: 'KnowledgeBase::Category', inverse_of: :answers, touch: true
scope :include_contents, -> { eager_load(translations: :content) }
scope :sorted, -> { order(position: :asc) }

View file

@ -16,7 +16,7 @@ class KnowledgeBase::Answer::Translation < ApplicationModel
belongs_to :content, class_name: 'KnowledgeBase::Answer::Translation::Content', inverse_of: :translation, dependent: :destroy
accepts_nested_attributes_for :content, update_only: true
validates :title, presence: true, length: { maximum: 250 }
validates :title, presence: true, length: { maximum: 250 }
validates :content, presence: true
validates :kb_locale_id, uniqueness: { scope: :answer_id }

View file

@ -7,7 +7,7 @@ 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
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

View file

@ -50,5 +50,5 @@ class KnowledgeBase::Locale < ApplicationModel
knowledge_base.kb_locales.find_by(primary: true)
end
scope :available_for, ->(object) { where(id: object.translations.select(:kb_locale_id)) }
scope :available_for, ->(object) { where(id: object.translations.select(:kb_locale_id)) }
end

View file

@ -932,7 +932,7 @@ is certain attribute used by triggers, overviews or schedulers
# fixes issue #2236 - Naming an attribute "attribute" causes ActiveRecord failure
begin
ObjectLookup.by_id(object_lookup_id).constantize.instance_method_already_implemented? name
rescue ActiveRecord::DangerousAttributeError
rescue ActiveRecord::DangerousAttributeError
errors.add(:name, "#{name} is a reserved word! (2)")
end

View file

@ -1,6 +1,6 @@
class Report::Profile < ApplicationModel
self.table_name = 'report_profiles'
validates :name, presence: true
validates :name, presence: true
store :condition
def self.list

View file

@ -17,7 +17,7 @@ class Role < ApplicationModel
after_add: :cache_update,
before_remove: :last_admin_check_by_permission,
after_remove: :cache_update
validates :name, presence: true
validates :name, presence: true
store :preferences
before_create :check_default_at_signup_permissions

View file

@ -176,7 +176,7 @@ reload config settings
# convert state into hash to be able to store it as store
def state_check
return true if state.nil? # allow false value
return true if state.nil? # allow false value
return true if state.try(:key?, :value)
self.state_current = { value: state }

View file

@ -405,7 +405,7 @@ Get source file at https://i18n.zammad.com/api/v1/translations_empty_translation
col_sep: ',',
}
rows = ::CSV.parse(content, params)
rows.shift # remove header
rows.shift # remove header
translation_raw = []
rows.each do |row|

View file

@ -1,6 +1,6 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
require ::File.expand_path('../config/environment', __FILE__)
run Zammad::Application
# set config to do no self notification

View file

@ -79,7 +79,7 @@ class CreateTicket < ActiveRecord::Migration[4.2]
t.column :pending_time, :timestamp, limit: 3, null: true
t.column :type, :string, limit: 100, null: true
t.column :time_unit, :decimal, precision: 6, scale: 2, null: true
t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
t.column :updated_by_id, :integer, null: false
t.column :created_by_id, :integer, null: false
t.timestamps limit: 3, null: false
@ -185,8 +185,8 @@ class CreateTicket < ActiveRecord::Migration[4.2]
t.column :content_type, :string, limit: 20, null: false, default: 'text/plain'
t.column :references, :string, limit: 3200, null: true
t.column :body, :text, limit: 20.megabytes + 1, null: false
t.column :internal, :boolean, null: false, default: false
t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
t.column :internal, :boolean, null: false, default: false
t.column :preferences, :text, limit: 500.kilobytes + 1, null: true
t.column :updated_by_id, :integer, null: false
t.column :created_by_id, :integer, null: false
t.column :origin_by_id, :integer
@ -212,7 +212,7 @@ class CreateTicket < ActiveRecord::Migration[4.2]
t.column :key, :string, limit: 50, null: false
t.column :value, :string, limit: 50, null: true
t.column :created_by_id, :integer, null: false
t.timestamps limit: 3, null: false
t.timestamps limit: 3, null: false
end
add_index :ticket_article_flags, %i[ticket_article_id created_by_id], name: 'index_ticket_article_flags_on_articles_id_and_created_by_id'
add_index :ticket_article_flags, %i[ticket_article_id key]
@ -252,7 +252,7 @@ class CreateTicket < ActiveRecord::Migration[4.2]
t.column :group_direction, :string, limit: 250, null: true
t.column :organization_shared, :boolean, null: false, default: false
t.column :out_of_office, :boolean, null: false, default: false
t.column :view, :string, limit: 1000, null: false
t.column :view, :string, limit: 1000, null: false
t.column :active, :boolean, null: false, default: true
t.column :updated_by_id, :integer, null: false
t.column :created_by_id, :integer, null: false
@ -290,7 +290,7 @@ class CreateTicket < ActiveRecord::Migration[4.2]
add_foreign_key :overviews_groups, :groups
create_table :triggers do |t|
t.column :name, :string, limit: 250, null: false
t.column :name, :string, limit: 250, null: false
t.column :condition, :text, limit: 500.kilobytes + 1, null: false
t.column :perform, :text, limit: 500.kilobytes + 1, null: false
t.column :disable_notification, :boolean, null: false, default: true
@ -349,7 +349,7 @@ class CreateTicket < ActiveRecord::Migration[4.2]
t.column :active, :boolean, null: false, default: true
t.timestamps limit: 3, null: false
end
add_index :link_objects, [:name], unique: true
add_index :link_objects, [:name], unique: true
create_table :links do |t|
t.references :link_type, null: false
@ -462,11 +462,11 @@ class CreateTicket < ActiveRecord::Migration[4.2]
add_foreign_key :slas, :users, column: :updated_by_id
create_table :macros do |t|
t.string :name, limit: 250, null: true
t.string :name, limit: 250, null: true
t.text :perform, limit: 500.kilobytes + 1, null: false
t.boolean :active, null: false, default: true
t.string :ux_flow_next_up, null: false, default: 'none'
t.string :note, limit: 250, null: true
t.string :note, limit: 250, null: true
t.integer :updated_by_id, null: false
t.integer :created_by_id, null: false
t.timestamps limit: 3, null: false
@ -476,9 +476,9 @@ class CreateTicket < ActiveRecord::Migration[4.2]
add_foreign_key :macros, :users, column: :updated_by_id
create_table :chats do |t|
t.string :name, limit: 250, null: true
t.integer :max_queue, null: false, default: 5
t.string :note, limit: 250, null: true
t.string :name, limit: 250, null: true
t.integer :max_queue, null: false, default: 5
t.string :note, limit: 250, null: true
t.boolean :active, null: false, default: true
t.boolean :public, null: false, default: false
t.string :block_ip, limit: 5000, null: true
@ -511,7 +511,7 @@ class CreateTicket < ActiveRecord::Migration[4.2]
t.string :name, limit: 250, null: true
t.string :state, limit: 50, null: false, default: 'waiting' # running, closed
t.references :user, null: true
t.text :preferences, limit: 100.kilobytes + 1, null: true
t.text :preferences, limit: 100.kilobytes + 1, null: true
t.integer :updated_by_id, null: true
t.integer :created_by_id, null: true
t.timestamps limit: 3, null: false
@ -526,9 +526,9 @@ class CreateTicket < ActiveRecord::Migration[4.2]
add_foreign_key :chat_sessions, :users, column: :updated_by_id
create_table :chat_messages do |t|
t.references :chat_session, null: false
t.text :content, limit: 20.megabytes + 1, null: false
t.integer :created_by_id, null: true
t.references :chat_session, null: false
t.text :content, limit: 20.megabytes + 1, null: false
t.integer :created_by_id, null: true
t.timestamps limit: 3, null: false
end
add_index :chat_messages, [:chat_session_id]
@ -549,7 +549,7 @@ class CreateTicket < ActiveRecord::Migration[4.2]
add_foreign_key :chat_agents, :users, column: :updated_by_id
create_table :report_profiles do |t|
t.column :name, :string, limit: 150, null: true
t.column :name, :string, limit: 150, null: true
t.column :condition, :text, limit: 500.kilobytes + 1, null: true
t.column :active, :boolean, null: false, default: true
t.column :updated_by_id, :integer, null: false
@ -563,7 +563,7 @@ class CreateTicket < ActiveRecord::Migration[4.2]
create_table :karma_users do |t|
t.references :user, null: false
t.integer :score, null: false
t.string :level, limit: 200, null: false
t.string :level, limit: 200, null: false
t.timestamps limit: 3, null: false
end
add_index :karma_users, [:user_id], unique: true

View file

@ -39,12 +39,12 @@ class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
# https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
#
# t.text :token, null: false
t.string :token, null: false
t.string :token, null: false
t.string :refresh_token
t.integer :expires_in
t.datetime :revoked_at
t.datetime :created_at, null: false
t.datetime :created_at, null: false
t.string :scopes
# If there is a previous_refresh_token column,

View file

@ -14,7 +14,7 @@ class EnhancedPermissions < ActiveRecord::Migration[4.2]
create_table :roles_groups, id: false do |t|
t.references :role, null: false
t.references :group, null: false
t.string :access, limit: 50, null: false, default: 'full'
t.string :access, limit: 50, null: false, default: 'full'
end
add_index :roles_groups, [:role_id]
add_index :roles_groups, [:group_id]

View file

@ -3,7 +3,7 @@ class NormalizeSettingTicketNumberIgnoreSystemId < ActiveRecord::Migration[5.1]
return if !Setting.find_by(name: 'system_init_done')
return if !Setting.exists?(name: 'ticket_number_ignore_system_id')
Setting.find_by(name: 'ticket_number_ignore_system_id')
Setting.find_by(name: 'ticket_number_ignore_system_id')
.update(state_initial: { value: false })
return if Setting.get('ticket_number_ignore_system_id') != { 'ticket_number_ignore_system_id' => false }

View file

@ -48,7 +48,7 @@ class InitializeKnowledgeBase < ActiveRecord::Migration[5.0]
end
create_table :knowledge_base_category_translations do |t|
t.string :title, limit: 250, null: false
t.string :title, limit: 250, null: false
t.references :kb_locale, null: false, foreign_key: { to_table: :knowledge_base_locales }
t.references :category, null: false, foreign_key: { to_table: :knowledge_base_categories, on_delete: :cascade }
@ -78,7 +78,7 @@ class InitializeKnowledgeBase < ActiveRecord::Migration[5.0]
end
create_table :knowledge_base_answer_translations do |t|
t.string :title, limit: 250, null: false
t.string :title, limit: 250, null: false
t.references :kb_locale, null: false, foreign_key: { to_table: :knowledge_base_locales }
t.references :answer, null: false, foreign_key: { to_table: :knowledge_base_answers, on_delete: :cascade }

View file

@ -63,7 +63,7 @@ class SMIMESupport < ActiveRecord::Migration[5.2]
t.datetime :not_after_at, null: true
t.binary :raw, limit: 10.megabytes, null: false
t.binary :private_key, limit: 10.megabytes, null: true
t.string :private_key_secret, limit: 500, null: true
t.string :private_key_secret, limit: 500, null: true
t.timestamps limit: 3, null: false
end
add_index :smime_certificates, [:fingerprint], unique: true

View file

@ -53,7 +53,7 @@ module CanBePublished
end
aasm do
state :draft, initial: true
state :draft, initial: true
state :internal
state :published
state :archived

View file

@ -20,7 +20,7 @@ returns
=end
def self.find_signature(messages)
signature_candidates = Hash.new(0) # <potential_signature>: <score>
signature_candidates = Hash.new(0) # <potential_signature>: <score>
messages = messages.map { |m| m[:content_type].match?(%r{text/html}i) ? m[:content].html2text(true) : m[:content] }
message_pairs = messages.each_cons(2).to_a
diffs = message_pairs.map { |msg_pair| Diffy::Diff.new(*msg_pair).to_s }

View file

@ -126,7 +126,7 @@ returns
end
# store hash in config
return if !list || !list[0]
return if !list || !list[0]
file = Store.find(list[0].id)
filelocation = filename(file)

View file

@ -324,7 +324,7 @@ returns
# find ticket or create one
state_ids = Ticket::State.where(name: %w[closed merged removed]).pluck(:id)
possible_tickets = Ticket.where(customer_id: user.id).where.not(state_id: state_ids).order(:updated_at)
ticket = possible_tickets.find_each.find { |possible_ticket| possible_ticket.preferences[:channel_id] == channel.id }
ticket = possible_tickets.find_each.find { |possible_ticket| possible_ticket.preferences[:channel_id] == channel.id }
if ticket
# check if title need to be updated
@ -732,7 +732,7 @@ returns
# get the last ticket of customer which is not closed yet, and close it
state_ids = Ticket::State.where(name: %w[closed merged removed]).pluck(:id)
possible_tickets = Ticket.where(customer_id: user.id).where.not(state_id: state_ids).order(:updated_at)
ticket = possible_tickets.find_each.find { |possible_ticket| possible_ticket.preferences[:channel_id] == channel.id }
ticket = possible_tickets.find_each.find { |possible_ticket| possible_ticket.preferences[:channel_id] == channel.id }
return if !ticket

View file

@ -22,7 +22,7 @@ module Zammad
end
def self.check_version_compatibility
return if connection.nil? # Edge case: if Postgres can't find a DB to connect to
return if connection.nil? # Edge case: if Postgres can't find a DB to connect to
super
end

View file

@ -6,8 +6,8 @@ module Zammad
class Application
class Initializer
module SessionStore
STORE_TYPE = :active_record_store # default: :cookie_store
SESSION_KEY = ('_zammad_session_' + Digest::MD5.hexdigest(Rails.root.to_s)[5..15]).freeze # default: '_zammad_session'
STORE_TYPE = :active_record_store # default: :cookie_store
SESSION_KEY = ('_zammad_session_' + Digest::MD5.hexdigest(Rails.root.to_s)[5..15]).freeze # default: '_zammad_session'
def self.perform
Rails.application.config.session_store STORE_TYPE,

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../config/application', __dir__)
require File.expand_path('../config/boot', __dir__)
APP_PATH = File.expand_path('../config/application', __dir__)
require File.expand_path('../config/boot', __dir__)
require 'rails/commands'

View file

@ -1,6 +1,6 @@
FactoryBot.define do
factory :job do
sequence(:name) { |n| "Test job #{n}" }
sequence(:name) { |n| "Test job #{n}" }
condition { { 'ticket.state_id' => { 'operator' => 'is not', 'value' => 4 } } }
perform { { 'ticket.state_id' => { 'value' => 4 } } }
active { true }

View file

@ -1,6 +1,6 @@
FactoryBot.define do
factory :postmaster_filter do
sequence(:name) { |n| "Test PostmasterFilter #{n}" }
sequence(:name) { |n| "Test PostmasterFilter #{n}" }
channel { 'email' }
match { { 'from' => { 'operator' => 'contains', 'value' => 'a' } } }
perform { { 'x-zammad-ticket-tags' => { 'operator' => 'remove', 'value' => 'test2, test7' } } }

View file

@ -1,7 +1,7 @@
FactoryBot.define do
factory :text_module do
name { 'text module ' + Faker::Number.unique.number(3) }
keywords { Faker::Superhero.prefix }
keywords { Faker::Superhero.prefix }
content { Faker::Lorem.sentence }
updated_by_id { 1 }
created_by_id { 1 }

View file

@ -5,7 +5,7 @@ FactoryBot.define do
priority_name { '2 normal' }
end
association :group, strategy: :create # or else build(:ticket).save fails
association :group, strategy: :create # or else build(:ticket).save fails
customer
title { 'Test Ticket' }

View file

@ -5,7 +5,7 @@ FactoryBot.define do
sender_name { 'Customer' }
end
association :ticket, strategy: :create # or else build(:ticket_article).save fails
association :ticket, strategy: :create # or else build(:ticket_article).save fails
from { 'factory-customer-1@example.com' }
to { 'factory-customer-1@example.com' }
subject { 'factory article' }
@ -28,7 +28,7 @@ FactoryBot.define do
sender_name { 'Agent' }
trait :reply do
in_reply_to { Faker::Number.number(19) }
in_reply_to { Faker::Number.number(19) }
end
end

View file

@ -6,7 +6,7 @@ RSpec.describe NotificationFactory::Mailer do
context 'for postmaster oversized mail' do
let(:raw_incoming_mail) { File.read(Rails.root.join('test/data/mail/mail010.box')) }
let(:parsed_incoming_mail) { Channel::EmailParser.new.parse raw_incoming_mail }
let(:parsed_incoming_mail) { Channel::EmailParser.new.parse raw_incoming_mail }
let(:incoming_mail) do
mail = OpenStruct.new

View file

@ -5,7 +5,7 @@ RSpec.describe Sessions::Backend::Base do
let(:agent) { create(:agent) }
let(:client_id) { '123-1' }
let(:ttl) { 3 } # seconds
let(:ttl) { 3 } # seconds
let!(:ticket) { Ticket.first || create(:ticket) }
describe '#asset_needed?' do

View file

@ -15,7 +15,7 @@ RSpec.describe Sessions::Backend::TicketOverviewList do
let(:admin) { create(:admin, groups: [group]) }
let(:group) { create(:group) }
let(:client_id) { '12345' }
let(:ttl) { 3 } # seconds
let(:ttl) { 3 } # seconds
context 'when 3rd argument ("client") is false' do
subject(:collection) { described_class.new(admin, {}, false, client_id, ttl) }

View file

@ -38,7 +38,7 @@ RSpec.shared_examples 'ApplicationModel::CanLookup' do
end
describe "cache storage by #{attribute}" do
context 'inside a DB transaction' do # provided by default RSpec config
context 'inside a DB transaction' do # provided by default RSpec config
it 'leaves the cache untouched' do
expect { described_class.lookup(attribute => instance.send(attribute)) }
.not_to change { described_class.cache_get(instance.send(attribute)) }

View file

@ -108,7 +108,7 @@ RSpec.describe Calendar, type: :model do
end
it 'does not create a background job for escalation rebuild' do
calendar # create and sync (1 inital background job is created)
calendar # create and sync (1 inital background job is created)
expect { calendar.sync } # a second sync right after calendar create
.to not_change { Delayed::Job.count }
end

View file

@ -921,7 +921,7 @@ RSpec.describe Channel::Driver::Twitter do
tweet_ids.each { |tweet_id| create(:ticket_article, message_id: tweet_id) }
end
let(:tweet_ids) { [1222126386334388225, 1222109934923460608] } # rubocop:disable Style/NumericLiterals
let(:tweet_ids) { [1222126386334388225, 1222109934923460608] } # rubocop:disable Style/NumericLiterals
it 'does not import duplicates' do
expect { channel.fetch }.not_to change(Ticket::Article, :count)
@ -970,7 +970,7 @@ RSpec.describe Channel::Driver::Twitter do
# Run BG job (Why not use Scheduler.worker?
# It led to hangs & failures elsewhere in test suite.)
Thread.new do
sleep 5 # simulate other bg jobs holding up the queue
sleep 5 # simulate other bg jobs holding up the queue
twitter_job.invoke_job
end.tap { example.run }.join
end

View file

@ -42,9 +42,9 @@ RSpec.describe Channel::EmailParser, type: :model do
end
describe '#process' do
let(:raw_mail) { File.read(mail_file) }
let(:raw_mail) { File.read(mail_file) }
before { Trigger.destroy_all } # triggers may cause additional articles to be created
before { Trigger.destroy_all } # triggers may cause additional articles to be created
describe 'auto-creating new users' do
context 'with one unrecognized email address' do

View file

@ -91,7 +91,7 @@ RSpec.shared_examples 'HasHistory' do |history_relation_object: nil|
describe 'of #owner' do
let(:attribute) { 'owner' }
let(:new_value) { create(:customer) } # Ticket#owner is restricted to active agents of the same group
let(:new_value) { create(:customer) } # Ticket#owner is restricted to active agents of the same group
include_examples 'failed attribute update' if described_class.attribute_names.include?('owner_id')
end

View file

@ -150,7 +150,7 @@ RSpec.describe Cti::CallerId do
context 'and no corresponding CallerId exists' do
it 'generates a CallerId record (with #level "known")' do
described_class.destroy_all # CallerId already generated in User callback
described_class.destroy_all # CallerId already generated in User callback
expect { described_class.rebuild }
.to change { described_class.exists?(user_id: user.id, caller_id: '49123456', level: 'known') }
@ -176,7 +176,7 @@ RSpec.describe Cti::CallerId do
let!(:users) { create_list(:agent, 2, phone: '+49 123 456') }
it 'generates two corresponding CallerId records (with #level "known")' do
described_class.destroy_all # CallerId already generated in User callback
described_class.destroy_all # CallerId already generated in User callback
expect { described_class.rebuild }
.to change { described_class.exists?(user_id: users.first.id, caller_id: '49123456', level: 'known') }
@ -196,7 +196,7 @@ RSpec.describe Cti::CallerId do
let(:sender_name) { 'Customer' }
it 'generates a CallerId record (with #level "maybe")' do
described_class.destroy_all # CallerId already generated in Article observer job
described_class.destroy_all # CallerId already generated in Article observer job
expect { described_class.rebuild }
.to change { described_class.exists?(user_id: article.created_by_id, caller_id: '49123456', level: 'maybe') }

View file

@ -29,7 +29,7 @@ RSpec.describe History, type: :model do
expect(list).to match_array(
[
hash_including(
'o_id' => object.id,
'o_id' => object.id,
),
hash_including(
'o_id' => object.id,
@ -95,7 +95,7 @@ RSpec.describe History, type: :model do
context 'with "related_history_object" argument' do
let!(:object) { related_object.ticket }
let!(:related_object) { create(:ticket_article, internal: true) } # MUST be internal, or else callbacks will create additional histories
let!(:related_object) { create(:ticket_article, internal: true) } # MUST be internal, or else callbacks will create additional histories
before { object.update(title: 'Lorem ipsum dolor') }

View file

@ -177,7 +177,7 @@ RSpec.describe Job, type: :model do
end
it 'updates #next_run_at' do
travel_to(Time.current.last_week) # force new value for #next_run_at
travel_to(Time.current.last_week) # force new value for #next_run_at
expect { job.run }.to change { job.reload.next_run_at }
end
@ -194,7 +194,7 @@ RSpec.describe Job, type: :model do
end
it 'updates #next_run_at' do
travel_to(Time.current.last_week) # force new value for #next_run_at
travel_to(Time.current.last_week) # force new value for #next_run_at
expect { job.run }.to change { job.reload.next_run_at }
end

View file

@ -145,7 +145,7 @@ RSpec.describe RecentView, type: :model do
let(:owner) { agent }
it 'does not create RecentView for records the given user cannot read' do
ticket.update(owner: User.first, # read access may come from ticket ownership,
ticket.update(owner: User.first, # read access may come from ticket ownership,
customer: User.first, # customer status,
organization: nil) # organization's 'shared' status,
agent.update(groups: []) # and membership in the Ticket's group

View file

@ -125,7 +125,7 @@ RSpec.describe Role do
context 'when reactivating a role adds new agents' do
subject(:role) { create(:agent_role, active: false) }
before { create(:user, roles: [role]) }
before { create(:user, roles: [role]) }
context 'exceeding the system limit' do
before { Setting.set('system_agent_limit', agents.count) }

View file

@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe Ticket::Number do
let(:stubbed_subclass) { double('Foo') }
before { stub_const('Ticket::Number::Foo', stubbed_subclass) }
before { stub_const('Ticket::Number::Foo', stubbed_subclass) }
describe '.generate' do
before { Setting.set('ticket_number', 'Ticket::Number::Foo') }

View file

@ -520,7 +520,7 @@ RSpec.describe Ticket, type: :model do
end
describe '#escalation_at' do
before { travel_to(Time.current) } # freeze time
before { travel_to(Time.current) } # freeze time
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
let(:calendar) { create(:calendar, :'24/7') }
@ -532,7 +532,7 @@ RSpec.describe Ticket, type: :model do
end
context 'with an SLA in the system' do
before { sla } # create sla
before { sla } # create sla
it 'is set based on SLAs #first_response_time' do
expect(ticket.reload.escalation_at.to_i)
@ -540,12 +540,12 @@ RSpec.describe Ticket, type: :model do
end
context 'after first agents response' do
before { ticket } # create ticket
before { ticket } # create ticket
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
it 'is updated based on the SLAs #update_time' do
travel(1.minute) # time is frozen: if we don't travel forward, pre- and post-update values will be the same
travel(1.minute) # time is frozen: if we don't travel forward, pre- and post-update values will be the same
expect { article }
.to change { ticket.reload.escalation_at.to_i }
@ -554,7 +554,7 @@ RSpec.describe Ticket, type: :model do
context 'when new #update_time is later than original #solution_time' do
it 'is updated based on the original #solution_time' do
travel(2.hours) # time is frozen: if we don't travel forward, pre- and post-update values will be the same
travel(2.hours) # time is frozen: if we don't travel forward, pre- and post-update values will be the same
expect { article }
.to change { ticket.reload.escalation_at.to_i }
@ -591,7 +591,7 @@ RSpec.describe Ticket, type: :model do
end
describe '#first_response_escalation_at' do
before { travel_to(Time.current) } # freeze time
before { travel_to(Time.current) } # freeze time
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
let(:calendar) { create(:calendar, :'24/7') }
@ -603,7 +603,7 @@ RSpec.describe Ticket, type: :model do
end
context 'with an SLA in the system' do
before { sla } # create sla
before { sla } # create sla
it 'is set based on SLAs #first_response_time' do
expect(ticket.reload.first_response_escalation_at.to_i)
@ -611,7 +611,7 @@ RSpec.describe Ticket, type: :model do
end
context 'after first agents response' do
before { ticket } # create ticket
before { ticket } # create ticket
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
@ -623,7 +623,7 @@ RSpec.describe Ticket, type: :model do
end
describe '#update_escalation_at' do
before { travel_to(Time.current) } # freeze time
before { travel_to(Time.current) } # freeze time
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
let(:calendar) { create(:calendar, :'24/7') }
@ -635,7 +635,7 @@ RSpec.describe Ticket, type: :model do
end
context 'with an SLA in the system' do
before { sla } # create sla
before { sla } # create sla
it 'is set based on SLAs #update_time' do
expect(ticket.reload.update_escalation_at.to_i)
@ -643,12 +643,12 @@ RSpec.describe Ticket, type: :model do
end
context 'after first agents response' do
before { ticket } # create ticket
before { ticket } # create ticket
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
it 'is updated based on the SLAs #update_time' do
travel(1.minute) # time is frozen: if we don't travel forward, pre- and post-update values will be the same
travel(1.minute) # time is frozen: if we don't travel forward, pre- and post-update values will be the same
expect { article }
.to change { ticket.reload.update_escalation_at.to_i }
@ -659,7 +659,7 @@ RSpec.describe Ticket, type: :model do
end
describe '#close_escalation_at' do
before { travel_to(Time.current) } # freeze time
before { travel_to(Time.current) } # freeze time
let(:sla) { create(:sla, calendar: calendar, first_response_time: 60, update_time: 180, solution_time: 240) }
let(:calendar) { create(:calendar, :'24/7') }
@ -671,7 +671,7 @@ RSpec.describe Ticket, type: :model do
end
context 'with an SLA in the system' do
before { sla } # create sla
before { sla } # create sla
it 'is set based on SLAs #solution_time' do
expect(ticket.reload.close_escalation_at.to_i)
@ -679,7 +679,7 @@ RSpec.describe Ticket, type: :model do
end
context 'after first agents response' do
before { ticket } # create ticket
before { ticket } # create ticket
let(:article) { create(:ticket_article, ticket: ticket, sender_name: 'Agent') }
@ -878,7 +878,7 @@ RSpec.describe Ticket, type: :model do
context 'and subsequently destroyed' do
it 'deletes all related attachments' do
ticket # create ticket
ticket # create ticket
expect { ticket.destroy }
.to change(Store, :count).by(-2)
@ -888,7 +888,7 @@ RSpec.describe Ticket, type: :model do
end
context 'and a duplicate ticket is generated from the same email' do
before { ticket } # create ticket
before { ticket } # create ticket
let(:duplicate) { Channel::EmailParser.new.process({}, raw_email).first }
@ -901,7 +901,7 @@ RSpec.describe Ticket, type: :model do
context 'when only the duplicate ticket is destroyed' do
it 'deletes only the duplicate attachments' do
duplicate # create ticket
duplicate # create ticket
expect { duplicate.destroy }
.to change(Store, :count).by(-2)

View file

@ -37,8 +37,8 @@ RSpec.describe Trigger, type: :model do
describe 'Send-email triggers' do
before do
described_class.destroy_all # Default DB state includes three sample triggers
trigger # create subject trigger
described_class.destroy_all # Default DB state includes three sample triggers
trigger # create subject trigger
end
let(:perform) do
@ -396,7 +396,7 @@ RSpec.describe Trigger, type: :model do
context 'when new article is created directly' do
context 'with empty #preferences hash' do
let!(:article) { create(:ticket_article, ticket: ticket) }
let!(:article) { create(:ticket_article, ticket: ticket) }
it 'fires (without altering ticket state)' do
expect { Observer::Transaction.commit }

View file

@ -17,7 +17,7 @@ describe Controllers::KnowledgeBase::CategoriesControllerPolicy do
describe '#show?' do
let(:action_name) { :show }
let(:params) { { id: internal_answer.category.id } }
let(:params) { { id: internal_answer.category.id } }
context 'with knowledge_base.reader permissions' do
let(:user) { create(:agent) }

View file

@ -35,7 +35,7 @@ RSpec.describe 'Integration SMIME', type: :request do
it 'adds certificate by file' do
expect do
post endpoint, params: { file: Rack::Test::UploadedFile.new(certificate_path, 'text/plain', true) }
post endpoint, params: { file: Rack::Test::UploadedFile.new(certificate_path, 'text/plain', true) }
end.to change(SMIMECertificate, :count).by(1)
expect(response).to have_http_status(:ok)

View file

@ -488,19 +488,19 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
let(:article_communication) do
create(:ticket_article,
sender_name: 'Agent', type_name: 'email', ticket: ticket,
updated_by_id: agent.id, created_by_id: agent.id )
updated_by_id: agent.id, created_by_id: agent.id )
end
let(:article_note) do
create(:ticket_article,
sender_name: 'Agent', internal: true, type_name: 'note', ticket: ticket,
updated_by_id: agent.id, created_by_id: agent.id )
updated_by_id: agent.id, created_by_id: agent.id )
end
let(:article_note_customer) do
create(:ticket_article,
sender_name: 'Customer', internal: false, type_name: 'note', ticket: ticket,
updated_by_id: customer.id, created_by_id: customer.id )
updated_by_id: customer.id, created_by_id: customer.id )
end
let(:article_note_communication) do
@ -508,7 +508,7 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
create(:ticket_article,
sender_name: 'Agent', internal: true, type_name: 'note_communication', ticket: ticket,
updated_by_id: agent.id, created_by_id: agent.id )
updated_by_id: agent.id, created_by_id: agent.id )
end
def delete_article_via_rest(article)

View file

@ -2048,7 +2048,7 @@ RSpec.describe 'Ticket', type: :request do
expect(json_response['tickets']).to eq([ticket1.id, ticket2.id])
authenticated_as(admin)
get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: %w[created_at updated_at], order_by: %w[desc asc] }, as: :json
get "/api/v1/tickets/search?query=#{CGI.escape(title)}&limit=40", params: { sort_by: %w[created_at updated_at], order_by: %w[desc asc] }, as: :json
expect(response).to have_http_status(:ok)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['tickets']).to eq([ticket2.id, ticket1.id])

View file

@ -3,7 +3,7 @@ require 'rails_helper'
RSpec.describe 'Login Message', type: :system, authenticated_as: false do
context 'with maintenance_login_message' do
let(:message) { "badum tssss #{rand(99_999)}" }
let(:alt_message) { 'lorem ipsum' }
let(:alt_message) { 'lorem ipsum' }
before { Setting.set 'maintenance_login_message', message }

View file

@ -739,7 +739,7 @@ class AdminObjectManagerTest < TestCase
# open the previously created ticket and verify its attribute selection
click(
xpath: '//a/div[contains(text(),"select_attributes_delete_test")]',
xpath: '//a/div[contains(text(),"select_attributes_delete_test")]',
)
# confirm that all options and their display values are there and are in the correct order
select_element = @browser.find_elements(css: '.content.active select[name="select_attributes_delete_test"]')[0]

View file

@ -246,7 +246,7 @@ class AdminRoleTest < TestCase
)
click(
css: '.content.active a[href="#manage/users"]',
css: '.content.active a[href="#manage/users"]',
)
# an inactive role should not appear in the role filter tabs

View file

@ -129,7 +129,7 @@ class AgentNavigationAndTitleTest < TestCase
exists_not(css: '#navigation .tasks .js-item.is-active')
# click on admin
click(css: 'a[href = "#manage"]')
click(css: 'a[href = "#manage"]')
verify_title(value: 'Users')
exists_not(css: '#navigation .js-menu .is-active')
exists_not(css: '#navigation .tasks .js-item.is-active')

View file

@ -110,7 +110,7 @@ class AgentTicketEmailReplyKeepBodyTest < TestCase
title: 'Welcome to Zammad',
)
watch_for(
css: '.content.active .js-settingContainer .js-setting .dropdown-icon',
css: '.content.active .js-settingContainer .js-setting .dropdown-icon',
)
# enable email full quote in the ticket zoom config page
@ -186,7 +186,7 @@ class AgentTicketEmailReplyKeepBodyTest < TestCase
title: 'Welcome to Zammad',
)
watch_for(
css: '.content.active .js-settingContainer .js-setting .dropdown-icon',
css: '.content.active .js-settingContainer .js-setting .dropdown-icon',
)
# enable email full quote in the ticket zoom config page

View file

@ -45,12 +45,12 @@ class AgentTicketOverviewPendingTil < TestCase
}
)
overview_open(
name: name,
name: name,
)
# sort by Pending Til
click(
css: '.content.active table.table th.js-tableHead[data-column-key="pending_time"]',
css: '.content.active table.table th.js-tableHead[data-column-key="pending_time"]',
)
# check if the first and second rows both correctly contain 'pending close'

View file

@ -25,7 +25,7 @@ class ReportingTest < TestCase
)
click(
css: 'a[href="#manage"]',
css: 'a[href="#manage"]',
)
click(
css: '.content.active a[href="#manage/report_profiles"]',

View file

@ -8,17 +8,17 @@ class DbAutoIncrementTest < ActiveSupport::TestCase
Setting.set('system_init_done', false)
Ticket::StateType.create_if_not_exists( id: 200, name: 'unit test 1', updated_by_id: 1, created_by_id: 1 )
Ticket::StateType.create_if_not_exists( id: 200, name: 'unit test 1', updated_by_id: 1, created_by_id: 1 )
state_type = Ticket::StateType.where( name: 'unit test 1' ).first
assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
assert_equal( 'unit test 1', state_type.name )
Ticket::StateType.create_if_not_exists( id: 200, name: 'unit test 1 _ should not be created', updated_by_id: 1, created_by_id: 1 )
Ticket::StateType.create_if_not_exists( id: 200, name: 'unit test 1 _ should not be created', updated_by_id: 1, created_by_id: 1 )
state_type = Ticket::StateType.where( id: 200 ).first
assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
assert_equal( 'unit test 1', state_type.name )
Ticket::StateType.create_or_update( id: 200, name: 'unit test 1 _ should be updated', updated_by_id: 1, created_by_id: 1 )
Ticket::StateType.create_or_update( id: 200, name: 'unit test 1 _ should be updated', updated_by_id: 1, created_by_id: 1 )
state_type = Ticket::StateType.where( name: 'unit test 1 _ should be updated' ).first
assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
assert_equal( 'unit test 1 _ should be updated', state_type.name )
@ -27,17 +27,17 @@ class DbAutoIncrementTest < ActiveSupport::TestCase
assert_equal( Ticket::StateType.to_s, state_type.class.to_s )
assert_equal( 'unit test 1 _ should be updated', state_type.name )
Ticket::State.create_if_not_exists( id: 210, name: 'unit test 1', state_type_id: Ticket::StateType.where(name: 'unit test 1 _ should be updated').first.id, updated_by_id: 1, created_by_id: 1 )
Ticket::State.create_if_not_exists( id: 210, name: 'unit test 1', state_type_id: Ticket::StateType.where(name: 'unit test 1 _ should be updated').first.id, updated_by_id: 1, created_by_id: 1 )
state = Ticket::State.where( name: 'unit test 1' ).first
assert_equal( Ticket::State.to_s, state.class.to_s )
assert_equal( 'unit test 1', state.name )
Ticket::State.create_if_not_exists( id: 210, name: 'unit test 1 _ should not be created', state_type_id: Ticket::StateType.where(name: 'unit test 1 _ should be updated').first.id, updated_by_id: 1, created_by_id: 1 )
Ticket::State.create_if_not_exists( id: 210, name: 'unit test 1 _ should not be created', state_type_id: Ticket::StateType.where(name: 'unit test 1 _ should be updated').first.id, updated_by_id: 1, created_by_id: 1 )
state = Ticket::State.where( id: 210 ).first
assert_equal( Ticket::State.to_s, state.class.to_s )
assert_equal( 'unit test 1', state.name )
Ticket::State.create_or_update( id: 210, name: 'unit test 1 _ should be updated', state_type_id: Ticket::StateType.where(name: 'unit test 1 _ should be updated').first.id, updated_by_id: 1, created_by_id: 1 )
Ticket::State.create_or_update( id: 210, name: 'unit test 1 _ should be updated', state_type_id: Ticket::StateType.where(name: 'unit test 1 _ should be updated').first.id, updated_by_id: 1, created_by_id: 1 )
state = Ticket::State.where( name: 'unit test 1 _ should be updated' ).first
assert_equal( Ticket::State.to_s, state.class.to_s )
assert_equal( 'unit test 1 _ should be updated', state.name )

View file

@ -75,7 +75,7 @@ class StoreTest < ActiveSupport::TestCase
# sha check
sha_new = Digest::SHA256.hexdigest(attachments[0].content)
assert_equal(sha, sha_new, "check file #{file[:filename]}")
assert_equal(sha, sha_new, "check file #{file[:filename]}")
# filename check
assert_equal(file[:filename], attachments[0].filename)
@ -101,7 +101,7 @@ class StoreTest < ActiveSupport::TestCase
# sha check
sha_new = Digest::SHA256.hexdigest(attachments[0].content)
assert_equal(sha, sha_new, "check file #{file[:filename]}")
assert_equal(sha, sha_new, "check file #{file[:filename]}")
# filename check
assert_equal(file[:filename], attachments[0].filename)
@ -128,7 +128,7 @@ class StoreTest < ActiveSupport::TestCase
# sha check
sha_new = Digest::SHA256.hexdigest(attachments[0].content)
assert_equal(sha, sha_new, "check file #{file[:filename]}")
assert_equal(sha, sha_new, "check file #{file[:filename]}")
# filename check
assert_equal(file[:filename], attachments[0].filename)