diff --git a/.rubocop.yml b/.rubocop.yml index 35e39b606..61171d89e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,13 +2,15 @@ # https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml AllCops: - RunRailsCops: true Exclude: - 'bin/rails' - 'bin/rake' - 'bin/spring' - 'db/schema.rb' +Rails: + Enabled: true + # Zammad StyleGuide Metrics/LineLength: @@ -30,8 +32,13 @@ Style/IfUnlessModifier: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier' Enabled: false -Style/TrailingComma: - Description: 'Checks for trailing comma in parameter lists and literals.' +Style/TrailingCommaInLiteral: + Description: 'Checks for trailing comma in array and hash literals.' + StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' + Enabled: false + +Style/TrailingCommaInArguments: + Description: 'Checks for trailing comma in argument lists.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas' Enabled: false @@ -47,12 +54,6 @@ Style/SpaceAfterMethodName: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces' Enabled: false -Style/SingleSpaceBeforeFirstArg: - Description: >- - Checks that exactly one space is used between a method name - and the first argument for method calls without parentheses. - Enabled: false - Style/LeadingCommentSpace: Description: 'Comments should start with a space.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space' diff --git a/Gemfile.lock b/Gemfile.lock index 2c925227c..100e7b2b9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,9 +44,7 @@ GEM addressable (2.4.0) arel (6.0.3) ast (2.2.0) - astrolabe (1.3.1) - parser (~> 2.2) - autoprefixer-rails (6.2.3) + autoprefixer-rails (6.3.1) execjs json biz (1.3.3) @@ -58,7 +56,7 @@ GEM browser (1.1.0) buftok (0.2.0) builder (3.2.2) - childprocess (0.5.8) + childprocess (0.5.9) ffi (~> 1.0, >= 1.0.11) clavius (1.0.1) memoizable (~> 0.4.0) @@ -95,7 +93,7 @@ GEM http_parser.rb (~> 0.6.0) equalizer (0.0.10) erubis (2.7.0) - eventmachine (1.0.8) + eventmachine (1.0.9.1) execjs (2.6.0) faraday (0.9.2) multipart-post (>= 1.2, < 3) @@ -159,7 +157,7 @@ GEM mysql2 (0.3.20) naught (1.1.0) nenv (0.2.0) - net-ldap (0.12.1) + net-ldap (0.13.0) nokogiri (1.6.7.1) mini_portile2 (~> 2.0.0.rc2) notiffany (0.0.8) @@ -177,28 +175,28 @@ GEM rack (>= 1.0, < 3) omniauth-facebook (3.0.0) omniauth-oauth2 (~> 1.2) - omniauth-google-oauth2 (0.2.10) + omniauth-google-oauth2 (0.3.0) addressable (~> 2.3) jwt (~> 1.0) multi_json (~> 1.3) omniauth (>= 1.1.1) - omniauth-oauth2 (~> 1.3.1) + omniauth-oauth2 (>= 1.3.1) omniauth-linkedin (0.2.0) omniauth-oauth (~> 1.0) omniauth-oauth (1.1.0) oauth omniauth (~> 1.0) - omniauth-oauth2 (1.3.1) + omniauth-oauth2 (1.4.0) oauth2 (~> 1.0) omniauth (~> 1.2) omniauth-twitter (1.2.1) json (~> 1.3) omniauth-oauth (~> 1.1) - parser (2.2.3.0) - ast (>= 1.1, < 3.0) + parser (2.3.0.1) + ast (~> 2.2) pluginator (1.3.0) polyglot (0.3.5) - power_assert (0.2.6) + power_assert (0.2.7) powerpack (0.1.1) pre-commit (0.26.0) pluginator (~> 1.1) @@ -239,21 +237,19 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.0.0) - rake (10.4.2) + rake (10.5.0) rb-fsevent (0.9.7) rb-inotify (0.9.5) ffi (>= 0.5.0) ref (2.0.0) - rubocop (0.35.1) - astrolabe (~> 1.3) - parser (>= 2.2.3.0, < 3.0) + rubocop (0.36.0) + parser (>= 2.3.0.0, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) - tins (<= 1.6.0) ruby-progressbar (1.7.5) rubyzip (1.1.7) - sass (3.4.20) + sass (3.4.21) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) sass (~> 3.1) @@ -261,7 +257,7 @@ GEM sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) scrub_rb (1.0.1) - selenium-webdriver (2.48.1) + selenium-webdriver (2.49.0) childprocess (~> 0.5) multi_json (~> 1.0) rubyzip (~> 1.0) @@ -277,7 +273,7 @@ GEM simplecov-rcov (0.2.3) simplecov (>= 0.4.1) slop (3.6.0) - spring (1.6.1) + spring (1.6.2) sprockets (3.5.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -293,8 +289,7 @@ GEM ref thor (0.19.1) thread_safe (0.3.5) - tilt (2.0.1) - tins (1.6.0) + tilt (2.0.2) treetop (1.4.15) polyglot polyglot (>= 0.3.1) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 25946bf47..5fb7a85f6 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -20,11 +20,11 @@ class SearchController < ApplicationController # convert objects string into array of class names # e.g. user-ticket-another_object = %w( User Ticket AnotherObject ) - if !params[:objects] - objects = Setting.get('models_searchable') - else - objects = params[:objects].split('-').map(&:camelize) - end + objects = if !params[:objects] + Setting.get('models_searchable') + else + params[:objects].split('-').map(&:camelize) + end # get priorities of result objects_in_order = [] diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 9ffee73f9..e4c30ddc5 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -18,11 +18,9 @@ class SessionsController < ApplicationController end # remember me - set session cookie to expire later - if params[:remember_me] - request.env['rack.session.options'][:expire_after] = 1.year - else - request.env['rack.session.options'][:expire_after] = nil - end + request.env['rack.session.options'][:expire_after] = if params[:remember_me] + 1.year + end # both not needed to set :expire_after works fine # request.env['rack.session.options'][:renew] = true # reset_session diff --git a/app/controllers/ticket_articles_controller.rb b/app/controllers/ticket_articles_controller.rb index da537268c..eb88e7edc 100644 --- a/app/controllers/ticket_articles_controller.rb +++ b/app/controllers/ticket_articles_controller.rb @@ -19,7 +19,7 @@ class TicketArticlesController < ApplicationController # POST /articles def create - form_id = params[:ticket_article][:form_id] + form_id = params[:ticket_article][:form_id] params[:ticket_article].delete(:form_id) @article = Ticket::Article.new( Ticket::Article.param_validation( params[:ticket_article] ) ) @@ -93,11 +93,11 @@ class TicketArticlesController < ApplicationController file = params[:File] content_type = file.content_type if !content_type || content_type == 'application/octet-stream' - if MIME::Types.type_for(file.original_filename).first - content_type = MIME::Types.type_for(file.original_filename).first.content_type - else - content_type = 'application/octet-stream' - end + content_type = if MIME::Types.type_for(file.original_filename).first + MIME::Types.type_for(file.original_filename).first.content_type + else + 'application/octet-stream' + end end headers_store = { 'Content-Type' => content_type diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 487035006..dda029b82 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -117,10 +117,10 @@ class TicketsController < ApplicationController # open tickets by customer group_ids = Group.select( 'groups.id' ) - .joins(:users) - .where( 'groups_users.user_id = ?', current_user.id ) - .where( 'groups.active = ?', true ) - .map( &:id ) + .joins(:users) + .where( 'groups_users.user_id = ?', current_user.id ) + .where( 'groups.active = ?', true ) + .map( &:id ) access_condition = [ 'group_id IN (?)', group_ids ] @@ -142,7 +142,7 @@ class TicketsController < ApplicationController } ticket_ids_recent_viewed = [] - recent_views = RecentView.list( current_user, 8, 'Ticket' ) + recent_views = RecentView.list( current_user, 8, 'Ticket' ) recent_views.each {|recent_view| next if recent_view['object'] != 'Ticket' ticket_ids_recent_viewed.push recent_view['o_id'] @@ -417,15 +417,15 @@ class TicketsController < ApplicationController # created created = Ticket.where('created_at > ? AND created_at < ?', date_start, date_end ) - .where(access_condition) - .where(condition) - .count + .where(access_condition) + .where(condition) + .count # closed closed = Ticket.where('close_time > ? AND close_time < ?', date_start, date_end ) - .where(access_condition) - .where(condition) - .count + .where(access_condition) + .where(condition) + .count data = { month: date_to_check.month, @@ -532,7 +532,7 @@ class TicketsController < ApplicationController def article_create(ticket, params) # create article if given - form_id = params[:form_id] + form_id = params[:form_id] params.delete(:form_id) article = Ticket::Article.new( Ticket::Article.param_validation( params ) ) article.ticket_id = ticket.id diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5477ef526..b320f472a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -15,11 +15,11 @@ class UsersController < ApplicationController def index # only allow customer to fetch him self - if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?('Agent') - users = User.where( id: current_user.id ) - else - users = User.all - end + users = if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?('Agent') + User.where( id: current_user.id ) + else + User.all + end users_all = [] users.each {|user| users_all.push User.lookup( id: user.id ).attributes_with_associations @@ -337,11 +337,11 @@ class UsersController < ApplicationController end # do query - if params[:role_ids] && !params[:role_ids].empty? - user_all = User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where('users.id != 1').order('users.created_at DESC').limit( params[:limit] || 20 ) - else - user_all = User.where('id != 1').order('created_at DESC').limit( params[:limit] || 20 ) - end + user_all = if params[:role_ids] && !params[:role_ids].empty? + User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where('users.id != 1').order('users.created_at DESC').limit( params[:limit] || 20 ) + else + User.where('id != 1').order('created_at DESC').limit( params[:limit] || 20 ) + end # build result list if !params[:full] diff --git a/app/models/activity_stream.rb b/app/models/activity_stream.rb index 787a9ef60..363bb5bcd 100644 --- a/app/models/activity_stream.rb +++ b/app/models/activity_stream.rb @@ -97,15 +97,15 @@ return all activity entries of an user customer_role = Role.lookup( name: 'Customer' ) return [] if role_ids.include?(customer_role.id) - if group_ids.empty? - stream = ActivityStream.where('(role_id IN (?) AND group_id is NULL)', role_ids ) - .order( 'created_at DESC, id DESC' ) - .limit( limit ) - else - stream = ActivityStream.where('(role_id IN (?) AND group_id is NULL) OR ( role_id IN (?) AND group_id IN (?) ) OR ( role_id is NULL AND group_id IN (?) )', role_ids, role_ids, group_ids, group_ids ) - .order( 'created_at DESC, id DESC' ) - .limit( limit ) - end + stream = if group_ids.empty? + ActivityStream.where('(role_id IN (?) AND group_id is NULL)', role_ids ) + .order( 'created_at DESC, id DESC' ) + .limit( limit ) + else + ActivityStream.where('(role_id IN (?) AND group_id is NULL) OR ( role_id IN (?) AND group_id IN (?) ) OR ( role_id is NULL AND group_id IN (?) )', role_ids, role_ids, group_ids, group_ids ) + .order( 'created_at DESC, id DESC' ) + .limit( limit ) + end list = [] stream.each do |item| data = item.attributes diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 682566de2..0218203ec 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -142,7 +142,7 @@ returns attributes = self.attributes self.class.reflect_on_all_associations.map { |assoc| real_key = assoc.name.to_s[0, assoc.name.to_s.length - 1] + '_ids' - if self.respond_to?(real_key) + if respond_to?(real_key) attributes[ real_key ] = send(real_key) end } @@ -230,7 +230,7 @@ returns end def cache_update(o) - cache_delete if self.respond_to?('cache_delete') + cache_delete if respond_to?('cache_delete') o.cache_delete if o.respond_to?('cache_delete') end @@ -241,7 +241,7 @@ returns Cache.delete(key) # delete old name / login caches - if self.changed? + if changed? if changes.key?('name') name = changes['name'][0] key = "#{self.class}::#{name}" @@ -349,9 +349,9 @@ returns end } return - else - fail 'Need name, id or login for lookup()' end + + fail 'Need name, id or login for lookup()' end =begin @@ -442,7 +442,7 @@ returns # do lookup with == to handle case insensitive databases records = where(login: data[:login]) records.each {|loop_record| - if loop_record.login.downcase == data[:login].downcase + if loop_record.login.casecmp data[:login] == 0 loop_record.update_attributes(data) return loop_record end @@ -455,7 +455,7 @@ returns # do lookup with == to handle case insensitive databases records = where(email: data[:email]) records.each {|loop_record| - if loop_record.email.downcase == data[:email].downcase + if loop_record.email.casecmp data[:email] == 0 loop_record.update_attributes(data) return loop_record end @@ -468,7 +468,7 @@ returns # do lookup with == to handle case insensitive databases records = where(locale: data[:locale]) records.each {|loop_record| - if loop_record.locale.downcase == data[:locale].downcase + if loop_record.locale.casecmp data[:locale] == 0 loop_record.update_attributes(data) return loop_record end @@ -783,7 +783,7 @@ log object update activity stream, if configured - will be executed automaticall def activity_stream_update return if !self.class.activity_stream_support_config - return if !self.changed? + return if !changed? # default ignored attributes ignore_attributes = { @@ -872,10 +872,10 @@ log object update history with all updated attributes, if configured - will be e def history_update return if !self.class.history_support_config - return if !self.changed? + return if !changed? # return if it's no update - return if self.new_record? + return if new_record? # new record also triggers update, so ignore new records changes = self.changes @@ -921,7 +921,7 @@ log object update history with all updated attributes, if configured - will be e value_id[0] = value[0] value_id[1] = value[1] - if self.respond_to?( attribute_name ) && send(attribute_name) + if respond_to?( attribute_name ) && send(attribute_name) relation_class = send(attribute_name).class if relation_class && value_id[0] relation_model = relation_class.lookup( id: value_id[0] ) diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 6c71f3c35..28c1609bd 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -344,11 +344,11 @@ returns if public_holidays_was && public_holidays_was[day] && public_holidays_was[day]['feed'] meta['feed'] = public_holidays_was[day]['feed'] end - if meta['active'] - meta['active'] = true - else - meta['active'] = false - end + meta['active'] = if meta['active'] + true + else + false + end } end diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index ce7ddbf1b..f80a8fb1b 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -40,11 +40,11 @@ module Channel::EmailBuild next if key.to_s == 'attachments' next if key.to_s == 'body' next if key.to_s == 'content_type' - if value && value.class != Array - mail[key.to_s] = value.to_s - else - mail[key.to_s] = value - end + mail[key.to_s] = if value && value.class != Array + value.to_s + else + value + end end # add html part diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 0bc41d001..9aa3e4dba 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -191,58 +191,56 @@ class Channel::EmailParser end # not multipart email - else - # text part only - if !mail.mime_type || mail.mime_type.to_s == '' || mail.mime_type.to_s.downcase == 'text/plain' + # text part only + elsif !mail.mime_type || mail.mime_type.to_s == '' || mail.mime_type.to_s.casecmp('text/plain') + data[:body] = mail.body.decoded + data[:body] = Encode.conv(mail.charset, data[:body]) + + if !data[:body].force_encoding('UTF-8').valid_encoding? + data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?') + end + + # html part only, convert ot text and add it as attachment + else + filename = '-no name-' + if mail.mime_type.to_s.casecmp('text/html') + filename = 'message.html' data[:body] = mail.body.decoded data[:body] = Encode.conv(mail.charset, data[:body]) + data[:body] = data[:body].html2text.to_s.force_encoding('utf-8') - if !data[:body].force_encoding('UTF-8').valid_encoding? + if !data[:body].valid_encoding? data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?') end - # html part only, convert ot text and add it as attachment + # any other attachments else - filename = '-no name-' - if mail.mime_type.to_s.downcase == 'text/html' - filename = 'message.html' - data[:body] = mail.body.decoded - data[:body] = Encode.conv(mail.charset, data[:body]) - data[:body] = data[:body].html2text.to_s.force_encoding('utf-8') - - if !data[:body].valid_encoding? - data[:body] = data[:body].encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '?') - end - - # any other attachments - else - data[:body] = 'no visible content' - end - - # add body as attachment - headers_store = { - 'content-alternative' => true, - } - if mail.mime_type - headers_store['Mime-Type'] = mail.mime_type - end - if mail.charset - headers_store['Charset'] = mail.charset - end - attachment = { - data: mail.body.decoded, - filename: mail.filename || filename, - preferences: headers_store - } - data[:attachments].push attachment + data[:body] = 'no visible content' end + + # add body as attachment + headers_store = { + 'content-alternative' => true, + } + if mail.mime_type + headers_store['Mime-Type'] = mail.mime_type + end + if mail.charset + headers_store['Charset'] = mail.charset + end + attachment = { + data: mail.body.decoded, + filename: mail.filename || filename, + preferences: headers_store + } + data[:attachments].push attachment end # strip not wanted chars data[:body].gsub!(/\n\r/, "\n") data[:body].gsub!(/\r\n/, "\n") - data[:body].gsub!(/\r/, "\n") + data[:body].tr!("\r", "\n") # remember original mail instance data[:mail_instance] = mail diff --git a/app/models/external_credential.rb b/app/models/external_credential.rb index 9d5c5c429..560d078fa 100644 --- a/app/models/external_credential.rb +++ b/app/models/external_credential.rb @@ -29,7 +29,7 @@ class ExternalCredential < ApplicationModel def self.load_backend(provider) adapter = "ExternalCredential::#{provider.camelcase}" - require "#{adapter.to_filename}" + require adapter.to_filename.to_s load_adapter(adapter) end diff --git a/app/models/history.rb b/app/models/history.rb index 23d499422..aca5a824b 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -153,8 +153,8 @@ returns if !related_history_object history_object = object_lookup( requested_object ) history = History.where( history_object_id: history_object.id ) - .where( o_id: requested_object_id ) - .order('created_at ASC, id ASC') + .where( o_id: requested_object_id ) + .order('created_at ASC, id ASC') else history_object_requested = object_lookup( requested_object ) history_object_related = object_lookup( related_history_object ) @@ -165,7 +165,7 @@ returns history_object_related.id, requested_object_id, ) - .order('created_at ASC, id ASC') # rubocop:disable Style/MultilineOperationIndentation + .order('created_at ASC, id ASC') end asset_list = {} list = [] diff --git a/app/models/job.rb b/app/models/job.rb index 2e0b50321..352e71972 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -43,8 +43,8 @@ class Job < ApplicationModel # find tickets to change tickets = Ticket.where( job.condition.permit! ) - .order( '`tickets`.`created_at` DESC' ) - .limit( 1_000 ) + .order( '`tickets`.`created_at` DESC' ) + .limit( 1_000 ) job.processed = tickets.count tickets.each do |ticket| logger.debug "CHANGE #{job.execute.inspect}" @@ -83,4 +83,5 @@ class Job < ApplicationModel minutes.gsub!(/(\d)\d/, '\\1') minutes.to_s + '0' end + private_class_method :match_minutes end diff --git a/app/models/observer/ticket/notification.rb b/app/models/observer/ticket/notification.rb index 0b7445e3a..9b1da9fa7 100644 --- a/app/models/observer/ticket/notification.rb +++ b/app/models/observer/ticket/notification.rb @@ -71,7 +71,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer end elsif event[:name] == 'Ticket' - ticket = Ticket.lookup( id: event[:id] ) + ticket = Ticket.lookup( id: event[:id] ) # next if ticket is already deleted next if !ticket diff --git a/app/models/observer/ticket/notification/background_job.rb b/app/models/observer/ticket/notification/background_job.rb index 7c9b3a871..4446fa5d9 100644 --- a/app/models/observer/ticket/notification/background_job.rb +++ b/app/models/observer/ticket/notification/background_job.rb @@ -6,7 +6,7 @@ class Observer::Ticket::Notification::BackgroundJob end def perform - ticket = Ticket.find(@p[:ticket_id]) + ticket = Ticket.find(@p[:ticket_id]) if @p[:article_id] article = Ticket::Article.find(@p[:article_id]) end @@ -53,11 +53,8 @@ class Observer::Ticket::Notification::BackgroundJob recipients.each do |user| # ignore user who changed it by him self - if article - next if article.updated_by_id == user.id - else - next if ticket.updated_by_id == user.id - end + next if article && article.updated_by_id == user.id + next if !article && ticket.updated_by_id == user.id # ignore inactive users next if !user.active @@ -217,11 +214,11 @@ class Observer::Ticket::Notification::BackgroundJob # set new key display = object_manager_attribute[:display].to_s end - if object_manager_attribute && object_manager_attribute[:translate] - changes[display] = ["i18n(#{value_str[0]})", "i18n(#{value_str[1]})"] - else - changes[display] = [value_str[0].to_s, value_str[1].to_s] - end + changes[display] = if object_manager_attribute && object_manager_attribute[:translate] + ["i18n(#{value_str[0]})", "i18n(#{value_str[1]})"] + else + [value_str[0].to_s, value_str[1].to_s] + end } changes end diff --git a/app/models/online_notification.rb b/app/models/online_notification.rb index 1cdd7e52b..5ec968579 100644 --- a/app/models/online_notification.rb +++ b/app/models/online_notification.rb @@ -89,8 +89,8 @@ return all online notifications of an user def self.list(user, limit) notifications = OnlineNotification.where(user_id: user.id) - .order( 'created_at DESC, id DESC' ) - .limit( limit ) + .order( 'created_at DESC, id DESC' ) + .limit( limit ) list = [] notifications.each do |item| data = item.attributes @@ -117,8 +117,8 @@ return all online notifications of an object object_lookup_id: object_id, o_id: o_id, ) - .order( 'created_at DESC, id DESC' ) # rubocop:disable Style/MultilineOperationIndentation - .limit( 10_000 ) # rubocop:disable Style/MultilineOperationIndentation + .order( 'created_at DESC, id DESC' ) + .limit( 10_000 ) notifications end diff --git a/app/models/organization.rb b/app/models/organization.rb index 7b852171f..dcdd6948f 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -11,7 +11,7 @@ class Organization < ApplicationModel has_many :members, class_name: 'User' validates :name, presence: true - activity_stream_support role: Z_ROLENAME_ADMIN + activity_stream_support role: Z_ROLENAME_ADMIN history_support search_index_support notify_clients_support diff --git a/app/models/package.rb b/app/models/package.rb index 0c0c4382d..bb1bf1da3 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -96,7 +96,7 @@ class Package < ApplicationModel def self.unlink(package_base_dir) # check if zpm is a package source repo - package = self._package_base_dir?(package_base_dir) + package = _package_base_dir?(package_base_dir) # migration down Package::Migration.migrate( package, 'reverse' ) @@ -126,7 +126,7 @@ class Package < ApplicationModel def self.link(package_base_dir) # check if zpm is a package source repo - package = self._package_base_dir?(package_base_dir) + package = _package_base_dir?(package_base_dir) # link files Dir.glob( package_base_dir + '/**/*' ) do |entry| @@ -337,13 +337,13 @@ class Package < ApplicationModel end def self._read_file(file, fullpath = false) - if fullpath == false - location = @@root + '/' + file - elsif fullpath == true - location = file - else - location = fullpath + '/' + file - end + location = if fullpath == false + @@root + '/' + file + elsif fullpath == true + file + else + fullpath + '/' + file + end begin data = File.open( location, 'rb' ) diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index 5d82fa40a..b97cb1199 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -27,8 +27,8 @@ class RecentView < ApplicationModel def self.log_destroy( requested_object, requested_object_id ) return if requested_object == 'RecentView' RecentView.where( recent_view_object_id: ObjectLookup.by_name( requested_object ) ) - .where( o_id: requested_object_id ) - .destroy_all + .where( o_id: requested_object_id ) + .destroy_all end def self.user_log_destroy( user ) @@ -36,15 +36,15 @@ class RecentView < ApplicationModel end def self.list( user, limit = 10, type = nil ) - if !type - recent_views = RecentView.where( created_by_id: user.id ) - .order('created_at DESC, id DESC') - .limit(limit) - else - recent_views = RecentView.select('DISTINCT(o_id), recent_view_object_id').where( created_by_id: user.id, recent_view_object_id: ObjectLookup.by_name(type) ) - .order('created_at DESC, id DESC') - .limit(limit) - end + recent_views = if !type + RecentView.where( created_by_id: user.id ) + .order('created_at DESC, id DESC') + .limit(limit) + else + RecentView.select('DISTINCT(o_id), recent_view_object_id').where( created_by_id: user.id, recent_view_object_id: ObjectLookup.by_name(type) ) + .order('created_at DESC, id DESC') + .limit(limit) + end list = [] recent_views.each { |item| diff --git a/app/models/setting.rb b/app/models/setting.rb index 495ba1713..2485f3d52 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -16,11 +16,11 @@ class Setting < ApplicationModel @@current = {} # rubocop:disable Style/ClassVars @@change_id = nil # rubocop:disable Style/ClassVars @@lookup_at = nil # rubocop:disable Style/ClassVars - if ENV['ZAMMAD_SETTING_TTL'] - @@lookup_timeout = ENV['ZAMMAD_SETTING_TTL'].to_i.seconds # rubocop:disable Style/ClassVars - else - @@lookup_timeout = 2.minutes # rubocop:disable Style/ClassVars - end + @@lookup_timeout = if ENV['ZAMMAD_SETTING_TTL'] # rubocop:disable Style/ClassVars + ENV['ZAMMAD_SETTING_TTL'].to_i.seconds + else + 2.minutes + end =begin @@ -118,6 +118,7 @@ reload config settings cache(config) true end + private_class_method :load # set initial value in state_initial def set_initial @@ -131,6 +132,7 @@ reload config settings logger.debug "Setting.cache: set cache, #{@@change_id}" @@lookup_at = Time.zone.now # rubocop:disable Style/ClassVars end + private_class_method :cache # reset cache def reset_cache @@ -156,6 +158,7 @@ reload config settings logger.debug "Setting.cache_valid?: cache has changed, #{@@change_id}/#{change_id}" false end + private_class_method :cache_valid? # convert state into hash to be able to store it as store def state_check diff --git a/app/models/stats_store.rb b/app/models/stats_store.rb index cd3363d3d..d3ec79bc4 100644 --- a/app/models/stats_store.rb +++ b/app/models/stats_store.rb @@ -23,7 +23,7 @@ class StatsStore < ApplicationModel end StatsStore.where(stats_store_object_id: object_id, o_id: data[:o_id], key: data[:key]) - .where('created_at > ? AND created_at < ?', data[:start], data[:end]).count + .where('created_at > ? AND created_at < ?', data[:start], data[:end]).count end =begin diff --git a/app/models/store.rb b/app/models/store.rb index e2cc3afcd..7df9d83aa 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -81,7 +81,7 @@ returns # search store_object_id = Store::Object.lookup( name: data[:object] ) stores = Store.where( store_object_id: store_object_id, o_id: data[:o_id].to_i ) - .order('created_at ASC, id ASC') + .order('created_at ASC, id ASC') stores end @@ -104,8 +104,8 @@ returns # search store_object_id = Store::Object.lookup( name: data[:object] ) stores = Store.where( store_object_id: store_object_id ) - .where( o_id: data[:o_id] ) - .order('created_at ASC, id ASC') + .where( o_id: data[:o_id] ) + .order('created_at ASC, id ASC') stores.each do |store| # check backend for references diff --git a/app/models/store/file.rb b/app/models/store/file.rb index b6cbe04e1..f294ea02a 100644 --- a/app/models/store/file.rb +++ b/app/models/store/file.rb @@ -46,12 +46,12 @@ read content of a file def content adapter = self.class.load_adapter("Store::Provider::#{provider}") - if sha - c = adapter.get( sha ) - else - # fallback until migration is done - c = Store::Provider::DB.find_by( md5: md5 ).data - end + c = if sha + adapter.get( sha ) + else + # fallback until migration is done + Store::Provider::DB.find_by( md5: md5 ).data + end c end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 0224277f2..389f4a6e1 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -103,16 +103,16 @@ returns access_condition = [] if user.role?(Z_ROLENAME_AGENT) group_ids = Group.select( 'groups.id' ).joins(:users) - .where( 'groups_users.user_id = ?', user.id ) - .where( 'groups.active = ?', true ) - .map( &:id ) + .where( 'groups_users.user_id = ?', user.id ) + .where( 'groups.active = ?', true ) + .map( &:id ) access_condition = [ 'group_id IN (?)', group_ids ] else - if !user.organization || ( !user.organization.shared || user.organization.shared == false ) - access_condition = [ 'tickets.customer_id = ?', user.id ] - else - access_condition = [ '( tickets.customer_id = ? OR tickets.organization_id = ? )', user.id, user.organization.id ] - end + access_condition = if !user.organization || ( !user.organization.shared || user.organization.shared == false ) + [ 'tickets.customer_id = ?', user.id ] + else + [ '( tickets.customer_id = ? OR tickets.organization_id = ? )', user.id, user.organization.id ] + end end access_condition end @@ -134,7 +134,7 @@ returns ticket_states = Ticket::State.where( state_type_id: Ticket::StateType.find_by( name: 'pending action' ), ) - .where.not(next_state_id: nil) # rubocop:disable Style/MultilineOperationIndentation + .where.not(next_state_id: nil) return [] if !ticket_states @@ -146,7 +146,7 @@ returns tickets = where( state_id: next_state_map.keys, ) - .where( 'pending_time <= ?', Time.zone.now ) # rubocop:disable Style/MultilineOperationIndentation + .where( 'pending_time <= ?', Time.zone.now ) return [] if !tickets diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index 66096a282..b72848835 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -49,12 +49,12 @@ class Ticket::Article < ApplicationModel end class Sender < ApplicationModel - validates :name, presence: true + validates :name, presence: true latest_change_support end class Type < ApplicationModel - validates :name, presence: true + validates :name, presence: true latest_change_support end end diff --git a/app/models/ticket/escalation.rb b/app/models/ticket/escalation.rb index 38a79cde6..bb43f77f8 100644 --- a/app/models/ticket/escalation.rb +++ b/app/models/ticket/escalation.rb @@ -171,10 +171,8 @@ returns # get close time in min if close_time self.close_time_in_min = pending_minutes(created_at, close_time, biz, 'business_minutes') - else - if close_time_escal_date && ((!escalation_time && close_time_escal_date) || close_time_escal_date < escalation_time) - self.escalation_time = close_time_escal_date - end + elsif close_time_escal_date && ((!escalation_time && close_time_escal_date) || close_time_escal_date < escalation_time) + self.escalation_time = close_time_escal_date end # set time to show if sla is raised or not @@ -186,7 +184,7 @@ returns self.escalation_time = nil end - return if !self.changed? + return if !changed? self.callback_loop = true save @@ -279,11 +277,11 @@ returns end total_time_in_min = total_time_in_min + diff - if history_item['value_to'] == 'pending reminder' - last_state_is_pending = true - else - last_state_is_pending = false - end + last_state_is_pending = if history_item['value_to'] == 'pending reminder' + true + else + false + end # remember for next loop last state last_state = history_item['value_to'] diff --git a/app/models/ticket/number/date.rb b/app/models/ticket/number/date.rb index 42f0ef8c3..48884dc2f 100644 --- a/app/models/ticket/number/date.rb +++ b/app/models/ticket/number/date.rb @@ -20,11 +20,11 @@ module Ticket::Number::Date # increase counter counter_increment, date_file = counter.content.to_s.split(';') - if date_file == date - counter_increment = counter_increment.to_i + 1 - else - counter_increment = 1 - end + counter_increment = if date_file == date + counter_increment.to_i + 1 + else + 1 + end # store new counter value counter.content = counter_increment.to_s + ';' + date diff --git a/app/models/ticket/number/increment.rb b/app/models/ticket/number/increment.rb index 9f1b97650..31f464ba9 100644 --- a/app/models/ticket/number/increment.rb +++ b/app/models/ticket/number/increment.rb @@ -9,7 +9,7 @@ module Ticket::Number::Increment config = Setting.get('ticket_number_increment') # read counter - min_digs = config[:min_size] || 4 + min_digs = config[:min_size] || 4 counter_increment = nil Ticket::Counter.transaction do counter = Ticket::Counter.where( generator: 'Increment' ).lock(true).first diff --git a/app/models/ticket/overviews.rb b/app/models/ticket/overviews.rb index d7d12c8f1..16a6623f6 100644 --- a/app/models/ticket/overviews.rb +++ b/app/models/ticket/overviews.rb @@ -20,11 +20,11 @@ returns # get customer overviews if data[:current_user].role?('Customer') role = Role.find_by( name: 'Customer' ) - if data[:current_user].organization_id && data[:current_user].organization.shared - overviews = Overview.where( role_id: role.id, active: true ) - else - overviews = Overview.where( role_id: role.id, organization_shared: false, active: true ) - end + overviews = if data[:current_user].organization_id && data[:current_user].organization.shared + Overview.where( role_id: role.id, active: true ) + else + Overview.where( role_id: role.id, organization_shared: false, active: true ) + end return overviews end @@ -113,10 +113,10 @@ returns query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user]) tickets = Ticket.select('id') - .where( access_condition ) - .where( query_condition, *bind_condition ) - .order( order_by ) - .limit( 500 ) + .where( access_condition ) + .where( query_condition, *bind_condition ) + .order( order_by ) + .limit( 500 ) ticket_ids = [] tickets.each { |ticket| @@ -136,8 +136,8 @@ returns data[:start_page] ||= 1 query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user]) tickets = Ticket.where( access_condition ) - .where( query_condition, *bind_condition ) - .order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ) + .where( query_condition, *bind_condition ) + .order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s ) tickets_count = Ticket.where( access_condition ).where( query_condition, *bind_condition ).count() diff --git a/app/models/ticket/priority.rb b/app/models/ticket/priority.rb index dd829a162..8bf23b74a 100644 --- a/app/models/ticket/priority.rb +++ b/app/models/ticket/priority.rb @@ -1,5 +1,5 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ class Ticket::Priority < ApplicationModel self.table_name = 'ticket_priorities' - validates :name, presence: true + validates :name, presence: true end diff --git a/app/models/ticket/search.rb b/app/models/ticket/search.rb index 0fc1943c3..6357dde42 100644 --- a/app/models/ticket/search.rb +++ b/app/models/ticket/search.rb @@ -104,8 +104,8 @@ returns if current_user.role?('Agent') groups = Group.joins(:users) - .where( 'groups_users.user_id = ?', current_user.id ) - .where( 'groups.active = ?', true ) + .where( 'groups_users.user_id = ?', current_user.id ) + .where( 'groups.active = ?', true ) group_condition = [] groups.each {|group| group_condition.push group.name @@ -113,24 +113,24 @@ returns access_condition = { 'query_string' => { 'default_field' => 'Ticket.group.name', 'query' => "\"#{group_condition.join('" OR "')}\"" } } - query_extention['bool']['must'].push access_condition else - if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false ) - access_condition = { - 'query_string' => { 'default_field' => 'Ticket.customer_id', 'query' => current_user.id } - } - # customer_id: XXX - # conditions = [ 'customer_id = ?', current_user.id ] - else - access_condition = { - 'query_string' => { 'query' => "Ticket.customer_id:#{current_user.id} OR Ticket.organization_id:#{current_user.organization.id}" } - } - # customer_id: XXX OR organization_id: XXX - # conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ] - end - query_extention['bool']['must'].push access_condition + access_condition = if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false ) + { + 'query_string' => { 'default_field' => 'Ticket.customer_id', 'query' => current_user.id } + } + # customer_id: XXX + # conditions = [ 'customer_id = ?', current_user.id ] + else + { + 'query_string' => { 'query' => "Ticket.customer_id:#{current_user.id} OR Ticket.organization_id:#{current_user.organization.id}" } + } + # customer_id: XXX OR organization_id: XXX + # conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ] + end end + query_extention['bool']['must'].push access_condition + items = SearchIndexBackend.search( query, limit, 'Ticket', query_extention ) if !full ids = [] @@ -154,18 +154,18 @@ returns if query query.delete! '*' tickets_all = Ticket.select('DISTINCT(tickets.id)') - .where(access_condition) - .where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ) - .joins(:articles) - .order('`tickets`.`created_at` DESC') - .limit(limit) + .where(access_condition) + .where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ) + .joins(:articles) + .order('`tickets`.`created_at` DESC') + .limit(limit) else query_condition, bind_condition = selector2sql(params[:condition]) tickets_all = Ticket.select('DISTINCT(tickets.id)') - .where(access_condition) - .where(query_condition, *bind_condition) - .order('`tickets`.`created_at` DESC') - .limit(limit) + .where(access_condition) + .where(query_condition, *bind_condition) + .order('`tickets`.`created_at` DESC') + .limit(limit) end # build result list diff --git a/app/models/translation.rb b/app/models/translation.rb index 990def1cc..70b0b5b48 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -175,30 +175,30 @@ get list of translations 'total' => Translation.where(locale: 'de-de').count, } list = [] - if admin - translations = Translation.where(locale: locale.downcase).order(:source) - else - translations = Translation.where(locale: locale.downcase).where.not(target: '').order(:source) - end + translations = if admin + Translation.where(locale: locale.downcase).order(:source) + else + Translation.where(locale: locale.downcase).where.not(target: '').order(:source) + end translations.each { |item| - if admin - translation_item = [ - item.id, - item.source, - item.target, - item.target_initial, - item.format, - ] - list.push translation_item - else - translation_item = [ - item.id, - item.source, - item.target, - item.format, - ] - list.push translation_item - end + translation_item = [] + translation_item = if admin + [ + item.id, + item.source, + item.target, + item.target_initial, + item.format, + ] + else + [ + item.id, + item.source, + item.target, + item.format, + ] + end + list.push translation_item } data['list'] = list @@ -250,8 +250,10 @@ translate strings in ruby context, e. g. for notifications def self.cache_set(locale, data) Cache.write('TranslationMapOnlyContent::' + locale.downcase, data) end + private_class_method :cache_set def self.cache_get(locale) Cache.get('TranslationMapOnlyContent::' + locale.downcase) end + private_class_method :cache_get end diff --git a/app/models/user.rb b/app/models/user.rb index 83a4be3c6..8efeee896 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -124,8 +124,8 @@ returns roles.each { |role| if role_name.class == Array next if !role_name.include?(role.name) - else - next if role.name != role_name + elsif role.name != role_name + next end result = true break diff --git a/app/models/user/search.rb b/app/models/user/search.rb index 7d6c6daf0..74734f677 100644 --- a/app/models/user/search.rb +++ b/app/models/user/search.rb @@ -69,15 +69,15 @@ returns # fallback do sql query # - stip out * we already search for *query* - query.delete! '*' - if params[:role_ids] - users = User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where( - '(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" - ).order('firstname').limit(limit) - else - users = User.where( - '(firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR login LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" - ).order('firstname').limit(limit) - end + users = if params[:role_ids] + User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where( + '(users.firstname LIKE ? OR users.lastname LIKE ? OR users.email LIKE ? OR users.login LIKE ?) AND users.id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" + ).order('firstname').limit(limit) + else + User.where( + '(firstname LIKE ? OR lastname LIKE ? OR email LIKE ? OR login LIKE ?) AND id != 1', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" + ).order('firstname').limit(limit) + end users end end diff --git a/config/initializers/core_zammad_constants.rb b/config/initializers/core_zammad_constants.rb index 6df36f534..be6355374 100644 --- a/config/initializers/core_zammad_constants.rb +++ b/config/initializers/core_zammad_constants.rb @@ -3,6 +3,6 @@ # Prefix all zammad constants w/ Z_ # Prefix all rolenames with Z_ROLENAME -Z_ROLENAME_ADMIN = 'Admin' -Z_ROLENAME_AGENT = 'Agent' -Z_ROLENAME_CUSTOMER = 'Customer' +Z_ROLENAME_ADMIN = 'Admin'.freeze +Z_ROLENAME_AGENT = 'Agent'.freeze +Z_ROLENAME_CUSTOMER = 'Customer'.freeze diff --git a/db/migrate/20120101000001_create_base.rb b/db/migrate/20120101000001_create_base.rb index 099a36522..0d0614c2b 100644 --- a/db/migrate/20120101000001_create_base.rb +++ b/db/migrate/20120101000001_create_base.rb @@ -5,7 +5,7 @@ class CreateBase < ActiveRecord::Migration t.string :session_id, null: false t.boolean :persistent, null: true t.text :data - t.timestamps null: false + t.timestamps null: false end add_index :sessions, :session_id add_index :sessions, :updated_at @@ -465,7 +465,7 @@ class CreateBase < ActiveRecord::Migration t.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) t.string :locked_by # Who is working on this object (if locked) t.string :queue # The name of the queue this job is in - t.timestamps null: false + t.timestamps null: false end add_index :delayed_jobs, [:priority, :run_at], name: 'delayed_jobs_priority' diff --git a/db/migrate/20151015000001_create_macro.rb b/db/migrate/20151015000001_create_macro.rb index acf62ad96..c0fd77c10 100644 --- a/db/migrate/20151015000001_create_macro.rb +++ b/db/migrate/20151015000001_create_macro.rb @@ -18,10 +18,10 @@ class CreateMacro < ActiveRecord::Migration Macro.create_or_update( name: 'Close & Tag as Spam', perform: { - 'ticket.state_id': { + 'ticket.state_id' => { value: Ticket::State.find_by(name: 'closed').id, }, - 'ticket.tags': { + 'ticket.tags' => { operator: 'add', value: 'spam', }, diff --git a/db/seeds.rb b/db/seeds.rb index d5aebaf67..7de9ef463 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1644,10 +1644,10 @@ Ticket::Article::Sender.create_if_not_exists( id: 3, name: 'System' ) Macro.create_if_not_exists( name: 'Close & Tag as Spam', perform: { - 'ticket.state_id': { + 'ticket.state_id' => { value: Ticket::State.find_by(name: 'closed').id, }, - 'ticket.tags': { + 'ticket.tags' => { operator: 'add', value: 'spam', }, diff --git a/lib/auto_wizard.rb b/lib/auto_wizard.rb index 42dd0d5bc..7e3adf04f 100644 --- a/lib/auto_wizard.rb +++ b/lib/auto_wizard.rb @@ -147,11 +147,10 @@ returns admin_user end - private - def self.file_location auto_wizard_file_name = 'auto_wizard.json' auto_wizard_file_location = "#{Rails.root}/#{auto_wizard_file_name}" auto_wizard_file_location end + private_class_method :file_location end diff --git a/lib/core_ext/class.rb b/lib/core_ext/class.rb index 6ab38d7e8..f46fcee9c 100644 --- a/lib/core_ext/class.rb +++ b/lib/core_ext/class.rb @@ -2,10 +2,10 @@ class Class def to_app_model_url camel_cased_word = to_s camel_cased_word.gsub(/::/, '_') - .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') - .gsub(/([a-z\d])([A-Z])/, '\1_\2') - .tr('-', '_') - .downcase + .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') + .tr('-', '_') + .downcase end def to_app_model diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb index 2a09a154f..68f611e86 100644 --- a/lib/core_ext/string.rb +++ b/lib/core_ext/string.rb @@ -31,11 +31,11 @@ class String =end def to_filename - camel_cased_word = "#{self}" + camel_cased_word = to_s camel_cased_word.gsub(/::/, '/') - .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') - .gsub(/([a-z\d])([A-Z])/, '\1_\2') - .tr('-', '_').downcase + .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') + .tr('-', '_').downcase end =begin @@ -48,7 +48,7 @@ class String =end def to_classname - camel_cased_word = "#{self}" + camel_cased_word = to_s camel_cased_word.gsub!(/\.rb$/, '') camel_cased_word.split('/').map(&:camelize).join('::') end @@ -65,7 +65,7 @@ class String end c } - .join('') # rubocop:disable Style/MultilineOperationIndentation + .join('') end =begin @@ -79,7 +79,7 @@ class String =end def html2text(string_only = false) - string = "#{self}" + string = to_s # in case of invalid encodeing, strip invalid chars # see also test/fixtures/mail21.box @@ -94,7 +94,7 @@ class String if !string_only string.gsub!( //ix ) { link = $2 - counter = counter + 1 + counter = counter + 1 link_list += "[#{counter}] #{link}\n" "[#{counter}] " } diff --git a/lib/email_helper/probe.rb b/lib/email_helper/probe.rb index 9b9df6efc..00da2856a 100644 --- a/lib/email_helper/probe.rb +++ b/lib/email_helper/probe.rb @@ -280,21 +280,21 @@ returns on fail end # prepare test email - if subject - mail = { - from: email, - to: email, - subject: "Zammad Getting started Test Email #{subject}", - body: "This is a Test Email of Zammad to check if sending and receiving is working correctly.\n\nYou can ignore or delete this email.", - } - else - mail = { - from: email, - to: 'emailtrytest@znuny.com', - subject: 'This is a Test Email', - body: "This is a Test Email of Zammad to verify if Zammad can send emails to an external address.\n\nIf you see this email, you can ignore and delete it.", - } - end + mail = if subject + { + from: email, + to: email, + subject: "Zammad Getting started Test Email #{subject}", + body: "This is a Test Email of Zammad to check if sending and receiving is working correctly.\n\nYou can ignore or delete this email.", + } + else + { + from: email, + to: 'emailtrytest@znuny.com', + subject: 'This is a Test Email', + body: "This is a Test Email of Zammad to verify if Zammad can send emails to an external address.\n\nIf you see this email, you can ignore and delete it.", + } + end if subject mail['X-Zammad-Test-Message'] = subject end diff --git a/lib/email_helper/verify.rb b/lib/email_helper/verify.rb index 888009435..cd97609bc 100644 --- a/lib/email_helper/verify.rb +++ b/lib/email_helper/verify.rb @@ -56,11 +56,11 @@ or def self.email(params) # send verify email - if !params[:subject] || params[:subject].empty? - subject = '#' + rand(99_999_999_999).to_s - else - subject = params[:subject] - end + subject = if !params[:subject] || params[:subject].empty? + '#' + rand(99_999_999_999).to_s + else + params[:subject] + end result = EmailHelper::Probe.outbound(params[:outbound], params[:sender], subject) if result[:result] != 'ok' result[:source] = 'outbound' diff --git a/lib/encode.rb b/lib/encode.rb index 31899d8af..be484c50c 100644 --- a/lib/encode.rb +++ b/lib/encode.rb @@ -11,7 +11,7 @@ module Encode end # validate already existing utf8 strings - if charset.downcase == 'utf8' || charset.downcase == 'utf-8' + if charset.casecmp('utf8') || charset.casecmp('utf-8') begin # return if encoding is valid diff --git a/lib/fill_db.rb b/lib/fill_db.rb index 2862d7581..d7f21120d 100644 --- a/lib/fill_db.rb +++ b/lib/fill_db.rb @@ -44,7 +44,7 @@ e. g. # create agents agent_pool = [] if agents && !agents.zero? - roles = Role.where( name: [ 'Agent'] ) + roles = Role.where( name: [ 'Agent'] ) groups_all = Group.all ActiveRecord::Base.transaction do @@ -73,7 +73,7 @@ e. g. # create customer customer_pool = [] if customers && !customers.zero? - roles = Role.where( name: [ 'Customer'] ) + roles = Role.where( name: [ 'Customer'] ) groups_all = Group.all ActiveRecord::Base.transaction do diff --git a/lib/http/uri.rb b/lib/http/uri.rb index f5aef9d77..a2f8e3822 100644 --- a/lib/http/uri.rb +++ b/lib/http/uri.rb @@ -1,6 +1,6 @@ # Monkey-patch HTTP::URI class HTTP::URI def port - 443 if self.https? + 443 if https? end end diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index b3e33d754..9a6f68b41 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -609,22 +609,22 @@ module Import::OTRS # find owner if ticket_new[:owner] user = User.lookup( login: ticket_new[:owner].downcase ) - if user - ticket_new[:owner_id] = user.id - else - ticket_new[:owner_id] = 1 - end + ticket_new[:owner_id] = if user + user.id + else + 1 + end ticket_new.delete(:owner) end # find customer if ticket_new[:customer] user = User.lookup( login: ticket_new[:customer].downcase ) - if user - ticket_new[:customer_id] = user.id - else - ticket_new[:customer_id] = 1 - end + ticket_new[:customer_id] = if user + user.id + else + 1 + end ticket_new.delete(:customer) else ticket_new[:customer_id] = 1 @@ -1345,19 +1345,19 @@ module Import::OTRS def self._set_valid(record) # map - if record['ValidID'].to_s == '3' - record['ValidID'] = false - elsif record['ValidID'].to_s == '2' - record['ValidID'] = false - elsif record['ValidID'].to_s == '1' - record['ValidID'] = true - elsif record['ValidID'].to_s == '0' - record['ValidID'] = false + record['ValidID'] = if record['ValidID'].to_s == '3' + false + elsif record['ValidID'].to_s == '2' + false + elsif record['ValidID'].to_s == '1' + true + elsif record['ValidID'].to_s == '0' + false - # fallback - else - record['ValidID'] = true - end + # fallback + else + true + end end # cleanup invalid values diff --git a/lib/import/zendesk.rb b/lib/import/zendesk.rb index fdb6e37ad..c6702394c 100644 --- a/lib/import/zendesk.rb +++ b/lib/import/zendesk.rb @@ -192,11 +192,11 @@ module Import::Zendesk def import_field(local_object, zendesk_field) name = '' - if local_object == 'Ticket' - name = zendesk_field.title - else - name = zendesk_field['key'] # TODO: y?! - end + name = if local_object == 'Ticket' + zendesk_field.title + else + zendesk_field['key'] # TODO: y?! + end @zendesk_ticket_field_mapping ||= {} @zendesk_ticket_field_mapping[ zendesk_field.id ] = name @@ -512,13 +512,13 @@ module Import::Zendesk ticket_author = User.find( @zendesk_user_mapping[ zendesk_ticket.requester_id ] ) - if ticket_author.role?('Customer') - local_ticket_fields[:create_article_sender_id] = article_sender_customer.id - elsif ticket_author.role?('Agent') - local_ticket_fields[:create_article_sender_id] = article_sender_agent.id - else - local_ticket_fields[:create_article_sender_id] = article_sender_system.id - end + local_ticket_fields[:create_article_sender_id] = if ticket_author.role?('Customer') + article_sender_customer.id + elsif ticket_author.role?('Agent') + article_sender_agent.id + else + article_sender_system.id + end # TODO: zendesk_ticket.external_id ? if zendesk_ticket.via.channel == 'web' @@ -530,20 +530,20 @@ module Import::Zendesk elsif zendesk_ticket.via.channel == 'twitter' # TODO - if zendesk_ticket.via.source.rel == 'mention' - local_ticket_fields[:create_article_type_id] = article_type_twitter_status.id - else - local_ticket_fields[:create_article_type_id] = article_type_twitter_dm.id - end + local_ticket_fields[:create_article_type_id] = if zendesk_ticket.via.source.rel == 'mention' + article_type_twitter_status.id + else + article_type_twitter_dm.id + end elsif zendesk_ticket.via.channel == 'facebook' # TODO - if zendesk_ticket.via.source.rel == 'post' - local_ticket_fields[:create_article_type_id] = article_type_facebook_feed_post.id - else - local_ticket_fields[:create_article_type_id] = article_type_facebook_feed_comment.id - end + local_ticket_fields[:create_article_type_id] = if zendesk_ticket.via.source.rel == 'post' + article_type_facebook_feed_post.id + else + article_type_facebook_feed_comment.id + end end local_ticket = Ticket.create( local_ticket_fields ) @@ -587,13 +587,13 @@ module Import::Zendesk article_author = User.find( @zendesk_user_mapping[ zendesk_article.author_id ] ) - if article_author.role?('Customer') - local_article_fields[:sender_id] = article_sender_customer.id - elsif article_author.role?('Agent') - local_article_fields[:sender_id] = article_sender_agent.id - else - local_article_fields[:sender_id] = article_sender_system.id - end + local_article_fields[:sender_id] = if article_author.role?('Customer') + article_sender_customer.id + elsif article_author.role?('Agent') + article_sender_agent.id + else + article_sender_system.id + end if zendesk_article.via.channel == 'web' local_article_fields[:message_id] = zendesk_article.id @@ -610,11 +610,11 @@ module Import::Zendesk local_article_fields[:message_id] = zendesk_article.id # TODO - if zendesk_article.via.source.rel == 'mention' - local_article_fields[:type_id] = article_type_twitter_status.id - else - local_article_fields[:type_id] = article_type_twitter_dm.id - end + local_article_fields[:type_id] = if zendesk_article.via.source.rel == 'mention' + article_type_twitter_status.id + else + article_type_twitter_dm.id + end elsif zendesk_article.via.channel == 'facebook' @@ -623,11 +623,11 @@ module Import::Zendesk local_article_fields[:message_id] = zendesk_article.id # TODO - if zendesk_article.via.source.rel == 'post' - local_article_fields[:type_id] = article_type_facebook_feed_post.id - else - local_article_fields[:type_id] = article_type_facebook_feed_comment.id - end + local_article_fields[:type_id] = if zendesk_article.via.source.rel == 'post' + article_type_facebook_feed_post.id + else + article_type_facebook_feed_comment.id + end end # create article diff --git a/lib/notification_factory.rb b/lib/notification_factory.rb index c9cd3ff1b..e393330bb 100644 --- a/lib/notification_factory.rb +++ b/lib/notification_factory.rb @@ -70,11 +70,11 @@ module NotificationFactory object_refs = object_refs.html2text.chomp } - if !value - placeholder = object_refs - else - placeholder = value - end + placeholder = if !value + object_refs + else + value + end end end placeholder diff --git a/lib/report/article_by_type_sender.rb b/lib/report/article_by_type_sender.rb index 5c16fbfda..01520e357 100644 --- a/lib/report/article_by_type_sender.rb +++ b/lib/report/article_by_type_sender.rb @@ -59,14 +59,14 @@ returns sender = Ticket::Article::Sender.lookup( name: params[:params][:sender] ) type = Ticket::Article::Type.lookup( name: params[:params][:type] ) count = Ticket::Article.joins('INNER JOIN tickets ON tickets.id = ticket_articles.ticket_id') - .where(query, *bind_params).joins(tables) - .where( - 'ticket_articles.created_at >= ? AND ticket_articles.created_at <= ? AND ticket_articles.type_id = ? AND ticket_articles.sender_id = ?', - start, - stop, - type.id, - sender.id, - ).count + .where(query, *bind_params).joins(tables) + .where( + 'ticket_articles.created_at >= ? AND ticket_articles.created_at <= ? AND ticket_articles.type_id = ? AND ticket_articles.sender_id = ?', + start, + stop, + type.id, + sender.id, + ).count result.push count start = stop } diff --git a/lib/report/base.rb b/lib/report/base.rb index b0b1c51dc..cdeb7457d 100644 --- a/lib/report/base.rb +++ b/lib/report/base.rb @@ -21,10 +21,10 @@ class Report::Base if params[:type] == 'created' history_type = History::Type.lookup( name: 'created' ) return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ?', params[:start], params[:end], history_object.id, history_type.id - ) - .where(query, *bind_params).joins(tables).count + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ?', params[:start], params[:end], history_object.id, history_type.id + ) + .where(query, *bind_params).joins(tables).count end # updated @@ -33,74 +33,72 @@ class Report::Base history_attribute = History::Attribute.lookup( name: params[:attribute] ) if !history_attribute || !history_type count = 0 - else - if params[:id_not_from] && params[:id_to] - return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where(query, *bind_params).joins(tables) - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from NOT IN (?) AND histories.id_to IN (?)', - params[:start], - params[:end], - history_object.id, - history_type.id, - history_attribute.id, - params[:id_not_from], - params[:id_to], - ).count - elsif params[:id_from] && params[:id_not_to] - return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where(query, *bind_params).joins(tables) - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from IN (?) AND histories.id_to NOT IN (?)', - params[:start], - params[:end], - history_object.id, - history_type.id, - history_attribute.id, - params[:id_from], - params[:id_not_to], - ).count - elsif params[:value_from] && params[:value_not_to] - return History.joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where(query, *bind_params).joins(tables) - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_from IN (?) AND histories.value_to NOT IN (?)', - params[:start], - params[:end], - history_object.id, - history_type.id, - history_attribute.id, - params[:value_from], - params[:value_not_to], - ).count - elsif params[:value_to] - return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where(query, *bind_params).joins(tables) - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_to IN (?)', - params[:start], - params[:end], - history_object.id, - history_type.id, - history_attribute.id, - params[:value_to], - ).count - elsif params[:id_to] - return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where(query, *bind_params).joins(tables) - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_to IN (?)', - params[:start], - params[:end], - history_object.id, - history_type.id, - history_attribute.id, - params[:id_to], - ).count - else - fail "UNKOWN params (#{params.inspect})!" - end + elsif params[:id_not_from] && params[:id_to] + return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') + .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from NOT IN (?) AND histories.id_to IN (?)', + params[:start], + params[:end], + history_object.id, + history_type.id, + history_attribute.id, + params[:id_not_from], + params[:id_to], + ).count + elsif params[:id_from] && params[:id_not_to] + return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') + .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from IN (?) AND histories.id_to NOT IN (?)', + params[:start], + params[:end], + history_object.id, + history_type.id, + history_attribute.id, + params[:id_from], + params[:id_not_to], + ).count + elsif params[:value_from] && params[:value_not_to] + return History.joins('INNER JOIN tickets ON tickets.id = histories.o_id') + .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_from IN (?) AND histories.value_to NOT IN (?)', + params[:start], + params[:end], + history_object.id, + history_type.id, + history_attribute.id, + params[:value_from], + params[:value_not_to], + ).count + elsif params[:value_to] + return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') + .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_to IN (?)', + params[:start], + params[:end], + history_object.id, + history_type.id, + history_attribute.id, + params[:value_to], + ).count + elsif params[:id_to] + return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') + .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_to IN (?)', + params[:start], + params[:end], + history_object.id, + history_type.id, + history_attribute.id, + params[:id_to], + ).count end + + fail "UNKOWN params (#{params.inspect})!" end fail "UNKOWN :type (#{params[:type]})!" end @@ -126,10 +124,10 @@ class Report::Base if data[:type] == 'created' history_type = History::Type.lookup( name: 'created' ) histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ?', data[:start], data[:end], history_object.id, history_type.id - ) - .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ?', data[:start], data[:end], history_object.id, history_type.id + ) + .where(query, *bind_params).joins(tables) histories.each {|history| count += 1 ticket_ids.push history.o_id @@ -149,67 +147,67 @@ class Report::Base else if data[:id_not_from] && data[:id_to] histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where(query, *bind_params).joins(tables) - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from NOT IN (?) AND histories.id_to IN (?)', - data[:start], - data[:end], - history_object.id, - history_type.id, - history_attribute.id, - data[:id_not_from], - data[:id_to], - ) + .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from NOT IN (?) AND histories.id_to IN (?)', + data[:start], + data[:end], + history_object.id, + history_type.id, + history_attribute.id, + data[:id_not_from], + data[:id_to], + ) elsif data[:id_from] && data[:id_not_to] histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where(query, *bind_params).joins(tables) - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from IN (?) AND histories.id_to NOT IN (?)', - data[:start], - data[:end], - history_object.id, - history_type.id, - history_attribute.id, - data[:id_from], - data[:id_not_to], - ) + .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from IN (?) AND histories.id_to NOT IN (?)', + data[:start], + data[:end], + history_object.id, + history_type.id, + history_attribute.id, + data[:id_from], + data[:id_not_to], + ) elsif data[:value_from] && data[:value_not_to] histories = History.joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where(query, *bind_params).joins(tables) - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_from IN (?) AND histories.value_to NOT IN (?)', - data[:start], - data[:end], - history_object.id, - history_type.id, - history_attribute.id, - data[:value_from], - data[:value_not_to], - ) + .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_from IN (?) AND histories.value_to NOT IN (?)', + data[:start], + data[:end], + history_object.id, + history_type.id, + history_attribute.id, + data[:value_from], + data[:value_not_to], + ) elsif data[:value_to] histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where(query, *bind_params).joins(tables) - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_to IN (?)', - data[:start], - data[:end], - history_object.id, - history_type.id, - history_attribute.id, - data[:value_to], - ) + .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_to IN (?)', + data[:start], + data[:end], + history_object.id, + history_type.id, + history_attribute.id, + data[:value_to], + ) elsif data[:id_to] histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id') - .where(query, *bind_params).joins(tables) - .where( - 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_to IN (?)', - data[:start], - data[:end], - history_object.id, - history_type.id, - history_attribute.id, - data[:id_to], - ) + .where(query, *bind_params).joins(tables) + .where( + 'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_to IN (?)', + data[:start], + data[:end], + history_object.id, + history_type.id, + history_attribute.id, + data[:id_to], + ) end histories.each {|history| count += 1 @@ -231,7 +229,7 @@ class Report::Base def self.time_average(data) query, bind_params, tables = Ticket.selector2sql(data[:condition]) ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] ) - .where(query, *bind_params).joins(tables) + .where(query, *bind_params).joins(tables) tickets = 0 time_total = 0 ticket_list.each {|ticket| @@ -262,7 +260,7 @@ class Report::Base def self.time_min(data) query, bind_params, tables = Ticket.selector2sql(data[:condition]) ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] ) - .where(query, *bind_params).joins(tables) + .where(query, *bind_params).joins(tables) tickets = 0 time_min = 0 ticket_ids = [] @@ -281,11 +279,11 @@ class Report::Base time_min = diff end } - if time_min == 0 - tickets = -0.001 - else - tickets = (time_min / 60).to_i - end + tickets = if time_min == 0 + -0.001 + else + (time_min / 60).to_i + end { count: tickets, ticket_ids: ticket_ids, @@ -299,7 +297,7 @@ class Report::Base def self.time_max(data) query, bind_params, tables = Ticket.selector2sql(data[:condition]) ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] ) - .where(query, *bind_params).joins(tables) + .where(query, *bind_params).joins(tables) tickets = 0 time_max = 0 ticket_ids = [] @@ -319,11 +317,11 @@ class Report::Base time_max = diff end } - if time_max == 0 - tickets = -0.001 - else - tickets = (time_max / 60).to_i - end + tickets = if time_max == 0 + -0.001 + else + (time_max / 60).to_i + end { count: tickets, ticket_ids: ticket_ids, diff --git a/lib/search_index_backend.rb b/lib/search_index_backend.rb index 175bab482..6b417d55a 100644 --- a/lib/search_index_backend.rb +++ b/lib/search_index_backend.rb @@ -155,27 +155,27 @@ return search result url = build_url() return if !url - if index - if index.class == Array - url += "/#{index.join(',')}/_search" - else - url += "/#{index}/_search" - end - else - url += '/_search' - end + url += if index + if index.class == Array + "/#{index.join(',')}/_search" + else + "/#{index}/_search" + end + else + '/_search' + end data = {} data['from'] = 0 data['size'] = limit data['sort'] = - [ - { - updated_at: { - order: 'desc' - } - }, - '_score' - ] + [ + { + updated_at: { + order: 'desc' + } + }, + '_score' + ] data['query'] = query_extention || {} if !data['query']['bool'] @@ -274,15 +274,15 @@ get count of tickets and tickets which match on selector url = build_url() return if !url - if index - if index.class == Array - url += "/#{index.join(',')}/_search" - else - url += "/#{index}/_search" - end - else - url += '/_search' - end + url += if index + if index.class == Array + "/#{index.join(',')}/_search" + else + "/#{index}/_search" + end + else + '/_search' + end data = selector2query(selectors, current_user, aggs_interval, limit) @@ -444,15 +444,15 @@ return true if backend is configured return if !SearchIndexBackend.enabled? index = Setting.get('es_index').to_s + "_#{Rails.env}" url = Setting.get('es_url') - if type - if o_id - url = "#{url}/#{index}/#{type}/#{o_id}" - else - url = "#{url}/#{index}/#{type}" - end - else - url = "#{url}/#{index}" - end + url = if type + if o_id + "#{url}/#{index}/#{type}/#{o_id}" + else + "#{url}/#{index}/#{type}" + end + else + "#{url}/#{index}" + end url end diff --git a/lib/service/geo_calendar/zammad.rb b/lib/service/geo_calendar/zammad.rb index 3df78e7f1..1e325d9b4 100644 --- a/lib/service/geo_calendar/zammad.rb +++ b/lib/service/geo_calendar/zammad.rb @@ -12,11 +12,11 @@ class Service::GeoCalendar::Zammad # do lookup host = 'https://geo.zammad.com' - if address - url = "/calendar?ip=#{CGI.escape address}" - else - url = '/calendar' - end + url = if address + "/calendar?ip=#{CGI.escape address}" + else + '/calendar' + end data = {} begin response = UserAgent.get( diff --git a/lib/sessions.rb b/lib/sessions.rb index 79cefbab0..385d1909d 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -401,7 +401,7 @@ returns } files.sort.each {|entry| filename = "#{path}/#{entry}" - if /^send/.match(entry) + if /^send/ =~ entry data.push Sessions.queue_file_read(path, entry) end } diff --git a/lib/sessions/backend/collections/organization.rb b/lib/sessions/backend/collections/organization.rb index 6ead8a5b3..b799e0b4c 100644 --- a/lib/sessions/backend/collections/organization.rb +++ b/lib/sessions/backend/collections/organization.rb @@ -7,10 +7,8 @@ class Sessions::Backend::Collections::Organization < Sessions::Backend::Collecti all = [] if !@user.role?('Customer') all = Organization.all - else - if @user.organization_id - all = Organization.where( id: @user.organization_id ) - end + elsif @user.organization_id + all = Organization.where( id: @user.organization_id ) end all diff --git a/lib/sessions/event/base.rb b/lib/sessions/event/base.rb index e36273cd1..0d4a66d94 100644 --- a/lib/sessions/event/base.rb +++ b/lib/sessions/event/base.rb @@ -11,11 +11,11 @@ class Sessions::Event::Base end def websocket_send(recipient_client_id, data) - if data.class != Array - msg = "[#{data.to_json}]" - else - msg = data.to_json - end + msg = if data.class != Array + "[#{data.to_json}]" + else + data.to_json + end if @clients[recipient_client_id] log 'debug', "ws send #{msg}", recipient_client_id @clients[recipient_client_id][:websocket].send(msg) diff --git a/lib/sessions/event/broadcast.rb b/lib/sessions/event/broadcast.rb index 3fec53074..ef874d76e 100644 --- a/lib/sessions/event/broadcast.rb +++ b/lib/sessions/event/broadcast.rb @@ -14,22 +14,18 @@ class Sessions::Event::Broadcast < Sessions::Event::Base if @payload['recipient'] if @payload['recipient'].class != Hash log 'error', "recipient attribute isn't a hash '#{@payload['recipient'].inspect}'" + elsif !@payload['recipient'].key?('user_id') + log 'error', "need recipient.user_id attribute '#{@payload['recipient'].inspect}'" + elsif @payload['recipient']['user_id'].class != Array + log 'error', "recipient.user_id attribute isn't an array '#{@payload['recipient']['user_id'].inspect}'" else - if !@payload['recipient'].key?('user_id') - log 'error', "need recipient.user_id attribute '#{@payload['recipient'].inspect}'" - else - if @payload['recipient']['user_id'].class != Array - log 'error', "recipient.user_id attribute isn't an array '#{@payload['recipient']['user_id'].inspect}'" - else - @payload['recipient']['user_id'].each { |user_id| + @payload['recipient']['user_id'].each { |user_id| - next if local_client[:user]['id'].to_i != user_id.to_i + next if local_client[:user]['id'].to_i != user_id.to_i - log 'notice', "send broadcast from (#{@client_id}) to (user_id=#{user_id})", local_client_id - websocket_send(local_client_id, @payload['data']) - } - end - end + log 'notice', "send broadcast from (#{@client_id}) to (user_id=#{user_id})", local_client_id + websocket_send(local_client_id, @payload['data']) + } end # broadcast every client diff --git a/lib/sessions/event/login.rb b/lib/sessions/event/login.rb index e9b6b347b..b520b54c0 100644 --- a/lib/sessions/event/login.rb +++ b/lib/sessions/event/login.rb @@ -13,11 +13,11 @@ class Sessions::Event::Login < Sessions::Event::Base end end - if session && session.data && session.data['user_id'] - new_session_data = { 'id' => session.data['user_id'] } - else - new_session_data = {} - end + new_session_data = if session && session.data && session.data['user_id'] + { 'id' => session.data['user_id'] } + else + {} + end if @clients[@client_id] @clients[@client_id][:session] = new_session_data diff --git a/lib/sessions/event/spool.rb b/lib/sessions/event/spool.rb index 702044b4f..f51a03ace 100644 --- a/lib/sessions/event/spool.rb +++ b/lib/sessions/event/spool.rb @@ -21,11 +21,10 @@ class Sessions::Event::Spool < Sessions::Event::Base # create new msg to push to client if item[:type] == 'direct' log 'notice', "send spool to (user_id=#{@session['id']})" - websocket_send(@client_id, item[:message]) else log 'notice', 'send spool' - websocket_send(@client_id, item[:message]) end + websocket_send(@client_id, item[:message]) } # send spool:sent event to client diff --git a/lib/stats/ticket_channel_distribution.rb b/lib/stats/ticket_channel_distribution.rb index ebc58e868..f56c518ee 100644 --- a/lib/stats/ticket_channel_distribution.rb +++ b/lib/stats/ticket_channel_distribution.rb @@ -67,19 +67,19 @@ class Stats::TicketChannelDistribution channels.each {|channel| count = result[channel[:sender].to_sym][:inbound] #puts "#{channel.inspect}:in/#{result.inspect}:#{count}" - if count == 0 - in_process_precent = 0 - else - in_process_precent = (count * 1000) / ((total_in * 1000) / 100) - end + in_process_precent = if count == 0 + 0 + else + (count * 1000) / ((total_in * 1000) / 100) + end result[channel[:sender].to_sym][:inbound_in_percent] = in_process_precent count = result[channel[:sender].to_sym][:outbound] - if count == 0 - out_process_precent = 0 - else - out_process_precent = (count * 1000) / ((total_out * 1000) / 100) - end + out_process_precent = if count == 0 + 0 + else + (count * 1000) / ((total_out * 1000) / 100) + end result[channel[:sender].to_sym][:outbound_in_percent] = out_process_precent } diff --git a/lib/stats/ticket_escalation.rb b/lib/stats/ticket_escalation.rb index 81cbaa5f0..abe359a04 100644 --- a/lib/stats/ticket_escalation.rb +++ b/lib/stats/ticket_escalation.rb @@ -21,15 +21,15 @@ class Stats::TicketEscalation average = '-' state = 'supergood' - if own_escalated == 0 - state = 'supergood' - elsif own_escalated <= 1 - state = 'good' - elsif own_escalated <= 4 - state = 'ok' - else - state = 'bad' - end + state = if own_escalated == 0 + 'supergood' + elsif own_escalated <= 1 + 'good' + elsif own_escalated <= 4 + 'ok' + else + 'bad' + end { used_for_average: own_escalated, diff --git a/lib/stats/ticket_in_process.rb b/lib/stats/ticket_in_process.rb index ce76f64e2..c4f45041d 100644 --- a/lib/stats/ticket_in_process.rb +++ b/lib/stats/ticket_in_process.rb @@ -63,17 +63,17 @@ class Stats::TicketInProcess end in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1) - if in_percent >= 90 - result[:state] = 'supergood' - elsif in_percent >= 65 - result[:state] = 'good' - elsif in_percent >= 40 - result[:state] = 'ok' - elsif in_percent >= 20 - result[:state] = 'bad' - else - result[:state] = 'superbad' - end + result[:state] = if in_percent >= 90 + 'supergood' + elsif in_percent >= 65 + 'good' + elsif in_percent >= 40 + 'ok' + elsif in_percent >= 20 + 'bad' + else + 'superbad' + end result end diff --git a/lib/stats/ticket_load_measure.rb b/lib/stats/ticket_load_measure.rb index 1c3e0fecb..b1c60dc58 100644 --- a/lib/stats/ticket_load_measure.rb +++ b/lib/stats/ticket_load_measure.rb @@ -44,17 +44,17 @@ class Stats::TicketLoadMeasure in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1) result[:average_per_agent_in_percent] = in_percent - if in_percent >= 90 - result[:state] = 'supergood' - elsif in_percent >= 65 - result[:state] = 'good' - elsif in_percent >= 40 - result[:state] = 'ok' - elsif in_percent >= 20 - result[:state] = 'bad' - else - result[:state] = 'superbad' - end + result[:state] = if in_percent >= 90 + 'supergood' + elsif in_percent >= 65 + 'good' + elsif in_percent >= 40 + 'ok' + elsif in_percent >= 20 + 'bad' + else + 'superbad' + end # convert result[:used_for_average] in percent to related total result[:average_per_agent] = ( (result[:total].to_f / 100) * result[:average_per_agent] ).round(1) diff --git a/lib/stats/ticket_reopen.rb b/lib/stats/ticket_reopen.rb index 7b7990df1..6ef880a36 100644 --- a/lib/stats/ticket_reopen.rb +++ b/lib/stats/ticket_reopen.rb @@ -49,17 +49,17 @@ class Stats::TicketReopen #in_percent = ( result[:used_for_average].to_f / (result[:average_per_agent].to_f / 100) ).round(1) #result[:average_per_agent_in_percent] = in_percent in_percent = ( result[:count].to_f / (result[:total].to_f / 100) ).round(1) - if in_percent >= 90 - result[:state] = 'superbad' - elsif in_percent >= 65 - result[:state] = 'bad' - elsif in_percent >= 40 - result[:state] = 'ok' - elsif in_percent >= 20 - result[:state] = 'good' - else - result[:state] = 'supergood' - end + result[:state] = if in_percent >= 90 + 'superbad' + elsif in_percent >= 65 + 'bad' + elsif in_percent >= 40 + 'ok' + elsif in_percent >= 20 + 'good' + else + 'supergood' + end result end diff --git a/lib/stats/ticket_response_time.rb b/lib/stats/ticket_response_time.rb index e6b2b494e..1952722e7 100644 --- a/lib/stats/ticket_response_time.rb +++ b/lib/stats/ticket_response_time.rb @@ -56,17 +56,17 @@ class Stats::TicketResponseTime end in_percent = ( result[:used_for_average].to_f / (result[:total].to_f / 100) ).round(1) - if in_percent >= 90 - result[:state] = 'supergood' - elsif in_percent >= 65 - result[:state] = 'good' - elsif in_percent >= 40 - result[:state] = 'ok' - elsif in_percent >= 20 - result[:state] = 'bad' - else - result[:state] = 'superbad' - end + result[:state] = if in_percent >= 90 + 'supergood' + elsif in_percent >= 65 + 'good' + elsif in_percent >= 40 + 'ok' + elsif in_percent >= 20 + 'bad' + else + 'superbad' + end result end diff --git a/lib/twitter/streaming/connection_custom.rb b/lib/twitter/streaming/connection_custom.rb index 6b90480f6..cd973cf05 100644 --- a/lib/twitter/streaming/connection_custom.rb +++ b/lib/twitter/streaming/connection_custom.rb @@ -4,8 +4,8 @@ class Twitter::Streaming::ConnectionCustom < Twitter::Streaming::Connection def stream(request, response) client_context = OpenSSL::SSL::SSLContext.new - @client = @tcp_socket_class.new(Resolv.getaddress(request.uri.host), request.uri.port) - ssl_client = @ssl_socket_class.new(@client, client_context) + @client = @tcp_socket_class.new(Resolv.getaddress(request.uri.host), request.uri.port) + ssl_client = @ssl_socket_class.new(@client, client_context) ssl_client.connect request.stream(ssl_client) diff --git a/lib/user_agent.rb b/lib/user_agent.rb index e11616040..739019bc9 100644 --- a/lib/user_agent.rb +++ b/lib/user_agent.rb @@ -274,10 +274,8 @@ returns if !params.empty? request.body = params.to_json end - else - if !params.empty? - request.set_form_data(params) - end + elsif !params.empty? + request.set_form_data(params) end request end diff --git a/script/websocket-server.rb b/script/websocket-server.rb index af7cb6a64..323ce8746 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -238,11 +238,11 @@ EventMachine.run { end def websocket_send(client_id, data) - if data.class != Array - msg = "[#{data.to_json}]" - else - msg = data.to_json - end + msg = if data.class != Array + "[#{data.to_json}]" + else + data.to_json + end log 'debug', "send #{msg}", client_id if !@clients[client_id] log 'error', "no such @clients for #{client_id}", client_id diff --git a/test/browser/translation_test.rb b/test/browser/translation_test.rb index 5baa33eec..02375209a 100644 --- a/test/browser/translation_test.rb +++ b/test/browser/translation_test.rb @@ -107,11 +107,11 @@ class TranslationTest < TestCase ) @browser.action.key_down(:control) - .key_down(:alt) - .send_keys('t') - .key_up(:alt) - .key_up(:control) - .perform + .key_down(:alt) + .send_keys('t') + .key_up(:alt) + .key_up(:control) + .perform watch_for( css: 'span.translation[title="Overviews"]', @@ -126,11 +126,11 @@ class TranslationTest < TestCase sleep 5 @browser.action.key_down(:control) - .key_down(:alt) - .send_keys('t') - .key_up(:alt) - .key_up(:control) - .perform + .key_down(:alt) + .send_keys('t') + .key_up(:alt) + .key_up(:control) + .perform sleep 5 exists_not( @@ -192,11 +192,11 @@ class TranslationTest < TestCase sleep 5 @browser.action.key_down(:control) - .key_down(:alt) - .send_keys('t') - .key_up(:alt) - .key_up(:control) - .perform + .key_down(:alt) + .send_keys('t') + .key_up(:alt) + .key_up(:control) + .perform watch_for( css: 'span.translation[title="Overviews"]', @@ -211,11 +211,11 @@ class TranslationTest < TestCase sleep 5 @browser.action.key_down(:control) - .key_down(:alt) - .send_keys('t') - .key_up(:alt) - .key_up(:control) - .perform + .key_down(:alt) + .send_keys('t') + .key_up(:alt) + .key_up(:control) + .perform sleep 5 exists_not( diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 0bd2638e5..b447a0764 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -512,10 +512,8 @@ class TestCase < Test::Unit::TestCase if params[:type] == 'on' instance.find_elements({ css: "#{params[:css]} label" })[0].click end - else - if params[:type] == 'off' - instance.find_elements({ css: "#{params[:css]} label" })[0].click - end + elsif params[:type] == 'off' + instance.find_elements({ css: "#{params[:css]} label" })[0].click end end @@ -622,32 +620,30 @@ class TestCase < Test::Unit::TestCase if success fail "should not match '#{params[:value]}' in select list, but is matching" end - return true - else - if !success - fail "not matching '#{params[:value]}' in select list" - end - return true + elsif !success + fail "not matching '#{params[:value]}' in select list" end + + return true end # match on attribute begin - if params[:attribute] - text = element.attribute(params[:attribute]) - elsif params[:css] =~ /(input|textarea)/i - text = element.attribute('value') - else - text = element.text - end + text = if params[:attribute] + element.attribute(params[:attribute]) + elsif params[:css] =~ /(input|textarea)/i + element.attribute('value') + else + element.text + end rescue => e # just try again if !fallback return match(params, true) - else - raise e.inspect end + + raise e.inspect end # do cleanups (needed for richtext tests) @@ -662,19 +658,16 @@ class TestCase < Test::Unit::TestCase if text =~ /#{params[:value]}/i match = $1 || true end - else - if text =~ /#{Regexp.quote(params[:value])}/i - match = true - end + elsif text =~ /#{Regexp.quote(params[:value])}/i + match = true end + if match if params[:should_not_match] fail "matching '#{params[:value]}' in content '#{text}' but should not!" end - else - if !params[:should_not_match] - fail "not matching '#{params[:value]}' in content '#{text}' but should!" - end + elsif !params[:should_not_match] + fail "not matching '#{params[:value]}' in content '#{text}' but should!" end sleep 0.8 match @@ -855,14 +848,12 @@ class TestCase < Test::Unit::TestCase else fail "task '#{data[:title]}' is not modifed" end + elsif !is_modified + assert(true, "task '#{data[:title]}' is modifed") + elsif !exists + fail "task '#{data[:title]}' not exists, should be not modified" else - if !is_modified - assert(true, "task '#{data[:title]}' is modifed") - elsif !exists - fail "task '#{data[:title]}' not exists, should be not modified" - else - fail "task '#{data[:title]}' is modifed, but should not" - end + fail "task '#{data[:title]}' is modifed, but should not" end end rescue => e @@ -870,9 +861,8 @@ class TestCase < Test::Unit::TestCase # just try again if !fallback verify_task(params, true) - else - raise 'ERROR: ' + e.inspect end + raise 'ERROR: ' + e.inspect end true end @@ -948,7 +938,7 @@ class TestCase < Test::Unit::TestCase if params[:timeout] timeout = params[:timeout] end - loops = (timeout).to_i * 2 + loops = timeout.to_i * 2 text = '' (1..loops).each { element = instance.find_elements({ css: params[:css] })[0] @@ -956,13 +946,13 @@ class TestCase < Test::Unit::TestCase begin # match pn attribute - if params[:attribute] - text = element.attribute(params[:attribute]) - elsif params[:css] =~ /(input|textarea)/i - text = element.attribute('value') - else - text = element.text - end + text = if params[:attribute] + element.attribute(params[:attribute]) + elsif params[:css] =~ /(input|textarea)/i + element.attribute('value') + else + element.text + end if text =~ /#{params[:value]}/i assert(true, "'#{params[:value]}' found in '#{text}'") sleep 0.5 @@ -1009,7 +999,7 @@ wait untill text in selector disabppears if params[:timeout] timeout = params[:timeout] end - loops = (timeout).to_i + loops = timeout.to_i text = '' (1..loops).each { element = instance.find_elements({ css: params[:css] })[0] diff --git a/test/integration/elasticsearch_test.rb b/test/integration/elasticsearch_test.rb index 7fbd4cfe3..b0735e4f6 100644 --- a/test/integration/elasticsearch_test.rb +++ b/test/integration/elasticsearch_test.rb @@ -46,7 +46,7 @@ class ElasticsearchTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1 ) - roles = Role.where( name: 'Customer' ) + roles = Role.where( name: 'Customer' ) organization1 = Organization.create_if_not_exists( name: 'Customer Organization Update', updated_by_id: 1, diff --git a/test/integration/twitter_browser_test.rb b/test/integration/twitter_browser_test.rb index e60c7fda9..43bab400e 100644 --- a/test/integration/twitter_browser_test.rb +++ b/test/integration/twitter_browser_test.rb @@ -215,12 +215,12 @@ class TwitterBrowserTest < TestCase watch_for( css: '.content.active', - value: "#{hash}", + value: hash.to_s, timeout: 20, ) ticket_open_by_title( - title: "#{hash}", + title: hash.to_s, ) # reply via app diff --git a/test/integration/twitter_test.rb b/test/integration/twitter_test.rb index 5c9903012..64f3a06b8 100644 --- a/test/integration/twitter_test.rb +++ b/test/integration/twitter_test.rb @@ -301,7 +301,7 @@ class TwitterTest < ActiveSupport::TestCase ticket.state = Ticket::State.find_by(name: 'pending reminder') ticket.save - text = 'Ok. ' + hash + text = 'Ok. ' + hash dm = client.create_direct_message( 'armin_theo', text, diff --git a/test/unit/aaa_string_test.rb b/test/unit/aaa_string_test.rb index c533c71aa..95cd22258 100644 --- a/test/unit/aaa_string_test.rb +++ b/test/unit/aaa_string_test.rb @@ -109,20 +109,20 @@ class AaaStringTest < ActiveSupport::TestCase result = 'Was soll verbessert werden:' assert_equal(result, html.html2text) - html = " + html = "
test


\n
\n
\n
" result = 'test' assert_equal(result, html.html2text) - html = "\n
Best Tool of the World + html = "\n
Best Tool of the World some other text
" result = "[1] Best Tool of the Worldsome other text\n\n\n[1] http://zammad.org" assert_equal(result, html.html2text) - html = " + html = "
test


\n
\n
\n
" @@ -259,7 +259,7 @@ div.wordsection1 should = 'IT-Infrastruktur' assert_equal( should, html.html2text) - html = "

some head

+ html = "

some head

some content

line 1

@@ -274,7 +274,7 @@ some content some text later' assert_equal(result, html.html2text) - html = "

some head

+ html = "

some head

some content
line 1
@@ -289,7 +289,7 @@ some content some text later' assert_equal(result, html.html2text) - html = "

some head

+ html = "

some head

some content
line 1

diff --git a/test/unit/activity_stream_test.rb b/test/unit/activity_stream_test.rb index d791a3d95..76a10852e 100644 --- a/test/unit/activity_stream_test.rb +++ b/test/unit/activity_stream_test.rb @@ -383,10 +383,8 @@ class ActivityStreamTest < ActiveSupport::TestCase assert_equal( check_item[:object], item['object'] ) assert_equal( check_item[:type], item['type'] ) assert_equal( check_item[:o_id], item['o_id'] ) - else - if check_item[:object] == item['object'] && check_item[:type] == item['type'] && check_item[:o_id] == item['o_id'] - assert( false, "entry should not exist #{item['object']}/#{item['type']}/#{item['o_id']}" ) - end + elsif check_item[:object] == item['object'] && check_item[:type] == item['type'] && check_item[:o_id] == item['o_id'] + assert( false, "entry should not exist #{item['object']}/#{item['type']}/#{item['o_id']}" ) end } } diff --git a/test/unit/email_build_test.rb b/test/unit/email_build_test.rb index cfd7f8165..04a4db2ec 100644 --- a/test/unit/email_build_test.rb +++ b/test/unit/email_build_test.rb @@ -41,7 +41,7 @@ class EmailBuildTest < ActiveSupport::TestCase content_type: 'text/html', attachments: [ { - 'Mime-Type' => 'image/png', + 'Mime-Type' => 'image/png', :content => 'xxx', :filename => 'somename.png', }, @@ -95,7 +95,7 @@ class EmailBuildTest < ActiveSupport::TestCase body: text, attachments: [ { - 'Mime-Type' => 'image/png', + 'Mime-Type' => 'image/png', :content => 'xxx', :filename => 'somename.png', }, diff --git a/test/unit/object_cache_test.rb b/test/unit/object_cache_test.rb index 5ca3cb821..8495c6837 100644 --- a/test/unit/object_cache_test.rb +++ b/test/unit/object_cache_test.rb @@ -98,7 +98,7 @@ class ObjectCacheTest < ActiveSupport::TestCase assert_equal( name, group_new[:name], 'verify by where' ) # lookup by name - cache_key = "#{group_new.name}" + cache_key = group_new.name.to_s assert_nil( Group.cache_get(cache_key) ) group_lookup_name = Group.lookup( name: group_new.name ) @@ -106,7 +106,7 @@ class ObjectCacheTest < ActiveSupport::TestCase assert( Group.cache_get(cache_key) ) # lookup by id - cache_key = "#{group_new.id}" + cache_key = group_new.id.to_s assert_nil( Group.cache_get(cache_key) ) group_lookup_id = Group.lookup( id: group.id ) @@ -119,7 +119,7 @@ class ObjectCacheTest < ActiveSupport::TestCase group.save # lookup by name - cache_key = "#{group.name}" + cache_key = group.name.to_s assert_nil( Group.cache_get(cache_key) ) group_lookup = Group.where( name: group_new.name ).first @@ -139,7 +139,7 @@ class ObjectCacheTest < ActiveSupport::TestCase assert( Group.cache_get(cache_key) ) # lookup by id - cache_key = "#{group_new.id}" + cache_key = group_new.id.to_s assert_nil( Group.cache_get(cache_key) ) group_lookup_id = Group.lookup( id: group.id ) diff --git a/test/unit/organization_ref_object_touch_test.rb b/test/unit/organization_ref_object_touch_test.rb index 02acd2718..5071fd04c 100644 --- a/test/unit/organization_ref_object_touch_test.rb +++ b/test/unit/organization_ref_object_touch_test.rb @@ -19,7 +19,7 @@ class OrganizationRefObjectTouchTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - roles = Role.where( name: 'Customer' ) + roles = Role.where( name: 'Customer' ) organization1 = Organization.create_if_not_exists( name: 'Ref Object Update Org 1', updated_at: '2015-02-05 16:37:00', diff --git a/test/unit/recent_view_test.rb b/test/unit/recent_view_test.rb index 4576b1507..6ed3e2500 100644 --- a/test/unit/recent_view_test.rb +++ b/test/unit/recent_view_test.rb @@ -25,7 +25,7 @@ class RecentViewTest < ActiveSupport::TestCase created_by_id: 1, ) assert( ticket2, 'ticket created' ) - user1 = User.find(2) + user1 = User.find(2) RecentView.user_log_destroy(user1) RecentView.log( ticket1.class.to_s, ticket1.id, user1 ) diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index 1b4551482..327f72a1d 100644 --- a/test/unit/session_basic_test.rb +++ b/test/unit/session_basic_test.rb @@ -180,7 +180,7 @@ class SessionBasicTest < ActiveSupport::TestCase end user = User.lookup(id: 1) - roles = Role.where( name: %w(Agent Admin) ) + roles = Role.where( name: %w(Agent Admin) ) user.roles = roles user.save diff --git a/test/unit/session_collections_test.rb b/test/unit/session_collections_test.rb index c6bd1942e..420638784 100644 --- a/test/unit/session_collections_test.rb +++ b/test/unit/session_collections_test.rb @@ -40,7 +40,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase agent2.roles = roles agent2.save - roles = Role.where( name: [ 'Customer'] ) + roles = Role.where( name: [ 'Customer'] ) customer1 = User.create_or_update( login: 'session-collections-customer-1', firstname: 'Session', diff --git a/test/unit/tag_test.rb b/test/unit/tag_test.rb index e3fac8588..4426e6bfe 100644 --- a/test/unit/tag_test.rb +++ b/test/unit/tag_test.rb @@ -116,11 +116,11 @@ class TagTest < ActiveSupport::TestCase # delete tags tests.each { |test| tags = nil - if test[:tag_add] - tags = test[:tag_add] - else - tags = test[:tag_remove] - end + tags = if test[:tag_add] + test[:tag_add] + else + test[:tag_remove] + end success = Tag.tag_remove( tags ) assert( success, 'Tag.tag_remove successful') list = Tag.tag_list( tags ) diff --git a/test/unit/ticket_customer_organization_update_test.rb b/test/unit/ticket_customer_organization_update_test.rb index 7e1c82d1b..59f0ba658 100644 --- a/test/unit/ticket_customer_organization_update_test.rb +++ b/test/unit/ticket_customer_organization_update_test.rb @@ -19,7 +19,7 @@ class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - roles = Role.where( name: 'Customer' ) + roles = Role.where( name: 'Customer' ) organization1 = Organization.create_if_not_exists( name: 'Customer Organization Update', updated_at: '2015-02-05 16:37:00', diff --git a/test/unit/ticket_ref_object_touch_test.rb b/test/unit/ticket_ref_object_touch_test.rb index 170f0448b..a516d6f9a 100644 --- a/test/unit/ticket_ref_object_touch_test.rb +++ b/test/unit/ticket_ref_object_touch_test.rb @@ -19,7 +19,7 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - roles = Role.where( name: 'Customer' ) + roles = Role.where( name: 'Customer' ) organization1 = Organization.create_if_not_exists( name: 'Ref Object Update Org', updated_at: '2015-02-05 16:37:00', diff --git a/test/unit/ticket_selector_test.rb b/test/unit/ticket_selector_test.rb index 75714001f..5476d3499 100644 --- a/test/unit/ticket_selector_test.rb +++ b/test/unit/ticket_selector_test.rb @@ -37,7 +37,7 @@ class TicketSelectorTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - roles = Role.where( name: 'Customer' ) + roles = Role.where( name: 'Customer' ) organization1 = Organization.create_if_not_exists( name: 'Selector Org', updated_at: '2015-02-05 16:37:00', diff --git a/test/unit/user_ref_object_touch_test.rb b/test/unit/user_ref_object_touch_test.rb index d13354220..621bea389 100644 --- a/test/unit/user_ref_object_touch_test.rb +++ b/test/unit/user_ref_object_touch_test.rb @@ -19,7 +19,7 @@ class UserRefObjectTouchTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - roles = Role.where( name: 'Customer' ) + roles = Role.where( name: 'Customer' ) organization1 = Organization.create_if_not_exists( name: 'Ref Object Update Org', updated_at: '2015-02-05 16:37:00',