diff --git a/Gemfile b/Gemfile
index b97775d7c..11e88dd40 100644
--- a/Gemfile
+++ b/Gemfile
@@ -185,7 +185,7 @@ group :development, :test do
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rails'
- gem 'rubocop-rspec'
+ gem 'rubocop-rspec', '2.0.0.pre' # see: https://github.com/rubocop-hq/rubocop-rspec/issues/1051
# changelog generation
gem 'github_changelog_generator'
diff --git a/Gemfile.lock b/Gemfile.lock
index 009a13ae3..ea8e8f632 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -452,16 +452,16 @@ GEM
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
rszr (0.5.2)
- rubocop (0.93.1)
+ rubocop (1.2.0)
parallel (~> 1.10)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
rexml
- rubocop-ast (>= 0.6.0)
+ rubocop-ast (>= 1.0.1)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
- rubocop-ast (1.0.0)
+ rubocop-ast (1.1.1)
parser (>= 2.7.1.5)
rubocop-performance (1.8.1)
rubocop (>= 0.87.0)
@@ -470,9 +470,8 @@ GEM
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.87.0)
- rubocop-rspec (1.44.1)
- rubocop (~> 0.87)
- rubocop-ast (>= 0.7.1)
+ rubocop-rspec (2.0.0.pre)
+ rubocop (~> 1.0)
ruby-progressbar (1.10.1)
ruby-saml (1.10.2)
nokogiri (>= 1.5.10)
@@ -656,7 +655,7 @@ DEPENDENCIES
rubocop
rubocop-performance
rubocop-rails
- rubocop-rspec
+ rubocop-rspec (= 2.0.0.pre)
rubyntlm!
sassc-rails
selenium-webdriver
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 7b0fc5054..a467b0502 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -16,10 +16,10 @@ class SearchController < ApplicationController
# convert objects string into array of class names
# e.g. user-ticket-another_object = %w( User Ticket AnotherObject )
- objects = if !params[:objects]
- Setting.get('models_searchable')
- else
+ objects = if params[:objects]
params[:objects].split('-').map(&:camelize)
+ else
+ Setting.get('models_searchable')
end
# get priorities of result
diff --git a/app/models/channel/driver/imap.rb b/app/models/channel/driver/imap.rb
index 6abe3d23e..bf089846d 100644
--- a/app/models/channel/driver/imap.rb
+++ b/app/models/channel/driver/imap.rb
@@ -329,10 +329,10 @@ example
begin
timeout(FETCH_MSG_TIMEOUT) do
- if !keep_on_server
- @imap.store(message_id, '+FLAGS', [:Deleted])
- else
+ if keep_on_server
@imap.store(message_id, '+FLAGS', [:Seen])
+ else
+ @imap.store(message_id, '+FLAGS', [:Deleted])
end
end
rescue Timeout::Error => e
diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb
index 9721d29dd..acfc93623 100644
--- a/app/models/channel/email_parser.rb
+++ b/app/models/channel/email_parser.rb
@@ -943,12 +943,11 @@ module Mail
# https://github.com/zammad/zammad/issues/348
class Body
def decoded
- if !Encodings.defined?(encoding)
- #raise UnknownEncodingType, "Don't know how to decode #{encoding}, please call #encoded and decode it yourself."
+ if Encodings.defined?(encoding)
+ Encodings.get_encoding(encoding).decode(raw_source)
+ else
Rails.logger.info "UnknownEncodingType: Don't know how to decode #{encoding}!"
raw_source
- else
- Encodings.get_encoding(encoding).decode(raw_source)
end
end
end
diff --git a/app/models/cti/caller_id.rb b/app/models/cti/caller_id.rb
index c11dac400..e865b08b8 100644
--- a/app/models/cti/caller_id.rb
+++ b/app/models/cti/caller_id.rb
@@ -226,7 +226,7 @@ returns
# see specs for example
return [] if !text.is_a?(String)
- text.scan(/([\d|\s|\-|(|)]{6,26})/).map do |match|
+ text.scan(/([\d\s\-(|)]{6,26})/).map do |match|
normalize_number(match[0])
end
end
diff --git a/app/models/observer/transaction.rb b/app/models/observer/transaction.rb
index e6b23ea04..e5d2addc1 100644
--- a/app/models/observer/transaction.rb
+++ b/app/models/observer/transaction.rb
@@ -155,16 +155,16 @@ class Observer::Transaction < ActiveRecord::Observer
# merge changes
if event[:changes]
- if !store[:changes]
- store[:changes] = event[:changes]
- else
+ if store[:changes]
event[:changes].each do |key, value|
- if !store[:changes][key]
- store[:changes][key] = value
- else
+ if store[:changes][key]
store[:changes][key][1] = value[1]
+ else
+ store[:changes][key] = value
end
end
+ else
+ store[:changes] = event[:changes]
end
end
diff --git a/app/models/smime_certificate.rb b/app/models/smime_certificate.rb
index 99b1acee6..60e99e697 100644
--- a/app/models/smime_certificate.rb
+++ b/app/models/smime_certificate.rb
@@ -73,23 +73,23 @@ class SMIMECertificate < ApplicationModel
@email_addresses ||= begin
subject_alt_name = parsed.extensions.detect { |extension| extension.oid == 'subjectAltName' }
if subject_alt_name.blank?
- warning = <<~TEXT.squish
+ Rails.logger.warn <<~TEXT.squish
SMIMECertificate with ID #{id} has no subjectAltName
extension and therefore no email addresses assigned.
This makes it useless in terms of S/MIME. Please check.
TEXT
- Rails.logger.warn warning
- return []
- end
- # ["IP Address:192.168.7.23", "IP Address:192.168.7.42", "email:jd@example.com", "email:John.Doe@example.com", "dirName:dir_sect"]
- entries = subject_alt_name.value.split(/,\s?/)
- # ["email:jd@example.com", "email:John.Doe@example.com"]
- email_address_entries = entries.select { |entry| entry.start_with?('email') }
- # ["jd@example.com", "John.Doe@example.com"]
- email_address_entries.map! { |entry| entry.split(':')[1] }
- # ["jd@example.com", "john.doe@example.com"]
- email_address_entries.map!(&:downcase)
+ []
+ else
+ # ["IP Address:192.168.7.23", "IP Address:192.168.7.42", "email:jd@example.com", "email:John.Doe@example.com", "dirName:dir_sect"]
+ entries = subject_alt_name.value.split(/,\s?/)
+ # ["email:jd@example.com", "email:John.Doe@example.com"]
+ email_address_entries = entries.select { |entry| entry.start_with?('email') }
+ # ["jd@example.com", "John.Doe@example.com"]
+ email_address_entries.map! { |entry| entry.split(':')[1] }
+ # ["jd@example.com", "john.doe@example.com"]
+ email_address_entries.map!(&:downcase)
+ end
end
end
diff --git a/app/models/translation.rb b/app/models/translation.rb
index f82594425..53260d211 100644
--- a/app/models/translation.rb
+++ b/app/models/translation.rb
@@ -470,13 +470,13 @@ Get source file at https://i18n.zammad.com/api/v1/translations_empty_translation
private_class_method def self.locals_to_sync(dedicated_locale = nil)
locales_list = []
- if !dedicated_locale
+ if dedicated_locale
+ locales_list = [dedicated_locale]
+ else
locales = Locale.to_sync
locales.each do |locale|
locales_list.push locale.locale
end
- else
- locales_list = [dedicated_locale]
end
locales_list
end
diff --git a/db/migrate/20181030000001_setting_add_placetel1.rb b/db/migrate/20181030000001_setting_add_placetel1.rb
index 592538028..b76f1d7e1 100644
--- a/db/migrate/20181030000001_setting_add_placetel1.rb
+++ b/db/migrate/20181030000001_setting_add_placetel1.rb
@@ -33,7 +33,10 @@ class SettingAddPlacetel1 < ActiveRecord::Migration[5.1]
frontend: true
)
placetel_config = Setting.find_by(name: 'placetel_config')
- if !placetel_config
+ if placetel_config
+ placetel_config.preferences[:cache] = ['placetelGetVoipUsers']
+ placetel_config.save!
+ else
Setting.create!(
title: 'Placetel config',
name: 'placetel_config',
@@ -48,9 +51,6 @@ class SettingAddPlacetel1 < ActiveRecord::Migration[5.1]
},
frontend: false,
)
- else
- placetel_config.preferences[:cache] = ['placetelGetVoipUsers']
- placetel_config.save!
end
Setting.create_if_not_exists(
title: 'PLACETEL Token',
diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb
index 79974cf89..b66bab2ba 100644
--- a/lib/core_ext/string.rb
+++ b/lib/core_ext/string.rb
@@ -124,16 +124,7 @@ class String
# find and replace it with [x]
link_list = ''
counter = 0
- if !string_only
- if string.scan(//ix) do
- link = $2
- counter = counter + 1
- link_list += "[#{counter}] #{link}\n"
- "[#{counter}] "
- end
- end
- else
+ if string_only
string.gsub!(%r{]*)>(.+?)<[[:space:]]*/a[[:space:]]*>}mxi) do |_placeholder|
link = $3
text = $6
@@ -168,6 +159,13 @@ class String
"#{link} (######LINKRAW:#{text}######)"
end
end
+ elsif string.scan(//ix) do
+ link = $2
+ counter = counter + 1
+ link_list += "[#{counter}] #{link}\n"
+ "[#{counter}] "
+ end
end
# remove style tags with content
@@ -195,7 +193,7 @@ class String
# blockquote handling
string.gsub!(%r{]*)>(.+?)
}m) do
- "\n#{$2.html2text(true).gsub(/^(.*)$/, '> \1')}\n" # rubocop:disable Lint/OutOfRangeRegexpRef
+ "\n#{$2.html2text(true).gsub(/^(.*)$/, '> \1')}\n"
end
# pre/code handling 2/2
diff --git a/lib/facebook.rb b/lib/facebook.rb
index aa09fe01e..8fb2dbab4 100644
--- a/lib/facebook.rb
+++ b/lib/facebook.rb
@@ -241,10 +241,10 @@ result
to = nil
if post['to'] && post['to']['data']
post['to']['data'].each do |to_entry|
- if !to
- to = ''
- else
+ if to
to += ', '
+ else
+ to = ''
end
to += to_entry['name']
end
diff --git a/lib/fill_db.rb b/lib/fill_db.rb
index 89aeffa1e..bead71715 100644
--- a/lib/fill_db.rb
+++ b/lib/fill_db.rb
@@ -45,21 +45,24 @@ or if you only want to create 100 tickets
# organizations
organization_pool = []
- if !organizations.zero?
+ if organizations.zero?
+ organization_pool = Organization.where(active: true)
+ puts " take #{organization_pool.length} organizations"
+ else
(1..organizations).each do
ActiveRecord::Base.transaction do
organization = Organization.create!(name: "FillOrganization::#{rand(999_999)}", active: true)
organization_pool.push organization
end
end
- else
- organization_pool = Organization.where(active: true)
- puts " take #{organization_pool.length} organizations"
end
# create agents
agent_pool = []
- if !agents.zero?
+ if agents.zero?
+ agent_pool = Role.where(name: 'Agent').first.users.where(active: true)
+ puts " take #{agent_pool.length} agents"
+ else
roles = Role.where(name: [ 'Agent'])
groups_all = Group.all
@@ -80,14 +83,14 @@ or if you only want to create 100 tickets
agent_pool.push user
end
end
- else
- agent_pool = Role.where(name: 'Agent').first.users.where(active: true)
- puts " take #{agent_pool.length} agents"
end
# create customer
customer_pool = []
- if !customers.zero?
+ if customers.zero?
+ customer_pool = Role.where(name: 'Customer').first.users.where(active: true)
+ puts " take #{customer_pool.length} customers"
+ else
roles = Role.where(name: [ 'Customer'])
groups_all = Group.all
@@ -112,15 +115,15 @@ or if you only want to create 100 tickets
customer_pool.push user
end
end
- else
- customer_pool = Role.where(name: 'Customer').first.users.where(active: true)
- puts " take #{customer_pool.length} customers"
end
# create groups
group_pool = []
- if !groups.zero?
+ if groups.zero?
+ group_pool = Group.where(active: true)
+ puts " take #{group_pool.length} groups"
+ else
(1..groups).each do
ActiveRecord::Base.transaction do
group = Group.create!(name: "FillGroup::#{rand(999_999)}", active: true)
@@ -134,9 +137,6 @@ or if you only want to create 100 tickets
sleep nice
end
end
- else
- group_pool = Group.where(active: true)
- puts " take #{group_pool.length} groups"
end
# create overviews
diff --git a/lib/html_sanitizer.rb b/lib/html_sanitizer.rb
index 16189d069..3d41b7535 100644
--- a/lib/html_sanitizer.rb
+++ b/lib/html_sanitizer.rb
@@ -113,10 +113,10 @@ satinize html string based on whiltelist
end
class_new += local_class
end
- if class_new != ''
- node['class'] = class_new
- else
+ if class_new == ''
node.delete('class')
+ else
+ node['class'] = class_new
end
end
diff --git a/lib/notification_factory/renderer.rb b/lib/notification_factory/renderer.rb
index 292a33a36..893696402 100644
--- a/lib/notification_factory/renderer.rb
+++ b/lib/notification_factory/renderer.rb
@@ -139,11 +139,7 @@ examples how to use
break
end
end
- placeholder = if !value
- object_refs
- else
- value
- end
+ placeholder = value || object_refs
escaping(convert_to_timezone(placeholder), escape)
end
diff --git a/lib/notification_factory/template.rb b/lib/notification_factory/template.rb
index f322dd7d3..945eba14d 100644
--- a/lib/notification_factory/template.rb
+++ b/lib/notification_factory/template.rb
@@ -20,7 +20,7 @@ examples how to use
@template.gsub(/\#{\s*(.*?)\s*}/m) do
# some browsers start adding HTML tags
# fixes https://github.com/zammad/zammad/issues/385
- input_template = $1.gsub(/\A<.+?>\s*|\s*<.+?>\z/, '') # rubocop:disable Lint/OutOfRangeRegexpRef
+ input_template = $1.gsub(/\A<.+?>\s*|\s*<.+?>\z/, '')
case input_template
when /\At\('(.+?)'\)\z/m
diff --git a/lib/sessions/backend/ticket_overview_list.rb b/lib/sessions/backend/ticket_overview_list.rb
index 2a96b7795..1c6de15fd 100644
--- a/lib/sessions/backend/ticket_overview_list.rb
+++ b/lib/sessions/backend/ticket_overview_list.rb
@@ -160,13 +160,7 @@ class Sessions::Backend::TicketOverviewList < Sessions::Backend::Base
data[:assets] = assets.to_h
- if !@client
- result = {
- event: 'ticket_overview_list',
- data: data,
- }
- results.push result
- else
+ if @client
@client.log "push overview_list #{overview.link} for user #{@user.id}"
# send update to browser
@@ -174,6 +168,12 @@ class Sessions::Backend::TicketOverviewList < Sessions::Backend::Base
event: 'ticket_overview_list',
data: data,
)
+ else
+ result = {
+ event: 'ticket_overview_list',
+ data: data,
+ }
+ results.push result
end
assets.flush
diff --git a/lib/sessions/event/base.rb b/lib/sessions/event/base.rb
index 4d8fed891..c2fb172a5 100644
--- a/lib/sessions/event/base.rb
+++ b/lib/sessions/event/base.rb
@@ -26,10 +26,10 @@ class Sessions::Event::Base
end
def websocket_send(recipient_client_id, data)
- msg = if data.class != Array
- "[#{data.to_json}]"
- else
+ msg = if data.instance_of?(Array)
data.to_json
+ else
+ "[#{data.to_json}]"
end
if @clients[recipient_client_id]
log 'debug', "ws send #{msg}", recipient_client_id
diff --git a/lib/twitter_sync.rb b/lib/twitter_sync.rb
index 39dd0d919..4557dcd81 100644
--- a/lib/twitter_sync.rb
+++ b/lib/twitter_sync.rb
@@ -253,10 +253,10 @@ class TwitterSync
if item['entities']
item['entities']['user_mentions']&.each do |local_user|
- if !to
- to = ''
- else
+ if to
to += ', '
+ else
+ to = ''
end
to += "@#{local_user['screen_name']}"
mention_ids.push local_user['id']
@@ -380,10 +380,10 @@ class TwitterSync
from = "@#{tweet.user.screen_name}"
mention_ids = []
tweet.user_mentions&.each do |local_user|
- if !to
- to = ''
- else
+ if to
to += ', '
+ else
+ to = ''
end
to += "@#{local_user.screen_name}"
mention_ids.push local_user.id
diff --git a/lib/websocket_server.rb b/lib/websocket_server.rb
index 6a18d36b2..c04cdf7ea 100644
--- a/lib/websocket_server.rb
+++ b/lib/websocket_server.rb
@@ -115,10 +115,10 @@ class WebsocketServer
end
def self.websocket_send(client_id, data)
- msg = if data.class != Array
- "[#{data.to_json}]"
- else
+ msg = if data.instance_of?(Array)
data.to_json
+ else
+ "[#{data.to_json}]"
end
log 'debug', "send #{msg}", client_id
if !@clients[client_id]
diff --git a/spec/factories/channel.rb b/spec/factories/channel.rb
index 064f0608d..36e670a37 100644
--- a/spec/factories/channel.rb
+++ b/spec/factories/channel.rb
@@ -7,8 +7,8 @@ FactoryBot.define do
area { 'Email::Dummy' }
group { ::Group.find(1) }
active { true }
- options {}
- preferences {}
+ options { nil }
+ preferences { nil }
updated_by_id { 1 }
created_by_id { 1 }
diff --git a/spec/factories/import_job.rb b/spec/factories/import_job.rb
index 6cb1bee76..d62cb59ec 100644
--- a/spec/factories/import_job.rb
+++ b/spec/factories/import_job.rb
@@ -1,7 +1,7 @@
FactoryBot.define do
factory :import_job do
name { 'Import::Test' }
- payload {}
+ payload { nil }
dry_run { false }
end
end
diff --git a/spec/factories/notification_factory/renderer.rb b/spec/factories/notification_factory/renderer.rb
index de4250681..87813b3e6 100644
--- a/spec/factories/notification_factory/renderer.rb
+++ b/spec/factories/notification_factory/renderer.rb
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :notification_factory_renderer, class: NotificationFactory::Renderer do
- objects {}
+ objects { nil }
locale { 'en-en' }
template { '' }
escape { true }
diff --git a/spec/factories/taskbar.rb b/spec/factories/taskbar.rb
index 69fedf67f..36ebbb5ff 100644
--- a/spec/factories/taskbar.rb
+++ b/spec/factories/taskbar.rb
@@ -4,7 +4,7 @@ FactoryBot.define do
key { 'Ticket-1234' }
add_attribute(:callback) { 'TicketZoom' }
params { {} }
- state {}
+ state { nil }
prio { 1 }
notify { false }
user_id { 1 }
diff --git a/spec/lib/application_handle_info_spec.rb b/spec/lib/application_handle_info_spec.rb
index 6f95328f5..dcb378c10 100644
--- a/spec/lib/application_handle_info_spec.rb
+++ b/spec/lib/application_handle_info_spec.rb
@@ -31,7 +31,7 @@ RSpec.describe ApplicationHandleInfo do
end
it 'resets ApplicationHandleInfo to its original value' do
- described_class.use('bar') {}
+ described_class.use('bar') { nil }
expect(described_class.current).to eq('foo')
end
diff --git a/spec/requests/integration/gmail_spec.rb b/spec/requests/integration/gmail_spec.rb
index ddf61acf3..c41ced924 100644
--- a/spec/requests/integration/gmail_spec.rb
+++ b/spec/requests/integration/gmail_spec.rb
@@ -72,7 +72,7 @@ RSpec.describe 'Gmail XOAUTH2' do # rubocop:disable RSpec/DescribeClass
end
it "doesn't remove email address assignments" do
- expect { Channel.where(area: 'Google::Account').find_each {} }.not_to change { email_address.reload.channel_id }
+ expect { Channel.where(area: 'Google::Account').find_each { nil } }.not_to change { email_address.reload.channel_id }
end
end
end
diff --git a/spec/requests/integration/microsoft365_spec.rb b/spec/requests/integration/microsoft365_spec.rb
index fc1bc8877..3e11415ec 100644
--- a/spec/requests/integration/microsoft365_spec.rb
+++ b/spec/requests/integration/microsoft365_spec.rb
@@ -71,7 +71,7 @@ RSpec.describe 'Microsoft365 XOAUTH2' do # rubocop:disable RSpec/DescribeClass
end
it "doesn't remove email address assignments" do
- expect { Channel.where(area: 'Microsoft365::Account').find_each {} }.not_to change { email_address.reload.channel_id }
+ expect { Channel.where(area: 'Microsoft365::Account').find_each { nil } }.not_to change { email_address.reload.channel_id }
end
end
end
diff --git a/spec/support/custom_matchers/system/knowledge_base_public/have_breadcrumb.rb b/spec/support/custom_matchers/system/knowledge_base_public/have_breadcrumb.rb
index dec557170..ee6495a7e 100644
--- a/spec/support/custom_matchers/system/knowledge_base_public/have_breadcrumb.rb
+++ b/spec/support/custom_matchers/system/knowledge_base_public/have_breadcrumb.rb
@@ -6,7 +6,7 @@ module KnowledgeBasePublicMatchers
match { breadcrumb_found? && of_specified_length? }
chain(:with, :length)
- chain(:items) {}
+ chain(:items) { nil }
description do
if @length.present?
diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb
index 5fffed85e..670ba476b 100644
--- a/test/browser_test_helper.rb
+++ b/test/browser_test_helper.rb
@@ -265,13 +265,13 @@ class TestCase < ActiveSupport::TestCase
sleep 4
login_failed = false
- if !instance.find_elements(css: '.user-menu .user a')[0]
- login_failed = true
- else
+ if instance.find_elements(css: '.user-menu .user a')[0]
login = instance.find_elements(css: '.user-menu .user a')[0].attribute('title')
if login != params[:username]
login_failed = true
end
+ else
+ login_failed = true
end
if login_failed
if params[:success] == false
@@ -784,14 +784,14 @@ class TestCase < ActiveSupport::TestCase
end
begin
- if !params[:slow]
- element.send_keys(params[:value])
- else
+ if params[:slow]
element.send_keys('')
keys = params[:value].to_s.split('')
keys.each do |key|
instance.action.send_keys(key).perform
end
+ else
+ element.send_keys(params[:value])
end
rescue
sleep 0.5
@@ -801,14 +801,14 @@ class TestCase < ActiveSupport::TestCase
element = instance.find_elements(css: params[:css])[0]
raise "No such element '#{params[:css]}'" if !element
- if !params[:slow]
- element.send_keys(params[:value])
- else
+ if params[:slow]
element.send_keys('')
keys = params[:value].to_s.split('')
keys.each do |key|
instance.action.send_keys(key).perform
end
+ else
+ element.send_keys(params[:value])
end
end