Updated to latest rubocop version.

This commit is contained in:
Thorsten Eckel 2018-04-12 16:57:37 +02:00
parent 777fe192eb
commit fbeccbc85c
74 changed files with 350 additions and 243 deletions

View file

@ -1,7 +1,10 @@
# Default enabled cops # Default enabled cops
# https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml # https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
inherit_from: .rubocop_todo.yml
AllCops: AllCops:
DisplayCopNames: true
Exclude: Exclude:
- 'bin/rails' - 'bin/rails'
- 'bin/rake' - 'bin/rake'
@ -35,9 +38,13 @@ Style/IfUnlessModifier:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier'
Enabled: false Enabled: false
Style/TrailingCommaInLiteral: Style/TrailingCommaInArrayLiteral:
Description: 'Checks for trailing comma in array and hash literals.' Description: 'Checks for trailing comma in array literals.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' StyleGuide: '#no-trailing-array-commas'
Enabled: false
Style/TrailingCommaInHashLiteral:
Description: 'Checks for trailing comma in hash literals.'
Enabled: false Enabled: false
Style/TrailingCommaInArguments: Style/TrailingCommaInArguments:
@ -67,9 +74,12 @@ Style/MethodCallWithoutArgsParentheses:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
Enabled: false Enabled: false
Layout/SpaceInsideBrackets: Layout/SpaceInsideReferenceBrackets:
Description: 'No spaces after [ or before ].' Description: 'Checks the spacing inside referential brackets.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces' Enabled: false
Layout/SpaceInsideArrayLiteralBrackets:
Description: 'Checks the spacing inside array literal brackets.'
Enabled: false Enabled: false
Style/DefWithParentheses: Style/DefWithParentheses:
@ -167,68 +177,31 @@ Naming/VariableNumber:
Description: 'Use the configured style when numbering variables.' Description: 'Use the configured style when numbering variables.'
Enabled: false Enabled: false
# 2.0 Naming/UncommunicativeMethodParamName:
Metrics/PerceivedComplexity:
Description: >- Description: >-
A complexity metric geared towards measuring complexity for a Checks for method parameter names that contain capital letters,
human reader. end in numbers, or do not meet a minimal length.
Enabled: false Enabled: true
AllowedNames: e, id, _, ip
Metrics/AbcSize: Lint/BooleanSymbol:
Description: >- Description: 'Check for `:true` and `:false` symbols.'
A calculated magnitude based on number of assignments, Enabled: true
branches, and conditions. Exclude:
Enabled: false - "db/seeds/object_manager_attributes.rb"
- "test/integration/object_manager_attributes_controller_test.rb"
- "test/integration/object_manager_test.rb"
Metrics/CyclomaticComplexity: Lint/InterpolationCheck:
Description: >- Description: 'Raise warning for interpolation in single q strs'
A complexity metric that is strongly correlated to the number Enabled: true
of test cases needed to validate a method. Exclude:
Enabled: false - "test/unit/email_process_auto_response_test.rb"
- "test/unit/email_process_bounce_delivery_permanent_failed_test.rb"
Metrics/BlockNesting: - "test/unit/email_process_bounce_follow_test.rb"
Description: 'Avoid excessive block nesting' - "test/unit/notification_factory_renderer_test.rb"
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count' - "test/unit/notification_factory_template_test.rb"
Enabled: false - "test/unit/ticket_trigger_test.rb"
Metrics/ModuleLength:
Description: 'Avoid modules longer than 100 lines of code.'
Enabled: false
Metrics/BlockLength:
Enabled: false
Lint/RescueWithoutErrorClass:
Enabled: false
Rails/ApplicationRecord:
Enabled: false
# TODO
Rails/HasManyOrHasOneDependent:
Enabled: false
Style/DateTime:
Enabled: false
Style/Documentation:
Description: 'Document classes and non-namespace modules.'
Enabled: false
Lint/UselessAssignment:
Enabled: false
Layout/ExtraSpacing:
Description: 'Do not use unnecessary spacing.'
Enabled: false
# Broken!!!! Generates broken code since "String".downcase == "strinG".downcase is not equals "String".casecmp("strinG") but "String".casecmp("strinG") == 0 !!!
Performance/Casecmp:
Description: 'Use `casecmp` rather than `downcase ==`.'
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringcasecmp-vs-stringdowncase---code'
Enabled: false
# RSpec tests # RSpec tests
Style/NumericPredicate: Style/NumericPredicate:

80
.rubocop_todo.yml Normal file
View file

@ -0,0 +1,80 @@
# 10.0
Metrics/PerceivedComplexity:
Description: >-
A complexity metric geared towards measuring complexity for a
human reader.
Enabled: false
Metrics/AbcSize:
Description: >-
A calculated magnitude based on number of assignments,
branches, and conditions.
Enabled: false
Metrics/CyclomaticComplexity:
Description: >-
A complexity metric that is strongly correlated to the number
of test cases needed to validate a method.
Enabled: false
Metrics/BlockNesting:
Description: 'Avoid excessive block nesting'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count'
Enabled: false
Metrics/ModuleLength:
Description: 'Avoid modules longer than 100 lines of code.'
Enabled: false
Metrics/BlockLength:
Enabled: false
Style/RescueStandardError:
Description: 'Avoid rescuing without specifying an error class.'
Enabled: false
# TODO
Rails/ApplicationRecord:
Description: 'Check that models subclass ApplicationRecord.'
Enabled: false
Rails/CreateTableWithTimestamps:
Description: >-
Checks the migration for which timestamps are not included
when creating a new table.
Enabled: false
Rails/HasManyOrHasOneDependent:
Description: 'Define the dependent option to the has_many and has_one associations.'
StyleGuide: 'https://github.com/bbatsov/rails-style-guide#has_many-has_one-dependent-option'
Enabled: false
Style/DateTime:
Description: 'Use Date or Time over DateTime.'
StyleGuide: '#date--time'
Enabled: false
Style/Documentation:
Description: 'Document classes and non-namespace modules.'
Enabled: false
Lint/UselessAssignment:
Enabled: false
Layout/ExtraSpacing:
Description: 'Do not use unnecessary spacing.'
Enabled: false
# Broken!!!! Generates broken code since "String".downcase == "strinG".downcase is not equals "String".casecmp("strinG") but "String".casecmp("strinG") == 0 !!!
Performance/Casecmp:
Description: 'Use `casecmp` rather than `downcase ==`.'
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringcasecmp-vs-stringdowncase---code'
Enabled: false
# Can be removed after introduction of Sequencer for OTRS migration
Lint/MissingCopEnableDirective:
Enabled: true
Exclude:
- "lib/import/**/*"

View file

@ -68,7 +68,7 @@ GEM
argon2 (1.1.4) argon2 (1.1.4)
ffi (~> 1.9) ffi (~> 1.9)
ffi-compiler (~> 0.1) ffi-compiler (~> 0.1)
ast (2.3.0) ast (2.4.0)
autoprefixer-rails (7.1.6) autoprefixer-rails (7.1.6)
execjs execjs
biz (1.7.0) biz (1.7.0)
@ -284,9 +284,9 @@ GEM
omniauth-weibo-oauth2 (0.4.5) omniauth-weibo-oauth2 (0.4.5)
omniauth (~> 1.5) omniauth (~> 1.5)
omniauth-oauth2 (>= 1.4.0) omniauth-oauth2 (>= 1.4.0)
parallel (1.12.0) parallel (1.12.1)
parser (2.4.0.2) parser (2.5.0.5)
ast (~> 2.3) ast (~> 2.4.0)
pg (0.21.0) pg (0.21.0)
pluginator (1.5.0) pluginator (1.5.0)
power_assert (1.1.1) power_assert (1.1.1)
@ -328,8 +328,7 @@ GEM
method_source method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rainbow (2.2.2) rainbow (3.0.0)
rake
raindrops (0.19.0) raindrops (0.19.0)
rake (12.3.1) rake (12.3.1)
rb-fsevent (0.10.2) rb-fsevent (0.10.2)
@ -358,11 +357,11 @@ GEM
rspec-mocks (~> 3.7.0) rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0) rspec-support (~> 3.7.0)
rspec-support (3.7.0) rspec-support (3.7.0)
rubocop (0.51.0) rubocop (0.54.0)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0) parser (>= 2.5)
powerpack (~> 0.1) powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0) rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1) unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0) ruby-progressbar (1.9.0)

View file

@ -2,6 +2,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake, # Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__) require File.expand_path('config/application', __dir__)
Zammad::Application.load_tasks Zammad::Application.load_tasks

View file

@ -26,7 +26,6 @@ class ExternalCredentialsController < ApplicationController
def app_verify def app_verify
attributes = ExternalCredential.app_verify(params) attributes = ExternalCredential.app_verify(params)
render json: { attributes: attributes }, status: :ok render json: { attributes: attributes }, status: :ok
return
rescue => e rescue => e
render json: { error: e.message }, status: :ok render json: { error: e.message }, status: :ok
end end

View file

@ -5,8 +5,16 @@ class ActivityStream < ApplicationModel
include ActivityStream::Assets include ActivityStream::Assets
self.table_name = 'activity_streams' self.table_name = 'activity_streams'
# rubocop:disable Rails/InverseOf
belongs_to :object, class_name: 'ObjectLookup', foreign_key: 'activity_stream_object_id' belongs_to :object, class_name: 'ObjectLookup', foreign_key: 'activity_stream_object_id'
belongs_to :type, class_name: 'TypeLookup', foreign_key: 'activity_stream_type_id' belongs_to :type, class_name: 'TypeLookup', foreign_key: 'activity_stream_type_id'
# rubocop:enable Rails/InverseOf
# the noop is needed since Layout/EmptyLines detects
# the block commend below wrongly as the measurement of
# the wanted indentation of the rubocop re-enabling above
def noop; end
=begin =begin

View file

@ -11,9 +11,9 @@ module ApplicationModel::HasCache
after_destroy :cache_delete after_destroy :cache_delete
end end
def cache_update(o) def cache_update(other)
cache_delete if respond_to?('cache_delete') cache_delete if respond_to?('cache_delete')
o.cache_delete if o.respond_to?('cache_delete') other.cache_delete if other.respond_to?('cache_delete')
true true
end end

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Avatar < ApplicationModel class Avatar < ApplicationModel
belongs_to :object_lookup, class_name: 'ObjectLookup' belongs_to :object_lookup
=begin =begin

View file

@ -4,7 +4,7 @@ class Channel < ApplicationModel
load 'channel/assets.rb' load 'channel/assets.rb'
include Channel::Assets include Channel::Assets
belongs_to :group, class_name: 'Group' belongs_to :group
store :options store :options
store :preferences store :preferences

View file

@ -8,9 +8,12 @@ class Chat::Session < ApplicationModel
load 'chat/session/assets.rb' load 'chat/session/assets.rb'
include Chat::Session::Assets include Chat::Session::Assets
# rubocop:disable Rails/InverseOf
has_many :messages, class_name: 'Chat::Message', foreign_key: 'chat_session_id' has_many :messages, class_name: 'Chat::Message', foreign_key: 'chat_session_id'
# rubocop:enable Rails/InverseOf
before_create :generate_session_id before_create :generate_session_id
store :preferences store :preferences
def generate_session_id def generate_session_id

View file

@ -173,7 +173,7 @@ returns
record.with_lock do record.with_lock do
record.associations_from_param(attributes) record.associations_from_param(attributes)
record.update_attributes!(clean_params) record.update!(clean_params)
end end
rescue => e rescue => e
errors.push "Line #{line_count}: #{e.message}" errors.push "Line #{line_count}: #{e.message}"

View file

@ -5,9 +5,17 @@ class History < ApplicationModel
include History::Assets include History::Assets
self.table_name = 'histories' self.table_name = 'histories'
# rubocop:disable Rails/InverseOf
belongs_to :history_type, class_name: 'History::Type' belongs_to :history_type, class_name: 'History::Type'
belongs_to :history_object, class_name: 'History::Object' belongs_to :history_object, class_name: 'History::Object'
belongs_to :history_attribute, class_name: 'History::Attribute' belongs_to :history_attribute, class_name: 'History::Attribute'
# rubocop:enable Rails/InverseOf
# the noop is needed since Layout/EmptyLines detects
# the block commend below wrongly as the measurement of
# the wanted indentation of the rubocop re-enabling above
def noop; end
=begin =begin

View file

@ -1,7 +1,7 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Karma::ActivityLog < ApplicationModel class Karma::ActivityLog < ApplicationModel
belongs_to :object_lookup, class_name: 'ObjectLookup' belongs_to :object_lookup
self.table_name = 'karma_activity_logs' self.table_name = 'karma_activity_logs'

View file

@ -1,8 +1,11 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Link < ApplicationModel class Link < ApplicationModel
# rubocop:disable Rails/InverseOf
belongs_to :link_type, class_name: 'Link::Type' belongs_to :link_type, class_name: 'Link::Type'
belongs_to :link_object, class_name: 'Link::Object' belongs_to :link_object, class_name: 'Link::Object'
# rubocop:enable Rails/InverseOf
after_destroy :touch_link_references after_destroy :touch_link_references

View file

@ -4,8 +4,10 @@ class ObjectManager::Attribute < ApplicationModel
self.table_name = 'object_manager_attributes' self.table_name = 'object_manager_attributes'
belongs_to :object_lookup, class_name: 'ObjectLookup' belongs_to :object_lookup
validates :name, presence: true validates :name, presence: true
store :screens store :screens
store :data_option store :data_option
store :data_option_new store :data_option_new

View file

@ -4,9 +4,11 @@ class OnlineNotification < ApplicationModel
load 'online_notification/assets.rb' load 'online_notification/assets.rb'
include OnlineNotification::Assets include OnlineNotification::Assets
belongs_to :type, class_name: 'TypeLookup', foreign_key: 'type_lookup_id'
belongs_to :object, class_name: 'ObjectLookup', foreign_key: 'object_lookup_id'
belongs_to :user belongs_to :user
# rubocop:disable Rails/InverseOf
belongs_to :object, class_name: 'ObjectLookup', foreign_key: 'object_lookup_id'
belongs_to :type, class_name: 'TypeLookup', foreign_key: 'type_lookup_id'
# rubocop:enable Rails/InverseOf
after_create :notify_clients_after_change after_create :notify_clients_after_change
after_update :notify_clients_after_change after_update :notify_clients_after_change

View file

@ -15,12 +15,15 @@ class Organization < ApplicationModel
load 'organization/search_index.rb' load 'organization/search_index.rb'
include Organization::SearchIndex include Organization::SearchIndex
# rubocop:disable Rails/InverseOf
has_many :members, class_name: 'User' has_many :members, class_name: 'User'
validates :name, presence: true # rubocop:enable Rails/InverseOf
before_create :domain_cleanup before_create :domain_cleanup
before_update :domain_cleanup before_update :domain_cleanup
validates :name, presence: true
activity_stream_permission 'admin.role' activity_stream_permission 'admin.role'
private private

View file

@ -77,7 +77,7 @@ class Overview < ApplicationModel
while check while check
count += 1 count += 1
exists = Overview.find_by(link: local_lookup_link) exists = Overview.find_by(link: local_lookup_link)
if exists && exists.id != id # rubocop:disable Style/SafeNavigation if exists && exists.id != id
local_lookup_link = "#{local_link}_#{count}" local_lookup_link = "#{local_link}_#{count}"
else else
check = false check = false

View file

@ -4,7 +4,10 @@ class RecentView < ApplicationModel
load 'recent_view/assets.rb' load 'recent_view/assets.rb'
include RecentView::Assets include RecentView::Assets
# rubocop:disable Rails/InverseOf
belongs_to :ticket, foreign_key: 'o_id'
belongs_to :object, class_name: 'ObjectLookup', foreign_key: 'recent_view_object_id' belongs_to :object, class_name: 'ObjectLookup', foreign_key: 'recent_view_object_id'
# rubocop:enable Rails/InverseOf
after_create :notify_clients after_create :notify_clients
after_update :notify_clients after_update :notify_clients

View file

@ -311,7 +311,7 @@ class Scheduler < ApplicationModel
sleep wait sleep wait
logger.debug { '*** worker thread loop' } logger.debug { '*** worker thread loop' }
else else
format "*** #{count} jobs processed at %.4f j/s, %d failed ...\n", count / realtime, result.last format "*** #{count} jobs processed at %<jps>.4f j/s, %<failed>d failed ...\n", jps: count / realtime, failed: result.last
end end
end end

View file

@ -163,7 +163,7 @@ reload config settings
# convert state into hash to be able to store it as store # convert state into hash to be able to store it as store
def state_check def state_check
return true if !state return true if !state
return true if state && state.respond_to?('has_key?') && state.key?(:value) return true if state.try(:key?, :value)
self.state_current = { value: state } self.state_current = { value: state }
true true
end end

View file

@ -4,11 +4,15 @@ class Store < ApplicationModel
load 'store/object.rb' load 'store/object.rb'
load 'store/file.rb' load 'store/file.rb'
store :preferences # rubocop:disable Rails/InverseOf
belongs_to :store_object, class_name: 'Store::Object' belongs_to :store_object, class_name: 'Store::Object'
belongs_to :store_file, class_name: 'Store::File' belongs_to :store_file, class_name: 'Store::File'
# rubocop:enable Rails/InverseOf
validates :filename, presence: true validates :filename, presence: true
store :preferences
=begin =begin
add an attachment to storage add an attachment to storage

View file

@ -1,8 +1,16 @@
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
class Tag < ApplicationModel class Tag < ApplicationModel
# rubocop:disable Rails/InverseOf
belongs_to :tag_object, class_name: 'Tag::Object' belongs_to :tag_object, class_name: 'Tag::Object'
belongs_to :tag_item, class_name: 'Tag::Item' belongs_to :tag_item, class_name: 'Tag::Item'
# rubocop:enable Rails/InverseOf
# the noop is needed since Layout/EmptyLines detects
# the block commend below wrongly as the measurement of
# the wanted indentation of the rubocop re-enabling above
def noop; end
=begin =begin

View file

@ -55,10 +55,12 @@ class Ticket < ApplicationModel
:article_count, :article_count,
:preferences :preferences
belongs_to :group, class_name: 'Group' belongs_to :group
has_many :articles, class_name: 'Ticket::Article', after_add: :cache_update, after_remove: :cache_update, dependent: :destroy belongs_to :organization
has_many :ticket_time_accounting, class_name: 'Ticket::TimeAccounting', dependent: :destroy has_many :articles, class_name: 'Ticket::Article', after_add: :cache_update, after_remove: :cache_update, dependent: :destroy, inverse_of: :ticket
belongs_to :organization, class_name: 'Organization' has_many :ticket_time_accounting, class_name: 'Ticket::TimeAccounting', dependent: :destroy, inverse_of: :ticket
# rubocop:disable Rails/InverseOf
belongs_to :state, class_name: 'Ticket::State' belongs_to :state, class_name: 'Ticket::State'
belongs_to :priority, class_name: 'Ticket::Priority' belongs_to :priority, class_name: 'Ticket::Priority'
belongs_to :owner, class_name: 'User' belongs_to :owner, class_name: 'User'
@ -67,6 +69,7 @@ class Ticket < ApplicationModel
belongs_to :updated_by, class_name: 'User' belongs_to :updated_by, class_name: 'User'
belongs_to :create_article_type, class_name: 'Ticket::Article::Type' belongs_to :create_article_type, class_name: 'Ticket::Article::Type'
belongs_to :create_article_sender, class_name: 'Ticket::Article::Sender' belongs_to :create_article_sender, class_name: 'Ticket::Article::Sender'
# rubocop:enable Rails/InverseOf
self.inheritance_column = nil self.inheritance_column = nil

View file

@ -11,17 +11,22 @@ class Ticket::Article < ApplicationModel
include Ticket::Article::Assets include Ticket::Article::Assets
belongs_to :ticket belongs_to :ticket
has_one :ticket_time_accounting, class_name: 'Ticket::TimeAccounting', foreign_key: :ticket_article_id, dependent: :destroy has_one :ticket_time_accounting, class_name: 'Ticket::TimeAccounting', foreign_key: :ticket_article_id, dependent: :destroy, inverse_of: :ticket_article
# rubocop:disable Rails/InverseOf
belongs_to :type, class_name: 'Ticket::Article::Type' belongs_to :type, class_name: 'Ticket::Article::Type'
belongs_to :sender, class_name: 'Ticket::Article::Sender' belongs_to :sender, class_name: 'Ticket::Article::Sender'
belongs_to :created_by, class_name: 'User' belongs_to :created_by, class_name: 'User'
belongs_to :updated_by, class_name: 'User' belongs_to :updated_by, class_name: 'User'
belongs_to :origin_by, class_name: 'User' belongs_to :origin_by, class_name: 'User'
store :preferences # rubocop:enable Rails/InverseOf
before_create :check_subject, :check_body, :check_message_id_md5 before_create :check_subject, :check_body, :check_message_id_md5
before_update :check_subject, :check_body, :check_message_id_md5 before_update :check_subject, :check_body, :check_message_id_md5
after_destroy :store_delete after_destroy :store_delete
store :preferences
sanitized_html :body sanitized_html :body
activity_stream_permission 'ticket.agent' activity_stream_permission 'ticket.agent'

View file

@ -2,12 +2,15 @@
class Ticket::State < ApplicationModel class Ticket::State < ApplicationModel
include ChecksLatestChangeObserved include ChecksLatestChangeObserved
belongs_to :state_type, class_name: 'Ticket::StateType', inverse_of: :states
# rubocop:disable Rails/InverseOf
belongs_to :next_state, class_name: 'Ticket::State'
# rubocop:enable Rails/InverseOf
after_create :ensure_defaults after_create :ensure_defaults
after_update :ensure_defaults after_update :ensure_defaults
after_destroy :ensure_defaults after_destroy :ensure_defaults
belongs_to :state_type, class_name: 'Ticket::StateType'
belongs_to :next_state, class_name: 'Ticket::State'
validates :name, presence: true validates :name, presence: true
attr_accessor :callback_loop attr_accessor :callback_loop

View file

@ -2,6 +2,7 @@
class Ticket::StateType < ApplicationModel class Ticket::StateType < ApplicationModel
include ChecksLatestChangeObserved include ChecksLatestChangeObserved
has_many :states, class_name: 'Ticket::State' has_many :states, class_name: 'Ticket::State', inverse_of: :state_type
validates :name, presence: true validates :name, presence: true
end end

View file

@ -2,7 +2,7 @@
class Ticket::TimeAccounting < ApplicationModel class Ticket::TimeAccounting < ApplicationModel
belongs_to :ticket belongs_to :ticket
belongs_to :ticket_article, class_name: 'Ticket::Article' belongs_to :ticket_article, class_name: 'Ticket::Article', inverse_of: :ticket_time_accounting
after_create :ticket_time_unit_update after_create :ticket_time_unit_update
after_update :ticket_time_unit_update after_update :ticket_time_unit_update

View file

@ -39,6 +39,12 @@ class User < ApplicationModel
load 'user/search_index.rb' load 'user/search_index.rb'
include User::SearchIndex include User::SearchIndex
has_and_belongs_to_many :roles, after_add: %i[cache_update check_notifications], after_remove: :cache_update, before_add: %i[validate_agent_limit_by_role validate_roles], before_remove: :last_admin_check_by_role, class_name: 'Role'
has_and_belongs_to_many :organizations, after_add: :cache_update, after_remove: :cache_update, class_name: 'Organization'
has_many :tokens, after_add: :cache_update, after_remove: :cache_update
has_many :authorizations, after_add: :cache_update, after_remove: :cache_update
belongs_to :organization, inverse_of: :members
before_validation :check_name, :check_email, :check_login, :check_mail_delivery_failed, :ensure_uniq_email, :ensure_password, :ensure_roles, :ensure_identifier before_validation :check_name, :check_email, :check_login, :check_mail_delivery_failed, :ensure_uniq_email, :ensure_password, :ensure_roles, :ensure_identifier
before_create :check_preferences_default, :validate_ooo, :domain_based_assignment, :set_locale before_create :check_preferences_default, :validate_ooo, :domain_based_assignment, :set_locale
before_update :check_preferences_default, :validate_ooo, :reset_login_failed, :validate_agent_limit_by_attributes, :last_admin_check_by_attribute before_update :check_preferences_default, :validate_ooo, :reset_login_failed, :validate_agent_limit_by_attributes, :last_admin_check_by_attribute
@ -46,13 +52,6 @@ class User < ApplicationModel
after_update :avatar_for_email_check after_update :avatar_for_email_check
before_destroy :avatar_destroy, :user_device_destroy, :cit_caller_id_destroy, :task_destroy before_destroy :avatar_destroy, :user_device_destroy, :cit_caller_id_destroy, :task_destroy
has_and_belongs_to_many :roles, after_add: %i[cache_update check_notifications], after_remove: :cache_update, before_add: %i[validate_agent_limit_by_role validate_roles], before_remove: :last_admin_check_by_role, class_name: 'Role'
has_and_belongs_to_many :organizations, after_add: :cache_update, after_remove: :cache_update, class_name: 'Organization'
#has_many :permissions, class_name: 'Permission', through: :roles, class_name: 'Role'
has_many :tokens, after_add: :cache_update, after_remove: :cache_update
has_many :authorizations, after_add: :cache_update, after_remove: :cache_update
belongs_to :organization, class_name: 'Organization'
store :preferences store :preferences
activity_stream_permission 'admin.user' activity_stream_permission 'admin.user'
@ -804,12 +803,12 @@ returns
true true
end end
def check_notifications(o, should_save = true) def check_notifications(other, should_save = true)
default = Rails.configuration.preferences_default_by_permission default = Rails.configuration.preferences_default_by_permission
return if !default return if !default
default.deep_stringify_keys! default.deep_stringify_keys!
has_changed = false has_changed = false
o.permissions.each do |permission| other.permissions.each do |permission|
next if !default[permission.name] next if !default[permission.name]
default[permission.name].each do |key, value| default[permission.name].each do |key, value|
next if preferences[key] next if preferences[key]
@ -871,11 +870,7 @@ returns
if (firstname.blank? && lastname.present?) || (firstname.present? && lastname.blank?) if (firstname.blank? && lastname.present?) || (firstname.present? && lastname.blank?)
# "Lastname, Firstname" # "Lastname, Firstname"
used_name = if firstname.blank? used_name = firstname.presence || lastname
lastname
else
firstname
end
name = used_name.split(', ', 2) name = used_name.split(', ', 2)
if name.count == 2 if name.count == 2
if name[0].present? if name[0].present?
@ -948,7 +943,7 @@ returns
check = true check = true
while check while check
exists = User.find_by(login: login) exists = User.find_by(login: login)
if exists && exists.id != id # rubocop:disable Style/SafeNavigation if exists && exists.id != id
self.login = "#{login}#{rand(999)}" self.login = "#{login}#{rand(999)}"
else else
check = false check = false

View file

@ -1,3 +1,3 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
load Gem.bin_path('bundler', 'bundle') load Gem.bin_path('bundler', 'bundle')

View file

@ -2,7 +2,7 @@
require 'pathname' require 'pathname'
# path to your application root. # path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) APP_ROOT = Pathname.new File.expand_path('..', __dir__)
Dir.chdir APP_ROOT do Dir.chdir APP_ROOT do
# This script is a starting point to setup your application. # This script is a starting point to setup your application.

View file

@ -1,4 +1,4 @@
require File.expand_path('../boot', __FILE__) require File.expand_path('boot', __dir__)
require 'rails/all' require 'rails/all'

View file

@ -1,3 +1,3 @@
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile. require 'bundler/setup' # Set up gems listed in the Gemfile.

View file

@ -1,5 +1,5 @@
# Load the Rails application. # Load the Rails application.
require File.expand_path('../application', __FILE__) require File.expand_path('application', __dir__)
# Initialize the Rails application. # Initialize the Rails application.
Rails.application.initialize! Rails.application.initialize!

View file

@ -8,7 +8,7 @@ Rails.application.routes.draw do
root to: 'init#index', via: :get root to: 'init#index', via: :get
# load routes from external files # load routes from external files
dir = File.expand_path('../', __FILE__) dir = File.expand_path(__dir__)
files = Dir.glob( "#{dir}/routes/*.rb" ) files = Dir.glob( "#{dir}/routes/*.rb" )
files.each do |file| files.each do |file|
if Rails.configuration.cache_classes if Rails.configuration.cache_classes

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/BooleanSymbol
class ObjectManagerUpdateUser < ActiveRecord::Migration[4.2] class ObjectManagerUpdateUser < ActiveRecord::Migration[4.2]
def up def up
@ -569,6 +568,7 @@ class ObjectManagerUpdateUser < ActiveRecord::Migration[4.2]
position: 1400, position: 1400,
) )
# rubocop:disable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,
object: 'User', object: 'User',
@ -607,6 +607,7 @@ class ObjectManagerUpdateUser < ActiveRecord::Migration[4.2]
to_delete: false, to_delete: false,
position: 1490, position: 1490,
) )
# rubocop:enable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/BooleanSymbol
class OrganizationDomainBasedAssignment < ActiveRecord::Migration[4.2] class OrganizationDomainBasedAssignment < ActiveRecord::Migration[4.2]
def up def up
# return if it's a new setup # return if it's a new setup
@ -8,6 +7,7 @@ class OrganizationDomainBasedAssignment < ActiveRecord::Migration[4.2]
add_column :organizations, :domain_assignment, :boolean, null: false, default: false add_column :organizations, :domain_assignment, :boolean, null: false, default: false
add_index :organizations, [:domain] add_index :organizations, [:domain]
# rubocop:disable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,
object: 'Organization', object: 'Organization',
@ -46,6 +46,7 @@ class OrganizationDomainBasedAssignment < ActiveRecord::Migration[4.2]
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
# rubocop:enable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/BooleanSymbol
class FixedAdminUserPermission920 < ActiveRecord::Migration[4.2] class FixedAdminUserPermission920 < ActiveRecord::Migration[4.2]
def up def up
@ -331,6 +330,7 @@ class FixedAdminUserPermission920 < ActiveRecord::Migration[4.2]
position: 100, position: 100,
) )
# rubocop:disable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,
object: 'TicketArticle', object: 'TicketArticle',
@ -363,6 +363,7 @@ class FixedAdminUserPermission920 < ActiveRecord::Migration[4.2]
to_delete: false, to_delete: false,
position: 200, position: 200,
) )
# rubocop:enable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,
@ -487,6 +488,7 @@ class FixedAdminUserPermission920 < ActiveRecord::Migration[4.2]
position: 1400, position: 1400,
) )
# rubocop:disable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,
object: 'User', object: 'User',
@ -523,6 +525,7 @@ class FixedAdminUserPermission920 < ActiveRecord::Migration[4.2]
to_delete: false, to_delete: false,
position: 1490, position: 1490,
) )
# rubocop:enable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,
@ -597,6 +600,7 @@ class FixedAdminUserPermission920 < ActiveRecord::Migration[4.2]
position: 1800, position: 1800,
) )
# rubocop:disable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,
object: 'Organization', object: 'Organization',
@ -672,6 +676,7 @@ class FixedAdminUserPermission920 < ActiveRecord::Migration[4.2]
to_delete: false, to_delete: false,
position: 1410, position: 1410,
) )
# rubocop:enable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,

View file

@ -1,10 +1,10 @@
# rubocop:disable Rails/ReversibleMigration
class RemoveNetwork < ActiveRecord::Migration[5.0] class RemoveNetwork < ActiveRecord::Migration[5.0]
# rewinds db/migrate/20120101000020_create_network.rb # rewinds db/migrate/20120101000020_create_network.rb
def change def change
return if !ActiveRecord::Base.connection.table_exists? 'networks' return if !ActiveRecord::Base.connection.table_exists? 'networks'
# rubocop:disable Rails/ReversibleMigration
drop_table :networks drop_table :networks
drop_table :network_category_types drop_table :network_category_types
drop_table :network_privacies drop_table :network_privacies
@ -15,5 +15,6 @@ class RemoveNetwork < ActiveRecord::Migration[5.0]
drop_table :network_item_plus drop_table :network_item_plus
drop_table :network_category_subscriptions drop_table :network_category_subscriptions
drop_table :network_item_subscriptions drop_table :network_item_subscriptions
# rubocop:enable Rails/ReversibleMigration
end end
end end

View file

@ -3,8 +3,11 @@ class ChangeExchangeExternalSyncIdentifier < ActiveRecord::Migration[5.1]
# return if it's a new setup to avoid running the migration # return if it's a new setup to avoid running the migration
return if !Setting.find_by(name: 'system_init_done') return if !Setting.find_by(name: 'system_init_done')
# rubocop:disable Rails/SkipsModelValidations ExternalSync.where(
ExternalSync.where(source: 'EWS::FolderContact').update_all(source: 'Exchange::FolderContact') source: 'EWS::FolderContact'
).update_all( # rubocop:disable Rails/SkipsModelValidations
source: 'Exchange::FolderContact'
)
end end
end end

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/BooleanSymbol
ObjectManager::Attribute.add( ObjectManager::Attribute.add(
force: true, force: true,
object: 'Ticket', object: 'Ticket',

View file

@ -1,11 +1,9 @@
# rubocop:disable Naming/FileName if Kernel.respond_to?(:open_uri_original_open) # rubocop:disable Naming/FileName
# rubocop:disable Style/CommentedKeyword
if Kernel.respond_to?(:open_uri_original_open)
module Kernel module Kernel
private private
# see: https://github.com/ruby/ruby/pull/1675 # see: https://github.com/ruby/ruby/pull/1675
def open(name, *rest, &block) # :doc: def open(name, *rest, &block)
if name.respond_to?(:open) && name.method(:open).parameters.present? if name.respond_to?(:open) && name.method(:open).parameters.present?
name.open(*rest, &block) name.open(*rest, &block)
elsif name.respond_to?(:to_str) && elsif name.respond_to?(:to_str) &&

View file

@ -56,11 +56,7 @@ or
def self.email(params) def self.email(params)
# send verify email # send verify email
subject = if params[:subject].blank? subject = params[:subject].presence || '#' + rand(99_999_999_999).to_s
'#' + rand(99_999_999_999).to_s
else
params[:subject]
end
result = EmailHelper::Probe.outbound(params[:outbound], params[:sender], subject) result = EmailHelper::Probe.outbound(params[:outbound], params[:sender], subject)
if result[:result] != 'ok' if result[:result] != 'ok'
result[:source] = 'outbound' result[:source] = 'outbound'

View file

@ -205,3 +205,4 @@ or if you only want to create 100 tickets
end end
end end
end end
# rubocop:enable Rails/Output

View file

@ -168,7 +168,7 @@ satinize html string based on whiltelist
end end
# remove attributes if not whitelisted # remove attributes if not whitelisted
node.each do |attribute, _value| # rubocop:disable Performance/HashEachMethods node.each do |attribute, _value|
attribute_name = attribute.downcase attribute_name = attribute.downcase
next if attributes_whitelist[:all].include?(attribute_name) || (attributes_whitelist[node.name]&.include?(attribute_name)) next if attributes_whitelist[:all].include?(attribute_name) || (attributes_whitelist[node.name]&.include?(attribute_name))
node.delete(attribute) node.delete(attribute)

View file

@ -11,7 +11,7 @@ module Import
end end
def extract def extract
@attributes ||= begin @extract ||= begin
properties = @resource.get_all_properties! properties = @resource.get_all_properties!
result = normalize(properties) result = normalize(properties)
flattened = flatten(result) flattened = flatten(result)

View file

@ -21,6 +21,7 @@ module Import
rescue => e rescue => e
# rubocop:disable Style/SpecialGlobalVars # rubocop:disable Style/SpecialGlobalVars
raise $!, "Problem with ObjectManager Attribute '#{name}': #{$!}", $!.backtrace raise $!, "Problem with ObjectManager Attribute '#{name}': #{$!}", $!.backtrace
# rubocop:enable Style/SpecialGlobalVars
end end
def attribute_config(object, name, attribute) def attribute_config(object, name, attribute)

View file

@ -11,7 +11,7 @@ require 'net/ldap/entry'
# @return [String] the base dn used while initializing the connection # @return [String] the base dn used while initializing the connection
class Ldap class Ldap
attr_reader :connection, :base_dn, :host, :port, :ssl attr_reader :base_dn, :host, :port, :ssl
# Initializes a LDAP connection. # Initializes a LDAP connection.
# #
@ -35,7 +35,8 @@ class Ldap
@config = Setting.get('ldap_config') @config = Setting.get('ldap_config')
end end
connect # connect on initialization
connection
end end
# Requests the rootDSE (the root of the directory data tree on a directory server). # Requests the rootDSE (the root of the directory data tree on a directory server).
@ -46,7 +47,7 @@ class Ldap
# #
# @return [Hash{String => Array<String>}] The found RootDSEs. # @return [Hash{String => Array<String>}] The found RootDSEs.
def preferences def preferences
@connection.search_root_dse.to_h connection.search_root_dse.to_h
end end
# Performs a LDAP search and yields over the found LDAP entries. # Performs a LDAP search and yields over the found LDAP entries.
@ -68,7 +69,7 @@ class Ldap
base ||= base_dn() base ||= base_dn()
scope ||= Net::LDAP::SearchScope_WholeSubtree scope ||= Net::LDAP::SearchScope_WholeSubtree
@connection.search( connection.search(
base: base, base: base,
filter: filter, filter: filter,
scope: scope, scope: scope,
@ -114,15 +115,15 @@ class Ldap
counter counter
end end
private def connection
def connect
@connection ||= begin @connection ||= begin
attributes_from_config attributes_from_config
binded_connection binded_connection
end end
end end
private
def binded_connection def binded_connection
# ldap connect # ldap connect
ldap = Net::LDAP.new(connection_params) ldap = Net::LDAP.new(connection_params)
@ -175,7 +176,7 @@ class Ldap
# fallback to default # fallback to default
# port if none given # port if none given
@port ||= 389 @port ||= 389 # rubocop:disable Naming/MemoizedInstanceVariableName
end end
def parse_host_url def parse_host_url

View file

@ -76,7 +76,7 @@ class Ldap
# #
# @return [String] The GUID equivalent of the HEX string. # @return [String] The GUID equivalent of the HEX string.
def string def string
oracle_raw16(guid.unpack('H*').first, dashify: true) oracle_raw16(guid.unpack1('H*'), dashify: true)
end end
private private

View file

@ -172,7 +172,7 @@ returns
) )
# rebuild subject # rebuild subject
if data[:main_object] && data[:main_object].respond_to?(:subject_build) if data[:main_object].respond_to?(:subject_build)
result[:subject] = data[:main_object].subject_build(result[:subject]) result[:subject] = data[:main_object].subject_build(result[:subject])
end end

View file

@ -3,8 +3,7 @@
module PasswordHash module PasswordHash
include ApplicationLib include ApplicationLib
# rubocop:disable Style/ModuleFunction extend self # rubocop:disable Style/ModuleFunction
extend self
def crypt(password) def crypt(password)
argon2.create(password) argon2.create(password)

View file

@ -53,7 +53,7 @@ class Sequencer
end end
def __setobj__(declarations) def __setobj__(declarations)
@attributes ||= begin @attributes ||= begin # rubocop:disable Naming/MemoizedInstanceVariableName
attributes = Hash.new do |hash, key| attributes = Hash.new do |hash, key|
hash[key] = Sequencer::Units::Attribute.new hash[key] = Sequencer::Units::Attribute.new
end end

View file

@ -2,11 +2,10 @@
class Service::Image::Zammad class Service::Image::Zammad
# rubocop:disable Style/ClassVars API_HOST = 'https://images.zammad.com'.freeze
@@api_host = 'https://images.zammad.com' OPEN_TIMEOUT = 4
@@open_timeout = 4 READ_TIMEOUT = 6
@@read_timeout = 6 TOTAL_TIMEOUT = 6
@@total_timeout = 6
def self.user(email) def self.user(email)
raise Exceptions::UnprocessableEntity, 'no email given' if email.blank? raise Exceptions::UnprocessableEntity, 'no email given' if email.blank?
@ -17,14 +16,14 @@ class Service::Image::Zammad
# fetch image # fetch image
response = UserAgent.post( response = UserAgent.post(
"#{@@api_host}/api/v1/person/image", "#{API_HOST}/api/v1/person/image",
{ {
email: email, email: email,
}, },
{ {
open_timeout: @@open_timeout, open_timeout: OPEN_TIMEOUT,
read_timeout: @@read_timeout, read_timeout: READ_TIMEOUT,
total_timeout: @@total_timeout, total_timeout: TOTAL_TIMEOUT,
}, },
) )
if !response.success? if !response.success?
@ -50,14 +49,14 @@ class Service::Image::Zammad
# fetch org logo # fetch org logo
response = UserAgent.post( response = UserAgent.post(
"#{@@api_host}/api/v1/organization/image", "#{API_HOST}/api/v1/organization/image",
{ {
domain: domain domain: domain
}, },
{ {
open_timeout: @@open_timeout, open_timeout: OPEN_TIMEOUT,
read_timeout: @@read_timeout, read_timeout: READ_TIMEOUT,
total_timeout: @@total_timeout, total_timeout: TOTAL_TIMEOUT,
}, },
) )
if !response.success? if !response.success?

View file

@ -5,7 +5,7 @@ module SessionHelper
default_collection = {} default_collection = {}
# load collections to deliver from external files # load collections to deliver from external files
dir = File.expand_path('../../', __FILE__) dir = File.expand_path('..', __dir__)
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb") files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb")
files.each do |file| files.each do |file|
load file load file

View file

@ -28,7 +28,7 @@ class Sessions::Backend::Collections < Sessions::Backend::Base
backends = [] backends = []
# load collections to deliver from external files # load collections to deliver from external files
dir = File.expand_path('../../../../', __FILE__) dir = File.expand_path('../../..', __dir__)
files = Dir.glob("#{dir}/lib/sessions/backend/collections/*.rb") files = Dir.glob("#{dir}/lib/sessions/backend/collections/*.rb")
files.each do |file| files.each do |file|
file.gsub!("#{dir}/lib/", '') file.gsub!("#{dir}/lib/", '')

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby #!/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. # 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', __FILE__) APP_PATH = File.expand_path('../config/application', __dir__)
require File.expand_path('../../config/boot', __FILE__) require File.expand_path('../config/boot', __dir__)
require 'rails/commands' require 'rails/commands'

View file

@ -57,7 +57,6 @@ RSpec.describe ImportJob do
payload: {}, payload: {},
delay: false delay: false
) )
end.not_to change { end.not_to change {
Delayed::Job.count Delayed::Job.count
} }
@ -72,7 +71,6 @@ RSpec.describe ImportJob do
name: test_backend_name, name: test_backend_name,
payload: {}, payload: {},
) )
end.not_to change { end.not_to change {
Delayed::Job.count Delayed::Job.count
} }

View file

@ -14,6 +14,7 @@ RSpec.describe Scheduler do
def self.reschedule=(reschedule) def self.reschedule=(reschedule)
@reschedule = reschedule @reschedule = reschedule
end end
# rubocop:enable Style/TrivialAccessors
def self.reschedule?(_delayed_job) def self.reschedule?(_delayed_job)
@reschedule || false @reschedule || false

View file

@ -1,6 +1,6 @@
# This file is copied to spec/ when you run 'rails generate rspec:install' # This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test' ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__) require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production # Prevent database truncation if the environment is production
abort('The Rails environment is running in production mode!') if Rails.env.production? abort('The Rails environment is running in production mode!') if Rails.env.production?

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/BooleanSymbol
require 'browser_test_helper' require 'browser_test_helper'
class AdminObjectManagerTest < TestCase class AdminObjectManagerTest < TestCase
@ -248,6 +247,7 @@ class AdminObjectManagerTest < TestCase
}, },
) )
# rubocop:disable Lint/BooleanSymbol
object_manager_attribute_create( object_manager_attribute_create(
data: { data: {
name: 'browser_test7', name: 'browser_test7',
@ -262,6 +262,7 @@ class AdminObjectManagerTest < TestCase
}, },
}, },
) )
# rubocop:enable Lint/BooleanSymbol
watch_for( watch_for(
css: '.content.active', css: '.content.active',

View file

@ -1,10 +1,12 @@
ENV['RAILS_ENV'] = 'test' ENV['RAILS_ENV'] = 'test'
# rubocop:disable HandleExceptions, ClassVars, NonLocalExitFromIterator, Style/GuardClause # rubocop:disable HandleExceptions, NonLocalExitFromIterator, Style/GuardClause, Lint/MissingCopEnableDirective
require File.expand_path('../../config/environment', __FILE__) require File.expand_path('../config/environment', __dir__)
require 'selenium-webdriver' require 'selenium-webdriver'
class TestCase < Test::Unit::TestCase class TestCase < Test::Unit::TestCase
@@debug = true
DEBUG = true
def browser def browser
ENV['BROWSER'] || 'firefox' ENV['BROWSER'] || 'firefox'
end end
@ -60,7 +62,7 @@ class TestCase < Test::Unit::TestCase
local_browser = browser_instance_remote local_browser = browser_instance_remote
break break
rescue rescue
wait_until_ready = rand(9) + 5 wait_until_ready = rand(5..13)
sleep wait_until_ready sleep wait_until_ready
log('browser_instance', { rescure: true, count: count, sleep: wait_until_ready }) log('browser_instance', { rescure: true, count: count, sleep: wait_until_ready })
end end
@ -3696,7 +3698,7 @@ wait untill text in selector disabppears
rescue rescue
# failed to get logs # failed to get logs
end end
return if !@@debug return if !DEBUG
return if params[:mute_log] return if params[:mute_log]
puts "#{Time.zone.now}/#{method}: #{params.inspect}" puts "#{Time.zone.now}/#{method}: #{params.inspect}"
end end

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/BooleanSymbol
require 'test_helper' require 'test_helper'
require 'rake' require 'rake'

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/BooleanSymbol
require 'test_helper' require 'test_helper'
class ObjectManagerTest < ActiveSupport::TestCase class ObjectManagerTest < ActiveSupport::TestCase

View file

@ -1,5 +1,5 @@
ENV['RAILS_ENV'] = 'test' ENV['RAILS_ENV'] = 'test'
require File.expand_path('../../config/environment', __FILE__) require File.expand_path('../config/environment', __dir__)
require 'rails/test_help' require 'rails/test_help'
require 'cache' require 'cache'

View file

@ -1,5 +1,5 @@
ENV['RAILS_ENV'] = 'test' ENV['RAILS_ENV'] = 'test'
require File.expand_path('../../config/environment', __FILE__) require File.expand_path('../config/environment', __dir__)
require 'rails/test_help' require 'rails/test_help'
require 'cache' require 'cache'
require 'simplecov' require 'simplecov'

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/InterpolationCheck
require 'test_helper' require 'test_helper'
class EmailProcessAutoResponseTest < ActiveSupport::TestCase class EmailProcessAutoResponseTest < ActiveSupport::TestCase

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/InterpolationCheck
require 'test_helper' require 'test_helper'
class EmailProcessBounceDeliveryPermanentFailedTest < ActiveSupport::TestCase class EmailProcessBounceDeliveryPermanentFailedTest < ActiveSupport::TestCase

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/InterpolationCheck
require 'test_helper' require 'test_helper'
class EmailProcessBounceFollowUpTest < ActiveSupport::TestCase class EmailProcessBounceFollowUpTest < ActiveSupport::TestCase

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/InterpolationCheck
require 'test_helper' require 'test_helper'
class NotificationFactoryRendererTest < ActiveSupport::TestCase class NotificationFactoryRendererTest < ActiveSupport::TestCase

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/InterpolationCheck
require 'test_helper' require 'test_helper'
class NotificationFactoryTemplateTest < ActiveSupport::TestCase class NotificationFactoryTemplateTest < ActiveSupport::TestCase

View file

@ -139,18 +139,18 @@ class OrganizationAssetsTest < ActiveSupport::TestCase
assert_not(Organization.find_by(id: org_new.id)) assert_not(Organization.find_by(id: org_new.id))
end end
def diff(o1, o2) def diff(object1, object2)
return true if o1 == o2 return true if object1 == object2
%w[updated_at created_at].each do |item| %w[updated_at created_at].each do |item|
if o1[item] if object1[item]
o1[item] = o1[item].to_s object1[item] = object1[item].to_s
end end
if o2[item] if object2[item]
o2[item] = o2[item].to_s object2[item] = object2[item].to_s
end end
end end
return true if (o1.to_a - o2.to_a).blank? return true if (object1.to_a - object2.to_a).blank?
#puts "ERROR: difference \n1: #{o1.inspect}\n2: #{o2.inspect}\ndiff: #{(o1.to_a - o2.to_a).inspect}" #puts "ERROR: difference \n1: #{object1.inspect}\n2: #{object2.inspect}\ndiff: #{(object1.to_a - object2.to_a).inspect}"
false false
end end

View file

@ -3,6 +3,10 @@ require 'test_helper'
class TicketArticleDos < ActiveSupport::TestCase class TicketArticleDos < ActiveSupport::TestCase
def two_mio_random_chars
@two_mio_random_chars ||= Array.new(2_000_000) { [*'0'..'9', *'a'..'z', ' ', ' ', ' ', '. '].sample }.join
end
test 'check body size' do test 'check body size' do
org_community = Organization.create_if_not_exists( org_community = Organization.create_if_not_exists(
@ -36,7 +40,7 @@ class TicketArticleDos < ActiveSupport::TestCase
type_id: Ticket::Article::Type.find_by(name: 'phone').id, type_id: Ticket::Article::Type.find_by(name: 'phone').id,
sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id, sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
from: 'Zammad Feedback <feedback@example.org>', from: 'Zammad Feedback <feedback@example.org>',
body: Array.new(2_000_000) { [*'0'..'9', *'a'..'z', ' ', ' ', ' ', '. '].sample }.join, body: two_mio_random_chars,
internal: false, internal: false,
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
@ -55,7 +59,7 @@ class TicketArticleDos < ActiveSupport::TestCase
type_id: Ticket::Article::Type.find_by(name: 'phone').id, type_id: Ticket::Article::Type.find_by(name: 'phone').id,
sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id, sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
from: 'Zammad Feedback <feedback@example.org>', from: 'Zammad Feedback <feedback@example.org>',
body: "\u0000#{Array.new(2_000_000) { [*'0'..'9', *'a'..'z', ' ', ' ', ' ', '. '].sample }.join}", body: "\u0000#{two_mio_random_chars}",
internal: false, internal: false,
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
@ -78,7 +82,7 @@ class TicketArticleDos < ActiveSupport::TestCase
type_id: Ticket::Article::Type.find_by(name: 'phone').id, type_id: Ticket::Article::Type.find_by(name: 'phone').id,
sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id, sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
from: 'Zammad Feedback <feedback@example.org>', from: 'Zammad Feedback <feedback@example.org>',
body: "\u0000#{Array.new(2_000_000) { [*'0'..'9', *'a'..'z', ' ', ' ', ' ', '. '].sample }.join}", body: "\u0000#{two_mio_random_chars}",
internal: false, internal: false,
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
@ -89,11 +93,13 @@ class TicketArticleDos < ActiveSupport::TestCase
test 'check body size / cut if email' do test 'check body size / cut if email' do
email_raw_string = "From: me@example.com email_raw_string = <<-MAIL.strip_indent
To: customer@example.com From: me@example.com
Subject: some new subject To: customer@example.com
Subject: some new subject
Some Text" + Array.new(2_000_000) { [*'0'..'9', *'a'..'z', ' ', ' ', ' ', '. '].sample }.join Some Text#{two_mio_random_chars}
MAIL
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string) ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
assert_equal(1_500_000, article_p.body.length) assert_equal(1_500_000, article_p.body.length)

View file

@ -1,4 +1,3 @@
# rubocop:disable Lint/InterpolationCheck
require 'test_helper' require 'test_helper'
class TicketTriggerTest < ActiveSupport::TestCase class TicketTriggerTest < ActiveSupport::TestCase

View file

@ -139,18 +139,18 @@ class UserAssetsTest < ActiveSupport::TestCase
assert_not(Organization.find_by(id: org2.id)) assert_not(Organization.find_by(id: org2.id))
end end
def diff(o1, o2) def diff(object1, object2)
return true if o1 == o2 return true if object1 == object2
%w[updated_at created_at].each do |item| %w[updated_at created_at].each do |item|
if o1[item] if object1[item]
o1[item] = o1[item].to_s object1[item] = object1[item].to_s
end end
if o2[item] if object2[item]
o2[item] = o2[item].to_s object2[item] = object2[item].to_s
end end
end end
return true if (o1.to_a - o2.to_a).blank? return true if (object1.to_a - object2.to_a).blank?
#puts "ERROR: difference \n1: #{o1.inspect}\n2: #{o2.inspect}\ndiff: #{(o1.to_a - o2.to_a).inspect}" #puts "ERROR: difference \n1: #{object1.inspect}\n2: #{object2.inspect}\ndiff: #{(object1.to_a - object2.to_a).inspect}"
false false
end end