diff --git a/Gemfile.lock b/Gemfile.lock index 7f82aa27c..d615376bf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -451,7 +451,7 @@ GEM rspec-support (~> 3.8.0) rspec-support (3.8.0) rszr (0.5.2) - rubocop (0.87.0) + rubocop (0.88.0) parallel (~> 1.10) parser (>= 2.7.1.1) rainbow (>= 2.2.2, < 4.0) @@ -468,8 +468,8 @@ GEM activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 0.82.0) - rubocop-rspec (1.41.0) - rubocop (>= 0.68.1) + rubocop-rspec (1.42.0) + rubocop (>= 0.87.0) ruby-progressbar (1.10.1) ruby-saml (1.10.2) nokogiri (>= 1.5.10) diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb index afae5000d..af27c92fd 100644 --- a/app/controllers/monitoring_controller.rb +++ b/app/controllers/monitoring_controller.rb @@ -306,13 +306,14 @@ curl http://localhost/api/v1/monitoring/amount_check?token=XXX&periode=1h periode = params[:periode][0, params[:periode].length - 1] raise Exceptions::UnprocessableEntity, 'periode need to be an integer!' if periode.to_i.zero? - if scale == 's' + case scale + when 's' created_at = Time.zone.now - periode.to_i.seconds - elsif scale == 'm' + when 'm' created_at = Time.zone.now - periode.to_i.minutes - elsif scale == 'h' + when 'h' created_at = Time.zone.now - periode.to_i.hours - elsif scale == 'd' + when 'd' created_at = Time.zone.now - periode.to_i.days end diff --git a/app/controllers/object_manager_attributes_controller.rb b/app/controllers/object_manager_attributes_controller.rb index 51d6b0e39..4299e9b1a 100644 --- a/app/controllers/object_manager_attributes_controller.rb +++ b/app/controllers/object_manager_attributes_controller.rb @@ -85,9 +85,10 @@ class ObjectManagerAttributesController < ApplicationController if permitted[:data_option][:options][:true] permitted[:data_option][:options][true] = permitted[:data_option][:options].delete(:true) end - if permitted[:data_option][:default] == 'true' + case permitted[:data_option][:default] + when 'true' permitted[:data_option][:default] = true - elsif permitted[:data_option][:default] == 'false' + when 'false' permitted[:data_option][:default] = false end # rubocop:enable Lint/BooleanSymbol diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 346a7cbd7..cf8c37119 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -138,22 +138,23 @@ class ReportsController < ApplicationController metric = local_config[:metric][params[:metric].to_sym] - if params[:timeRange] == 'realtime' + case params[:timeRange] + when 'realtime' start_at = (Time.zone.now - 60.minutes) stop_at = Time.zone.now range = 'minute' - elsif params[:timeRange] == 'day' + when 'day' date = Date.parse("#{params[:year]}-#{params[:month]}-#{params[:day]}").to_s start_at = Time.zone.parse("#{date}T00:00:00Z") stop_at = Time.zone.parse("#{date}T23:59:59Z") range = 'hour' - elsif params[:timeRange] == 'week' + when 'week' start_week_at = Date.commercial(params[:year].to_i, params[:week].to_i) stop_week_at = start_week_at.end_of_week start_at = Time.zone.parse("#{start_week_at.year}-#{start_week_at.month}-#{start_week_at.day}T00:00:00Z") stop_at = Time.zone.parse("#{stop_week_at.year}-#{stop_week_at.month}-#{stop_week_at.day}T23:59:59Z") range = 'week' - elsif params[:timeRange] == 'month' + when 'month' start_at = Time.zone.parse("#{params[:year]}-#{params[:month]}-01T00:00:00Z") stop_at = Time.zone.parse("#{params[:year]}-#{params[:month]}-#{start_at.end_of_month.day}T23:59:59Z") range = 'day' diff --git a/app/helpers/knowledge_base_top_bar_helper.rb b/app/helpers/knowledge_base_top_bar_helper.rb index 3c7a25487..6fb8ad2bb 100644 --- a/app/helpers/knowledge_base_top_bar_helper.rb +++ b/app/helpers/knowledge_base_top_bar_helper.rb @@ -12,16 +12,13 @@ module KnowledgeBaseTopBarHelper end def kb_answer_top_bar_color(answer) - case answer.can_be_published_aasm.current_state - when :draft - 'yellow' - when :internal - 'blue' - when :published - 'green' - when :archived - 'grey' - end + state_color_map = { + draft: 'yellow', + internal: 'blue', + published: 'green', + archived: 'grey', + } + state_color_map[answer.can_be_published_aasm.current_state] end def kb_top_bar_tag(object) diff --git a/app/helpers/knowledge_base_visibility_class_helper.rb b/app/helpers/knowledge_base_visibility_class_helper.rb index 49dcf29fd..ae01cfc5d 100644 --- a/app/helpers/knowledge_base_visibility_class_helper.rb +++ b/app/helpers/knowledge_base_visibility_class_helper.rb @@ -13,14 +13,12 @@ module KnowledgeBaseVisibilityClassHelper end def visiblity_class_suffix_can_be_published(object) - case object.can_be_published_aasm.current_state - when :internal - 'internal' - when :archived - 'archived' - when :draft - 'not-published' - end + state_suffix_map = { + internal: 'internal', + archived: 'archived', + draft: 'not-published', + } + state_suffix_map[object.can_be_published_aasm.current_state] end def visiblity_class_suffix_category(object) diff --git a/app/helpers/knowledge_base_visibility_note_helper.rb b/app/helpers/knowledge_base_visibility_note_helper.rb index ba8fd86ec..99a1fcc87 100644 --- a/app/helpers/knowledge_base_visibility_note_helper.rb +++ b/app/helpers/knowledge_base_visibility_note_helper.rb @@ -19,14 +19,12 @@ module KnowledgeBaseVisibilityNoteHelper end def visiblity_text_can_be_published(object) - case object.can_be_published_aasm.current_state - when :internal - 'internal' - when :archived - 'archived' - when :draft - 'not published' - end + state_text_map = { + internal: 'internal', + archived: 'archived', + draft: 'not published', + } + state_text_map[object.can_be_published_aasm.current_state] end def visiblity_text_category(object) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index f8291ea03..f97e9a1fa 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -87,7 +87,7 @@ class Channel::EmailParser headers, body, self.class.sender_attributes(headers), - raw: msg, + { raw: msg }, ] message_attributes.reduce({}.with_indifferent_access, &:merge) end diff --git a/app/models/channel/filter/database.rb b/app/models/channel/filter/database.rb index 4fa279e4b..e00651782 100644 --- a/app/models/channel/filter/database.rb +++ b/app/models/channel/filter/database.rb @@ -18,12 +18,13 @@ module Channel::Filter::Database value = mail[ key.downcase.to_sym ] match_rule = meta['value'] min_one_rule_exists = true - if meta[:operator] == 'contains not' + case meta[:operator] + when 'contains not' if value.present? && Channel::Filter::Match::EmailRegex.match(value: value, match_rule: match_rule) all_matches_ok = false Rails.logger.info " matching #{key.downcase}:'#{value}' on #{match_rule}, but shoud not" end - elsif meta[:operator] == 'contains' + when 'contains' if value.blank? || !Channel::Filter::Match::EmailRegex.match(value: value, match_rule: match_rule) all_matches_ok = false Rails.logger.info " not matching #{key.downcase}:'#{value}' on #{match_rule}, but should" diff --git a/app/models/channel/filter/monitoring_base.rb b/app/models/channel/filter/monitoring_base.rb index 849c96d44..b342986ef 100644 --- a/app/models/channel/filter/monitoring_base.rb +++ b/app/models/channel/filter/monitoring_base.rb @@ -71,9 +71,10 @@ class Channel::Filter::MonitoringBase # possible event types https://mmonit.com/monit/documentation/#Setting-an-event-filter if result['state'].blank? - result['state'] = if mail[:body].match?(/\s(done|recovery|succeeded|bytes\sok|packets\sok)\s/) + result['state'] = case mail[:body] + when /\s(done|recovery|succeeded|bytes\sok|packets\sok)\s/ 'OK' - elsif mail[:body].match?(/(instance\schanged\snot|Link\sup|Exists|Saturation\sok|Speed\sok)/) + when /(instance\schanged\snot|Link\sup|Exists|Saturation\sok|Speed\sok)/ 'OK' else 'CRITICAL' diff --git a/app/models/chat.rb b/app/models/chat.rb index d0ae016eb..9463d7b5a 100644 --- a/app/models/chat.rb +++ b/app/models/chat.rb @@ -66,7 +66,8 @@ reconnect - chat session already exists, serve agent and session chat messages ( chat_session = Chat::Session.find_by(session_id: session_id, state: %w[waiting running]) if chat_session - if chat_session.state == 'running' + case chat_session.state + when 'running' user = chat_session.agent_user if user @@ -80,7 +81,7 @@ reconnect - chat session already exists, serve agent and session chat messages ( } end end - elsif chat_session.state == 'waiting' + when 'waiting' return { state: 'reconnect', position: chat_session.position, diff --git a/app/models/cti/driver/placetel.rb b/app/models/cti/driver/placetel.rb index 9bb20565b..ee523de59 100644 --- a/app/models/cti/driver/placetel.rb +++ b/app/models/cti/driver/placetel.rb @@ -7,15 +7,16 @@ class Cti::Driver::Placetel < Cti::Driver::Base def mapping(params) # do event mapping - if params['event'] == 'IncomingCall' + case params['event'] + when 'IncomingCall' params['direction'] = 'in' params['event'] = 'newCall' - elsif params['event'] == 'HungUp' + when 'HungUp' params['event'] = 'hangup' - elsif params['event'] == 'OutgoingCall' + when 'OutgoingCall' params['direction'] = 'out' params['event'] = 'newCall' - elsif params['event'] == 'CallAccepted' + when 'CallAccepted' params['event'] = 'answer' end @@ -41,13 +42,14 @@ class Cti::Driver::Placetel < Cti::Driver::Base end # do case mapping - if params['type'] == 'missed' + case params['type'] + when 'missed' params['cause'] = 'cancel' - elsif params['type'] == 'voicemail' + when 'voicemail' params['cause'] = 'voicemail' - elsif params['type'] == 'blocked' + when 'blocked' params['cause'] = 'blocked' - elsif params['type'] == 'accepted' + when 'accepted' params['cause'] = 'normalClearing' end diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb index 1b25cf6e6..d24447235 100644 --- a/app/models/object_manager/attribute.rb +++ b/app/models/object_manager/attribute.rb @@ -677,21 +677,23 @@ to send no browser reload event, pass false end data_type = nil - if attribute.data_type.match?(/^input|select|tree_select|richtext|textarea|checkbox$/) + case attribute.data_type + when /^input|select|tree_select|richtext|textarea|checkbox$/ data_type = :string - elsif attribute.data_type.match?(/^integer|user_autocompletion$/) + when /^integer|user_autocompletion$/ data_type = :integer - elsif attribute.data_type.match?(/^boolean|active$/) + when /^boolean|active$/ data_type = :boolean - elsif attribute.data_type.match?(/^datetime$/) + when /^datetime$/ data_type = :datetime - elsif attribute.data_type.match?(/^date$/) + when /^date$/ data_type = :date end # change field if model.column_names.include?(attribute.name) - if attribute.data_type.match?(/^input|select|tree_select|richtext|textarea|checkbox$/) + case attribute.data_type + when /^input|select|tree_select|richtext|textarea|checkbox$/ ActiveRecord::Migration.change_column( model.table_name, attribute.name, @@ -699,7 +701,7 @@ to send no browser reload event, pass false limit: attribute.data_option[:maxlength], null: true ) - elsif attribute.data_type.match?(/^integer|user_autocompletion|datetime|date$/) + when /^integer|user_autocompletion|datetime|date$/ ActiveRecord::Migration.change_column( model.table_name, attribute.name, @@ -707,7 +709,7 @@ to send no browser reload event, pass false default: attribute.data_option[:default], null: true ) - elsif attribute.data_type.match?(/^boolean|active$/) + when /^boolean|active$/ ActiveRecord::Migration.change_column( model.table_name, attribute.name, @@ -730,7 +732,8 @@ to send no browser reload event, pass false end # create field - if attribute.data_type.match?(/^input|select|tree_select|richtext|textarea|checkbox$/) + case attribute.data_type + when /^input|select|tree_select|richtext|textarea|checkbox$/ ActiveRecord::Migration.add_column( model.table_name, attribute.name, @@ -738,7 +741,7 @@ to send no browser reload event, pass false limit: attribute.data_option[:maxlength], null: true ) - elsif attribute.data_type.match?(/^integer|user_autocompletion$/) + when /^integer|user_autocompletion$/ ActiveRecord::Migration.add_column( model.table_name, attribute.name, @@ -746,7 +749,7 @@ to send no browser reload event, pass false default: attribute.data_option[:default], null: true ) - elsif attribute.data_type.match?(/^boolean|active$/) + when /^boolean|active$/ ActiveRecord::Migration.add_column( model.table_name, attribute.name, @@ -754,7 +757,7 @@ to send no browser reload event, pass false default: attribute.data_option[:default], null: true ) - elsif attribute.data_type.match?(/^datetime|date$/) + when /^datetime|date$/ ActiveRecord::Migration.add_column( model.table_name, attribute.name, diff --git a/app/models/package.rb b/app/models/package.rb index ea173477d..835f5ac83 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -408,9 +408,10 @@ execute all pending package migrations at once end def self._read_file(file, fullpath = false) - location = if fullpath == false + location = case fullpath + when false @@root + '/' + file - elsif fullpath == true + when true file else fullpath + '/' + file diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 4bb8ec1e9..58640cee6 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -547,19 +547,20 @@ condition example if query != '' query += ' AND ' end - if selector[0] == 'customer' + case selector[0] + when 'customer' tables += ', users customers' query += 'tickets.customer_id = customers.id' - elsif selector[0] == 'organization' + when 'organization' tables += ', organizations' query += 'tickets.organization_id = organizations.id' - elsif selector[0] == 'owner' + when 'owner' tables += ', users owners' query += 'tickets.owner_id = owners.id' - elsif selector[0] == 'article' + when 'article' tables += ', ticket_articles articles' query += 'tickets.id = articles.ticket_id' - elsif selector[0] == 'ticket_state' + when 'ticket_state' tables += ', ticket_states' query += 'tickets.state_id = ticket_states.id' else @@ -786,15 +787,16 @@ condition example elsif selector['operator'] == 'within last (relative)' query += "#{attribute} >= ?" time = nil - if selector['range'] == 'minute' + case selector['range'] + when 'minute' time = Time.zone.now - selector['value'].to_i.minutes - elsif selector['range'] == 'hour' + when 'hour' time = Time.zone.now - selector['value'].to_i.hours - elsif selector['range'] == 'day' + when 'day' time = Time.zone.now - selector['value'].to_i.days - elsif selector['range'] == 'month' + when 'month' time = Time.zone.now - selector['value'].to_i.months - elsif selector['range'] == 'year' + when 'year' time = Time.zone.now - selector['value'].to_i.years else raise "Unknown selector attributes '#{selector.inspect}'" @@ -803,15 +805,16 @@ condition example elsif selector['operator'] == 'within next (relative)' query += "#{attribute} <= ?" time = nil - if selector['range'] == 'minute' + case selector['range'] + when 'minute' time = Time.zone.now + selector['value'].to_i.minutes - elsif selector['range'] == 'hour' + when 'hour' time = Time.zone.now + selector['value'].to_i.hours - elsif selector['range'] == 'day' + when 'day' time = Time.zone.now + selector['value'].to_i.days - elsif selector['range'] == 'month' + when 'month' time = Time.zone.now + selector['value'].to_i.months - elsif selector['range'] == 'year' + when 'year' time = Time.zone.now + selector['value'].to_i.years else raise "Unknown selector attributes '#{selector.inspect}'" @@ -820,15 +823,16 @@ condition example elsif selector['operator'] == 'before (relative)' query += "#{attribute} <= ?" time = nil - if selector['range'] == 'minute' + case selector['range'] + when 'minute' time = Time.zone.now - selector['value'].to_i.minutes - elsif selector['range'] == 'hour' + when 'hour' time = Time.zone.now - selector['value'].to_i.hours - elsif selector['range'] == 'day' + when 'day' time = Time.zone.now - selector['value'].to_i.days - elsif selector['range'] == 'month' + when 'month' time = Time.zone.now - selector['value'].to_i.months - elsif selector['range'] == 'year' + when 'year' time = Time.zone.now - selector['value'].to_i.years else raise "Unknown selector attributes '#{selector.inspect}'" @@ -837,15 +841,16 @@ condition example elsif selector['operator'] == 'after (relative)' query += "#{attribute} >= ?" time = nil - if selector['range'] == 'minute' + case selector['range'] + when 'minute' time = Time.zone.now + selector['value'].to_i.minutes - elsif selector['range'] == 'hour' + when 'hour' time = Time.zone.now + selector['value'].to_i.hours - elsif selector['range'] == 'day' + when 'day' time = Time.zone.now + selector['value'].to_i.days - elsif selector['range'] == 'month' + when 'month' time = Time.zone.now + selector['value'].to_i.months - elsif selector['range'] == 'year' + when 'year' time = Time.zone.now + selector['value'].to_i.years else raise "Unknown selector attributes '#{selector.inspect}'" @@ -944,11 +949,12 @@ perform changes on ticket next if value['value'].blank? tags = value['value'].split(/,/) - if value['operator'] == 'add' + case value['operator'] + when 'add' tags.each do |tag| tag_add(tag, current_user_id || 1) end - elsif value['operator'] == 'remove' + when 'remove' tags.each do |tag| tag_remove(tag, current_user_id || 1) end @@ -1365,7 +1371,8 @@ result recipients_raw = [] value_recipient.each do |recipient| - if recipient == 'article_last_sender' + case recipient + when 'article_last_sender' if article.present? if article.reply_to.present? recipients_raw.push(article.reply_to) @@ -1379,17 +1386,17 @@ result recipients_raw.push(email) end end - elsif recipient == 'ticket_customer' + when 'ticket_customer' email = User.find_by(id: customer_id).email recipients_raw.push(email) - elsif recipient == 'ticket_owner' + when 'ticket_owner' email = User.find_by(id: owner_id).email recipients_raw.push(email) - elsif recipient == 'ticket_agents' + when 'ticket_agents' User.group_access(group_id, 'full').sort_by(&:login).each do |user| recipients_raw.push(user.email) end - elsif recipient =~ /\Auserid_(\d+)\z/ + when /\Auserid_(\d+)\z/ user = User.lookup(id: $1) if !user logger.warn "Can't find configured Trigger Email recipient User with ID '#{$1}'" diff --git a/app/models/transaction/notification.rb b/app/models/transaction/notification.rb index f7cd2daa7..daaaf00e4 100644 --- a/app/models/transaction/notification.rb +++ b/app/models/transaction/notification.rb @@ -170,15 +170,16 @@ class Transaction::Notification # get user based notification template # if create, send create message / block update messages template = nil - if @item[:type] == 'create' + case @item[:type] + when 'create' template = 'ticket_create' - elsif @item[:type] == 'update' + when 'update' template = 'ticket_update' - elsif @item[:type] == 'reminder_reached' + when 'reminder_reached' template = 'ticket_reminder_reached' - elsif @item[:type] == 'escalation' + when 'escalation' template = 'ticket_escalation' - elsif @item[:type] == 'escalation_warning' + when 'escalation_warning' template = 'ticket_escalation_warning' else raise "unknown type for notification #{@item[:type]}" diff --git a/app/models/transaction/slack.rb b/app/models/transaction/slack.rb index ab915301c..f50f8b972 100644 --- a/app/models/transaction/slack.rb +++ b/app/models/transaction/slack.rb @@ -60,17 +60,18 @@ class Transaction::Slack # if create, send create message / block update messages template = nil sent_value = nil - if @item[:type] == 'create' + case @item[:type] + when 'create' template = 'ticket_create' - elsif @item[:type] == 'update' + when 'update' template = 'ticket_update' - elsif @item[:type] == 'reminder_reached' + when 'reminder_reached' template = 'ticket_reminder_reached' sent_value = ticket.pending_time - elsif @item[:type] == 'escalation' + when 'escalation' template = 'ticket_escalation' sent_value = ticket.escalation_at - elsif @item[:type] == 'escalation_warning' + when 'escalation_warning' template = 'ticket_escalation_warning' sent_value = ticket.escalation_at else diff --git a/app/models/user.rb b/app/models/user.rb index b60157594..03da4f9d3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1058,9 +1058,10 @@ try to find correct name return true if !preferences[:notification_sound] return true if !preferences[:notification_sound][:enabled] - if preferences[:notification_sound][:enabled] == 'true' + case preferences[:notification_sound][:enabled] + when 'true' preferences[:notification_sound][:enabled] = true - elsif preferences[:notification_sound][:enabled] == 'false' + when 'false' preferences[:notification_sound][:enabled] = false end class_name = preferences[:notification_sound][:enabled].class.to_s diff --git a/db/migrate/20170531144425_foreign_keys.rb b/db/migrate/20170531144425_foreign_keys.rb index 66b192657..cd124e74d 100644 --- a/db/migrate/20170531144425_foreign_keys.rb +++ b/db/migrate/20170531144425_foreign_keys.rb @@ -14,25 +14,25 @@ class ForeignKeys < ActiveRecord::Migration[4.2] foreign_keys = [ # Base %i[users organizations], - [:users, :users, column: :created_by_id], - [:users, :users, column: :updated_by_id], + [:users, :users, { column: :created_by_id }], + [:users, :users, { column: :updated_by_id }], - [:signatures, :users, column: :created_by_id], - [:signatures, :users, column: :updated_by_id], + [:signatures, :users, { column: :created_by_id }], + [:signatures, :users, { column: :updated_by_id }], - [:email_addresses, :users, column: :created_by_id], - [:email_addresses, :users, column: :updated_by_id], + [:email_addresses, :users, { column: :created_by_id }], + [:email_addresses, :users, { column: :updated_by_id }], %i[groups signatures], %i[groups email_addresses], - [:groups, :users, column: :created_by_id], - [:groups, :users, column: :updated_by_id], + [:groups, :users, { column: :created_by_id }], + [:groups, :users, { column: :updated_by_id }], - [:roles, :users, column: :created_by_id], - [:roles, :users, column: :updated_by_id], + [:roles, :users, { column: :created_by_id }], + [:roles, :users, { column: :updated_by_id }], - [:organizations, :users, column: :created_by_id], - [:organizations, :users, column: :updated_by_id], + [:organizations, :users, { column: :created_by_id }], + [:organizations, :users, { column: :updated_by_id }], %i[roles_users users], %i[roles_users roles], @@ -45,108 +45,108 @@ class ForeignKeys < ActiveRecord::Migration[4.2] %i[authorizations users], - [:translations, :users, column: :created_by_id], - [:translations, :users, column: :updated_by_id], + [:translations, :users, { column: :created_by_id }], + [:translations, :users, { column: :updated_by_id }], %i[tokens users], - [:packages, :users, column: :created_by_id], - [:packages, :users, column: :updated_by_id], + [:packages, :users, { column: :created_by_id }], + [:packages, :users, { column: :updated_by_id }], %i[taskbars users], %i[tags tag_items], %i[tags tag_objects], - [:tags, :users, column: :created_by_id], + [:tags, :users, { column: :created_by_id }], - [:recent_views, :object_lookups, column: :recent_view_object_id], - [:recent_views, :users, column: :created_by_id], + [:recent_views, :object_lookups, { column: :recent_view_object_id }], + [:recent_views, :users, { column: :created_by_id }], - [:activity_streams, :type_lookups, column: :activity_stream_type_id], - [:activity_streams, :object_lookups, column: :activity_stream_object_id], + [:activity_streams, :type_lookups, { column: :activity_stream_type_id }], + [:activity_streams, :object_lookups, { column: :activity_stream_object_id }], %i[activity_streams permissions], %i[activity_streams groups], - [:activity_streams, :users, column: :created_by_id], + [:activity_streams, :users, { column: :created_by_id }], %i[histories history_types], %i[histories history_objects], %i[histories history_attributes], - [:histories, :users, column: :created_by_id], + [:histories, :users, { column: :created_by_id }], %i[stores store_objects], %i[stores store_files], - [:stores, :users, column: :created_by_id], + [:stores, :users, { column: :created_by_id }], - [:avatars, :users, column: :created_by_id], - [:avatars, :users, column: :updated_by_id], + [:avatars, :users, { column: :created_by_id }], + [:avatars, :users, { column: :updated_by_id }], - [:online_notifications, :users, column: :created_by_id], - [:online_notifications, :users, column: :updated_by_id], + [:online_notifications, :users, { column: :created_by_id }], + [:online_notifications, :users, { column: :updated_by_id }], - [:schedulers, :users, column: :created_by_id], - [:schedulers, :users, column: :updated_by_id], + [:schedulers, :users, { column: :created_by_id }], + [:schedulers, :users, { column: :updated_by_id }], - [:calendars, :users, column: :created_by_id], - [:calendars, :users, column: :updated_by_id], + [:calendars, :users, { column: :created_by_id }], + [:calendars, :users, { column: :updated_by_id }], %i[user_devices users], %i[object_manager_attributes object_lookups], - [:object_manager_attributes, :users, column: :created_by_id], - [:object_manager_attributes, :users, column: :updated_by_id], + [:object_manager_attributes, :users, { column: :created_by_id }], + [:object_manager_attributes, :users, { column: :updated_by_id }], %i[cti_caller_ids users], - [:stats_stores, :users, column: :created_by_id], + [:stats_stores, :users, { column: :created_by_id }], - [:http_logs, :users, column: :created_by_id], - [:http_logs, :users, column: :updated_by_id], + [:http_logs, :users, { column: :created_by_id }], + [:http_logs, :users, { column: :updated_by_id }], # Ticket - [:ticket_state_types, :users, column: :created_by_id], - [:ticket_state_types, :users, column: :updated_by_id], + [:ticket_state_types, :users, { column: :created_by_id }], + [:ticket_state_types, :users, { column: :updated_by_id }], - [:ticket_states, :ticket_state_types, column: :state_type_id], - [:ticket_states, :users, column: :created_by_id], - [:ticket_states, :users, column: :updated_by_id], + [:ticket_states, :ticket_state_types, { column: :state_type_id }], + [:ticket_states, :users, { column: :created_by_id }], + [:ticket_states, :users, { column: :updated_by_id }], - [:ticket_priorities, :users, column: :created_by_id], - [:ticket_priorities, :users, column: :updated_by_id], + [:ticket_priorities, :users, { column: :created_by_id }], + [:ticket_priorities, :users, { column: :updated_by_id }], %i[tickets groups], - [:tickets, :users, column: :owner_id], - [:tickets, :users, column: :customer_id], - [:tickets, :ticket_priorities, column: :priority_id], - [:tickets, :ticket_states, column: :state_id], + [:tickets, :users, { column: :owner_id }], + [:tickets, :users, { column: :customer_id }], + [:tickets, :ticket_priorities, { column: :priority_id }], + [:tickets, :ticket_states, { column: :state_id }], %i[tickets organizations], - [:tickets, :users, column: :created_by_id], - [:tickets, :users, column: :updated_by_id], + [:tickets, :users, { column: :created_by_id }], + [:tickets, :users, { column: :updated_by_id }], - [:ticket_flags, :tickets, column: :ticket_id], - [:ticket_flags, :users, column: :created_by_id], + [:ticket_flags, :tickets, { column: :ticket_id }], + [:ticket_flags, :users, { column: :created_by_id }], - [:ticket_article_types, :users, column: :created_by_id], - [:ticket_article_types, :users, column: :updated_by_id], + [:ticket_article_types, :users, { column: :created_by_id }], + [:ticket_article_types, :users, { column: :updated_by_id }], - [:ticket_article_senders, :users, column: :created_by_id], - [:ticket_article_senders, :users, column: :updated_by_id], + [:ticket_article_senders, :users, { column: :created_by_id }], + [:ticket_article_senders, :users, { column: :updated_by_id }], %i[ticket_articles tickets], - [:ticket_articles, :ticket_article_types, column: :type_id], - [:ticket_articles, :ticket_article_senders, column: :sender_id], - [:ticket_articles, :users, column: :created_by_id], - [:ticket_articles, :users, column: :updated_by_id], - [:ticket_articles, :users, column: :origin_by_id], + [:ticket_articles, :ticket_article_types, { column: :type_id }], + [:ticket_articles, :ticket_article_senders, { column: :sender_id }], + [:ticket_articles, :users, { column: :created_by_id }], + [:ticket_articles, :users, { column: :updated_by_id }], + [:ticket_articles, :users, { column: :origin_by_id }], - [:ticket_article_flags, :ticket_articles, column: :ticket_article_id], - [:ticket_article_flags, :users, column: :created_by_id], + [:ticket_article_flags, :ticket_articles, { column: :ticket_article_id }], + [:ticket_article_flags, :users, { column: :created_by_id }], %i[ticket_time_accountings tickets], %i[ticket_time_accountings ticket_articles], - [:ticket_time_accountings, :users, column: :created_by_id], + [:ticket_time_accountings, :users, { column: :created_by_id }], - [:overviews, :users, column: :created_by_id], - [:overviews, :users, column: :updated_by_id], + [:overviews, :users, { column: :created_by_id }], + [:overviews, :users, { column: :updated_by_id }], %i[overviews_roles overviews], %i[overviews_roles roles], @@ -157,65 +157,65 @@ class ForeignKeys < ActiveRecord::Migration[4.2] %i[overviews_groups overviews], %i[overviews_groups groups], - [:triggers, :users, column: :created_by_id], - [:triggers, :users, column: :updated_by_id], + [:triggers, :users, { column: :created_by_id }], + [:triggers, :users, { column: :updated_by_id }], - [:jobs, :users, column: :created_by_id], - [:jobs, :users, column: :updated_by_id], + [:jobs, :users, { column: :created_by_id }], + [:jobs, :users, { column: :updated_by_id }], %i[links link_types], - [:postmaster_filters, :users, column: :created_by_id], - [:postmaster_filters, :users, column: :updated_by_id], + [:postmaster_filters, :users, { column: :created_by_id }], + [:postmaster_filters, :users, { column: :updated_by_id }], %i[text_modules users], - [:text_modules, :users, column: :created_by_id], - [:text_modules, :users, column: :updated_by_id], + [:text_modules, :users, { column: :created_by_id }], + [:text_modules, :users, { column: :updated_by_id }], %i[text_modules_groups text_modules], %i[text_modules_groups groups], %i[templates users], - [:templates, :users, column: :created_by_id], - [:templates, :users, column: :updated_by_id], + [:templates, :users, { column: :created_by_id }], + [:templates, :users, { column: :updated_by_id }], %i[templates_groups templates], %i[templates_groups groups], %i[channels groups], - [:channels, :users, column: :created_by_id], - [:channels, :users, column: :updated_by_id], + [:channels, :users, { column: :created_by_id }], + [:channels, :users, { column: :updated_by_id }], - [:slas, :users, column: :created_by_id], - [:slas, :users, column: :updated_by_id], + [:slas, :users, { column: :created_by_id }], + [:slas, :users, { column: :updated_by_id }], - [:macros, :users, column: :created_by_id], - [:macros, :users, column: :updated_by_id], + [:macros, :users, { column: :created_by_id }], + [:macros, :users, { column: :updated_by_id }], - [:chats, :users, column: :created_by_id], - [:chats, :users, column: :updated_by_id], + [:chats, :users, { column: :created_by_id }], + [:chats, :users, { column: :updated_by_id }], - [:chat_topics, :users, column: :created_by_id], - [:chat_topics, :users, column: :updated_by_id], + [:chat_topics, :users, { column: :created_by_id }], + [:chat_topics, :users, { column: :updated_by_id }], %i[chat_sessions chats], %i[chat_sessions users], - [:chat_sessions, :users, column: :created_by_id], - [:chat_sessions, :users, column: :updated_by_id], + [:chat_sessions, :users, { column: :created_by_id }], + [:chat_sessions, :users, { column: :updated_by_id }], %i[chat_messages chat_sessions], - [:chat_messages, :users, column: :created_by_id], + [:chat_messages, :users, { column: :created_by_id }], - [:chat_agents, :users, column: :created_by_id], - [:chat_agents, :users, column: :updated_by_id], + [:chat_agents, :users, { column: :created_by_id }], + [:chat_agents, :users, { column: :updated_by_id }], - [:report_profiles, :users, column: :created_by_id], - [:report_profiles, :users, column: :updated_by_id], + [:report_profiles, :users, { column: :created_by_id }], + [:report_profiles, :users, { column: :updated_by_id }], %i[karma_users users], %i[karma_activity_logs users], - [:karma_activity_logs, :karma_activities, column: :activity_id], + [:karma_activity_logs, :karma_activities, { column: :activity_id }], ] foreign_keys.each do |foreign_key| diff --git a/lib/import/exchange/item_attributes.rb b/lib/import/exchange/item_attributes.rb index dcaa80fd0..54b107d80 100644 --- a/lib/import/exchange/item_attributes.rb +++ b/lib/import/exchange/item_attributes.rb @@ -23,11 +23,12 @@ module Import def booleanize_values(properties) properties.each do |key, value| - if value.is_a?(String) + case value + when String next if !%w[true false].include?(value) properties[key] = value == 'true' - elsif value.is_a?(Hash) + when Hash properties[key] = booleanize_values(value) end end diff --git a/lib/notification_factory/mailer.rb b/lib/notification_factory/mailer.rb index 480a55d71..1e9cdad02 100644 --- a/lib/notification_factory/mailer.rb +++ b/lib/notification_factory/mailer.rb @@ -48,9 +48,10 @@ returns owned_by_nobody = false owned_by_me = false - if ticket.owner_id == 1 + case ticket.owner_id + when 1 owned_by_nobody = true - elsif ticket.owner_id == user.id + when user.id owned_by_me = true else # check the replacement chain of max 10 diff --git a/lib/report/article_by_type_sender.rb b/lib/report/article_by_type_sender.rb index ecd4714a3..0d2afca23 100644 --- a/lib/report/article_by_type_sender.rb +++ b/lib/report/article_by_type_sender.rb @@ -23,32 +23,36 @@ returns params = params_origin.dup result = [] - if params[:interval] == 'month' + case params[:interval] + when 'month' stop_interval = 12 - elsif params[:interval] == 'week' + when 'week' stop_interval = 7 - elsif params[:interval] == 'day' + when 'day' stop_interval = 31 - elsif params[:interval] == 'hour' + when 'hour' stop_interval = 24 - elsif params[:interval] == 'minute' + when 'minute' stop_interval = 60 end + + query, bind_params, tables = Ticket.selector2sql(params[:selector]) + sender = Ticket::Article::Sender.lookup(name: params[:params][:sender]) + type = Ticket::Article::Type.lookup(name: params[:params][:type]) + (1..stop_interval).each do |_counter| - if params[:interval] == 'month' + case params[:interval] + when 'month' params[:range_end] = params[:range_start].next_month - elsif params[:interval] == 'week' + when 'week' params[:range_end] = params[:range_start].next_day - elsif params[:interval] == 'day' + when 'day' params[:range_end] = params[:range_start].next_day - elsif params[:interval] == 'hour' + when 'hour' params[:range_end] = params[:range_start] + 1.hour - elsif params[:interval] == 'minute' + when 'minute' params[:range_end] = params[:range_start] + 1.minute end - query, bind_params, tables = Ticket.selector2sql(params[:selector]) - 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( diff --git a/lib/report/ticket_first_solution.rb b/lib/report/ticket_first_solution.rb index 77d4f56d6..f26fa6a2d 100644 --- a/lib/report/ticket_first_solution.rb +++ b/lib/report/ticket_first_solution.rb @@ -19,27 +19,29 @@ returns params = params_origin.dup result = [] - if params[:interval] == 'month' + case params[:interval] + when 'month' stop_interval = 12 - elsif params[:interval] == 'week' + when 'week' stop_interval = 7 - elsif params[:interval] == 'day' + when 'day' stop_interval = 31 - elsif params[:interval] == 'hour' + when 'hour' stop_interval = 24 - elsif params[:interval] == 'minute' + when 'minute' stop_interval = 60 end (1..stop_interval).each do |_counter| - if params[:interval] == 'month' + case params[:interval] + when 'month' params[:range_end] = params[:range_start].next_month - elsif params[:interval] == 'week' + when 'week' params[:range_end] = params[:range_start].next_day - elsif params[:interval] == 'day' + when 'day' params[:range_end] = params[:range_start].next_day - elsif params[:interval] == 'hour' + when 'hour' params[:range_end] = params[:range_start] + 1.hour - elsif params[:interval] == 'minute' + when 'minute' params[:range_end] = params[:range_start] + 1.minute end diff --git a/lib/report/ticket_generic_time.rb b/lib/report/ticket_generic_time.rb index c0c0a4eaf..3d4f0c933 100644 --- a/lib/report/ticket_generic_time.rb +++ b/lib/report/ticket_generic_time.rb @@ -46,15 +46,16 @@ returns selector.merge!(without_merged_tickets) # do not show merged tickets in reports result_es = SearchIndexBackend.selectors('Ticket', selector, {}, aggs_interval) - if params[:interval] == 'month' + case params[:interval] + when 'month' stop_interval = 12 - elsif params[:interval] == 'week' + when 'week' stop_interval = 7 - elsif params[:interval] == 'day' + when 'day' stop_interval = ((params[:range_end] - params[:range_start]) / 86_400).to_i + 1 - elsif params[:interval] == 'hour' + when 'hour' stop_interval = 24 - elsif params[:interval] == 'minute' + when 'minute' stop_interval = 60 end result = [] @@ -80,9 +81,10 @@ returns # only compare date - in certain cases elasticsearch timezone offset will not match replace = ':\d\dZ$' - if params[:interval] == 'month' + case params[:interval] + when 'month' replace = '\d\dT\d\d:\d\d:\d\dZ$' - elsif params[:interval] == 'day' || params[:interval] == 'week' + when 'day', 'week' replace = '\d\d:\d\d:\d\dZ$' end @@ -91,30 +93,32 @@ returns match = true result.push item['doc_count'] - if params[:interval] == 'month' + case params[:interval] + when 'month' params[:range_start] = params[:range_start].next_month - elsif params[:interval] == 'week' + when 'week' params[:range_start] = params[:range_start].next_day - elsif params[:interval] == 'day' + when 'day' params[:range_start] = params[:range_start].next_day - elsif params[:interval] == 'hour' + when 'hour' params[:range_start] = params[:range_start] + 1.hour - elsif params[:interval] == 'minute' + when 'minute' params[:range_start] = params[:range_start] + 1.minute end end next if match result.push 0 - if params[:interval] == 'month' + case params[:interval] + when 'month' params[:range_start] = params[:range_start].next_month - elsif params[:interval] == 'week' + when 'week' params[:range_start] = params[:range_start].next_day - elsif params[:interval] == 'day' + when 'day' params[:range_start] = params[:range_start] + 1.day - elsif params[:interval] == 'hour' + when 'hour' params[:range_start] = params[:range_start] + 1.hour - elsif params[:interval] == 'minute' + when 'minute' params[:range_start] = params[:range_start] + 1.minute end end diff --git a/lib/report/ticket_moved.rb b/lib/report/ticket_moved.rb index 6f113e626..4494b25ff 100644 --- a/lib/report/ticket_moved.rb +++ b/lib/report/ticket_moved.rb @@ -27,27 +27,29 @@ returns end result = [] - if params[:interval] == 'month' + case params[:interval] + when 'month' stop_interval = 12 - elsif params[:interval] == 'week' + when 'week' stop_interval = 7 - elsif params[:interval] == 'day' + when 'day' stop_interval = 31 - elsif params[:interval] == 'hour' + when 'hour' stop_interval = 24 - elsif params[:interval] == 'minute' + when 'minute' stop_interval = 60 end (1..stop_interval).each do |_counter| - if params[:interval] == 'month' + case params[:interval] + when 'month' params[:range_end] = params[:range_start].next_month - elsif params[:interval] == 'week' + when 'week' params[:range_end] = params[:range_start].next_day - elsif params[:interval] == 'day' + when 'day' params[:range_end] = params[:range_start].next_day - elsif params[:interval] == 'hour' + when 'hour' params[:range_end] = params[:range_start] + 1.hour - elsif params[:interval] == 'minute' + when 'minute' params[:range_end] = params[:range_start] + 1.minute end local_params = group_attributes(selector, params) @@ -141,7 +143,8 @@ returns def self.group_attributes(selector, params) group_id = selector['value'] - if selector['operator'] == 'is' + case selector['operator'] + when 'is' if params[:params][:type] == 'in' return { id_not_from: group_id, @@ -153,7 +156,7 @@ returns id_not_to: group_id, } end - elsif selector['operator'] == 'is not' + when 'is not' if params[:params][:type] == 'in' return { id_from: group_id, diff --git a/lib/report/ticket_reopened.rb b/lib/report/ticket_reopened.rb index 5f6594f97..ff38c55e2 100644 --- a/lib/report/ticket_reopened.rb +++ b/lib/report/ticket_reopened.rb @@ -21,27 +21,29 @@ returns ticket_state_ids = ticket_ids result = [] - if params[:interval] == 'month' + case params[:interval] + when 'month' stop_interval = 12 - elsif params[:interval] == 'week' + when 'week' stop_interval = 7 - elsif params[:interval] == 'day' + when 'day' stop_interval = 31 - elsif params[:interval] == 'hour' + when 'hour' stop_interval = 24 - elsif params[:interval] == 'minute' + when 'minute' stop_interval = 60 end (1..stop_interval).each do |_counter| - if params[:interval] == 'month' + case params[:interval] + when 'month' params[:range_end] = params[:range_start].next_month - elsif params[:interval] == 'week' + when 'week' params[:range_end] = params[:range_start].next_day - elsif params[:interval] == 'day' + when 'day' params[:range_end] = params[:range_start].next_day - elsif params[:interval] == 'hour' + when 'hour' params[:range_end] = params[:range_start] + 1.hour - elsif params[:interval] == 'minute' + when 'minute' params[:range_end] = params[:range_start] + 1.minute end diff --git a/lib/search_index_backend.rb b/lib/search_index_backend.rb index 098f73902..195dda2b9 100644 --- a/lib/search_index_backend.rb +++ b/lib/search_index_backend.rb @@ -524,33 +524,36 @@ example for aggregations within one year end # is/is not/contains/contains not - if data['operator'] == 'is' || data['operator'] == 'is not' || data['operator'] == 'contains' || data['operator'] == 'contains not' + case data['operator'] + when 'is', 'is not', 'contains', 'contains not' t[wildcard_or_term] = {} t[wildcard_or_term][key_tmp] = data['value'] - if data['operator'] == 'is' || data['operator'] == 'contains' + case data['operator'] + when 'is', 'contains' query_must.push t - elsif data['operator'] == 'is not' || data['operator'] == 'contains not' + when 'is not', 'contains not' query_must_not.push t end - elsif data['operator'] == 'contains all' || data['operator'] == 'contains one' || data['operator'] == 'contains all not' || data['operator'] == 'contains one not' + when 'contains all', 'contains one', 'contains all not', 'contains one not' values = data['value'].split(',').map(&:strip) t[:query_string] = {} - if data['operator'] == 'contains all' + case data['operator'] + when 'contains all' t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" AND "')}\"" query_must.push t - elsif data['operator'] == 'contains one not' + when 'contains one not' t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" OR "')}\"" query_must_not.push t - elsif data['operator'] == 'contains one' + when 'contains one' t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" OR "')}\"" query_must.push t - elsif data['operator'] == 'contains all not' + when 'contains all not' t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" AND "')}\"" query_must_not.push t end # within last/within next (relative) - elsif data['operator'] == 'within last (relative)' || data['operator'] == 'within next (relative)' + when 'within last (relative)', 'within next (relative)' range = relative_map[data['range'].to_sym] if range.blank? raise "Invalid relative_map for range '#{data['range']}'." @@ -566,7 +569,7 @@ example for aggregations within one year query_must.push t # before/after (relative) - elsif data['operator'] == 'before (relative)' || data['operator'] == 'after (relative)' + when 'before (relative)', 'after (relative)' range = relative_map[data['range'].to_sym] if range.blank? raise "Invalid relative_map for range '#{data['range']}'." @@ -582,7 +585,7 @@ example for aggregations within one year query_must.push t # before/after (absolute) - elsif data['operator'] == 'before (absolute)' || data['operator'] == 'after (absolute)' + when 'before (absolute)', 'after (absolute)' t[:range] = {} t[:range][key_tmp] = {} if data['operator'] == 'before (absolute)' diff --git a/lib/sessions.rb b/lib/sessions.rb index 61189f3aa..05ef88f54 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -794,9 +794,10 @@ returns # we use it in rails and non rails context def self.log(level, message) if defined?(Rails) - if level == 'debug' + case level + when 'debug' Rails.logger.debug { message } - elsif level == 'notice' + when 'notice' Rails.logger.notice message else Rails.logger.error message diff --git a/lib/static_assets.rb b/lib/static_assets.rb index fce2405b0..1dcd2d42e 100644 --- a/lib/static_assets.rb +++ b/lib/static_assets.rb @@ -145,13 +145,14 @@ generate filename based on Store model def self.filename(file) hash = Digest::MD5.hexdigest(file.content) extention = '' - if file.preferences['Content-Type'].match?(/jpg|jpeg/i) + case file.preferences['Content-Type'] + when /jpg|jpeg/i extention = '.jpg' - elsif file.preferences['Content-Type'].match?(/png/i) + when /png/i extention = '.png' - elsif file.preferences['Content-Type'].match?(/gif/i) + when /gif/i extention = '.gif' - elsif file.preferences['Content-Type'].match?(/svg/i) + when /svg/i extention = '.svg' end "#{hash}#{extention}" diff --git a/lib/twitter_sync.rb b/lib/twitter_sync.rb index 7e7307d45..f3d0885c7 100644 --- a/lib/twitter_sync.rb +++ b/lib/twitter_sync.rb @@ -480,7 +480,8 @@ create a tweet or direct message from an article def from_article(article) tweet = nil - if article[:type] == 'twitter direct-message' + case article[:type] + when 'twitter direct-message' Rails.logger.debug { "Create twitter direct message from article to '#{article[:to]}'..." } @@ -509,7 +510,7 @@ create a tweet or direct message from an article tweet = Twitter::REST::Request.new(@client, :json_post, '/1.1/direct_messages/events/new.json', data).perform - elsif article[:type] == 'twitter status' + when 'twitter status' Rails.logger.debug { 'Create tweet from article...' } diff --git a/spec/lib/sessions/event/chat_session_start_spec.rb b/spec/lib/sessions/event/chat_session_start_spec.rb index a8e2eba5d..2e98b16a9 100644 --- a/spec/lib/sessions/event/chat_session_start_spec.rb +++ b/spec/lib/sessions/event/chat_session_start_spec.rb @@ -77,10 +77,10 @@ RSpec.describe Sessions::Event::ChatSessionStart do messages = Sessions.queue(client_id) expect(messages.count).to eq(1) expect(messages).to eq([ - 'event' => 'chat_error', - 'data' => { - 'state' => 'no_permission' - } + { 'event' => 'chat_error', + 'data' => { + 'state' => 'no_permission' + } } ]) end end diff --git a/spec/lib/sessions/event/chat_transfer_spec.rb b/spec/lib/sessions/event/chat_transfer_spec.rb index 9057656fa..f125eb7a6 100644 --- a/spec/lib/sessions/event/chat_transfer_spec.rb +++ b/spec/lib/sessions/event/chat_transfer_spec.rb @@ -53,10 +53,10 @@ RSpec.describe Sessions::Event::ChatTransfer do messages = Sessions.queue(client_id) expect(messages.count).to eq(1) expect(messages).to eq([ - 'event' => 'chat_error', - 'data' => { - 'state' => 'no_permission' - } + { 'event' => 'chat_error', + 'data' => { + 'state' => 'no_permission' + } } ]) end end diff --git a/spec/requests/ticket/article_spec.rb b/spec/requests/ticket/article_spec.rb index a24e7ae91..531d5c9b4 100644 --- a/spec/requests/ticket/article_spec.rb +++ b/spec/requests/ticket/article_spec.rb @@ -84,9 +84,9 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO body: 'some body', type: 'note', attachments: [ - 'filename' => 'some_file.txt', - 'data' => 'dGVzdCAxMjM=', - 'mime-type' => 'text/plain', + { 'filename' => 'some_file.txt', + 'data' => 'dGVzdCAxMjM=', + 'mime-type' => 'text/plain' }, ], } post '/api/v1/ticket_articles', params: params, as: :json diff --git a/spec/requests/ticket_spec.rb b/spec/requests/ticket_spec.rb index 4f977c6d6..4af02f2d8 100644 --- a/spec/requests/ticket_spec.rb +++ b/spec/requests/ticket_spec.rb @@ -429,9 +429,9 @@ RSpec.describe 'Ticket', type: :request do subject: 'some test 123', body: 'some test 123', attachments: [ - 'filename' => 'some_file.txt', - 'data' => 'dGVzdCAxMjM=', - 'mime-type' => 'text/plain', + { 'filename' => 'some_file.txt', + 'data' => 'dGVzdCAxMjM=', + 'mime-type' => 'text/plain' }, ], }, } @@ -506,9 +506,9 @@ RSpec.describe 'Ticket', type: :request do subject: 'some test 123', body: 'some test 123', attachments: [ - 'filename' => 'some_file.txt', - 'data' => 'ABC_INVALID_BASE64', - 'mime-type' => 'text/plain', + { 'filename' => 'some_file.txt', + 'data' => 'ABC_INVALID_BASE64', + 'mime-type' => 'text/plain' }, ], }, } @@ -528,9 +528,9 @@ RSpec.describe 'Ticket', type: :request do subject: 'some test 123', body: 'some test 123', attachments: [ - 'filename' => 'some_file.txt', - 'data' => "LARGE_INVALID_BASE64_#{'#' * 20_000_000}", - 'mime-type' => 'text/plain', + { 'filename' => 'some_file.txt', + 'data' => "LARGE_INVALID_BASE64_#{'#' * 20_000_000}", + 'mime-type' => 'text/plain' }, ], }, } @@ -550,9 +550,9 @@ RSpec.describe 'Ticket', type: :request do subject: 'some test 123', body: 'some test 123', attachments: [ - 'filename' => 'some_file.txt', - 'data' => Base64.encode64('a' * 1_000), - 'mime-type' => 'text/plain', + { 'filename' => 'some_file.txt', + 'data' => Base64.encode64('a' * 1_000), + 'mime-type' => 'text/plain' }, ], }, } @@ -576,9 +576,9 @@ RSpec.describe 'Ticket', type: :request do subject: 'some test 123', body: 'some test 123', attachments: [ - 'filename' => 'some_file.txt', - 'data' => Base64.strict_encode64('a' * 1_000), - 'mime-type' => 'text/plain', + { 'filename' => 'some_file.txt', + 'data' => Base64.strict_encode64('a' * 1_000), + 'mime-type' => 'text/plain' }, ], }, } @@ -602,8 +602,8 @@ RSpec.describe 'Ticket', type: :request do subject: 'some test 123', body: 'some test 123', attachments: [ - 'filename' => 'some_file.txt', - 'data' => 'dGVzdCAxMjM=', + { 'filename' => 'some_file.txt', + 'data' => 'dGVzdCAxMjM=' }, ], }, } @@ -665,9 +665,9 @@ RSpec.describe 'Ticket', type: :request do body: 'some test 123 ', attachments: [ - 'filename' => 'some_file.txt', - 'data' => 'dGVzdCAxMjM=', - 'mime-type' => 'text/plain', + { 'filename' => 'some_file.txt', + 'data' => 'dGVzdCAxMjM=', + 'mime-type' => 'text/plain' }, ], }, } diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 2602a352d..c221cd665 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -41,7 +41,8 @@ class TestCase < ActiveSupport::TestCase def profile browser_profile = nil - if browser == 'firefox' + case browser + when 'firefox' browser_profile = Selenium::WebDriver::Firefox::Profile.new browser_profile['intl.locale.matchOS'] = false @@ -50,7 +51,7 @@ class TestCase < ActiveSupport::TestCase # currently console log not working for firefox # https://github.com/SeleniumHQ/selenium/issues/1161 #browser_profile['loggingPref'] = { browser: :all } - elsif browser == 'chrome' + when 'chrome' # profile are only working on remote selenium if ENV['REMOTE_URL'] @@ -89,10 +90,11 @@ class TestCase < ActiveSupport::TestCase profile: profile, } if ENV['BROWSER_HEADLESS'].present? - if browser == 'firefox' + case browser + when 'firefox' params[:options] = Selenium::WebDriver::Firefox::Options.new params[:options].add_argument('-headless') - elsif browser == 'chrome' + when 'chrome' params[:options] = Selenium::WebDriver::Chrome::Options.new params[:options].add_argument('-headless') end @@ -3084,17 +3086,18 @@ wait untill text in selector disabppears end if data[:role] - if data[:role] == 'Admin' + case data[:role] + when 'Admin' check( browser: instance, css: '.modal input[name=role_ids][value=1]', ) - elsif data[:role] == 'Customer' + when 'Customer' check( browser: instance, css: '.modal input[name=role_ids][value=3]', ) - elsif data[:role] == 'Agent' + when 'Agent' check( browser: instance, css: '.modal input[name=role_ids][value=2]', @@ -3251,17 +3254,18 @@ wait untill text in selector disabppears end if data[:role] - if data[:role] == 'Admin' + case data[:role] + when 'Admin' check( browser: instance, css: '.modal input[name=role_ids][value=1]', ) - elsif data[:role] == 'Customer' + when 'Customer' check( browser: instance, css: '.modal input[name=role_ids][value=3]', ) - elsif data[:role] == 'Agent' + when 'Agent' check( browser: instance, css: '.modal input[name=role_ids][value=2]', @@ -4718,7 +4722,8 @@ wait untill text in selector disabppears if data[:data_option] if data[:data_option][:options] - if data[:data_type] == 'Boolean' + case data[:data_type] + when 'Boolean' # rubocop:disable Lint/BooleanSymbol element = instance.find_elements(css: '.modal .js-valueTrue').first element.clear @@ -4727,7 +4732,7 @@ wait untill text in selector disabppears element.clear element.send_keys(data[:data_option][:options][:false]) # rubocop:enable Lint/BooleanSymbol - elsif data[:data_type] == 'Tree Select' + when 'Tree Select' add_tree_options( instance: instance, options: data[:data_option][:options], diff --git a/test/integration/package_test.rb b/test/integration/package_test.rb index 51edd823f..0385228a5 100644 --- a/test/integration/package_test.rb +++ b/test/integration/package_test.rb @@ -302,7 +302,8 @@ class PackageTest < ActiveSupport::TestCase ] tests.each do |test| - if test[:action] == 'install' + case test[:action] + when 'install' begin package = Package.install(string: test[:zpm]) rescue => e @@ -315,7 +316,7 @@ class PackageTest < ActiveSupport::TestCase else assert_not(package, 'install package successful but should not') end - elsif test[:action] == 'reinstall' + when 'reinstall' begin package = Package.reinstall(test[:name]) rescue @@ -328,7 +329,7 @@ class PackageTest < ActiveSupport::TestCase else assert_not(package, 'reinstall package successful but should not') end - elsif test[:action] == 'uninstall' + when 'uninstall' if test[:zpm] begin package = Package.uninstall(string: test[:zpm]) @@ -347,7 +348,7 @@ class PackageTest < ActiveSupport::TestCase else assert_not(package, 'uninstall package successful but should not') end - elsif test[:action] == 'auto_install' + when 'auto_install' if test[:zpm] if !File.exist?(Rails.root.to_s + '/auto_install/') Dir.mkdir(Rails.root.to_s + '/auto_install/', 0o755) diff --git a/test/unit/email_build_test.rb b/test/unit/email_build_test.rb index 97391c9bf..f527584d3 100644 --- a/test/unit/email_build_test.rb +++ b/test/unit/email_build_test.rb @@ -89,12 +89,13 @@ class EmailBuildTest < ActiveSupport::TestCase # check attachments data[:attachments]&.each do |attachment| - if attachment[:filename] == 'message.html' + case attachment[:filename] + when 'message.html' assert_nil(attachment[:preferences]['Content-ID']) assert_equal(true, attachment[:preferences]['content-alternative']) assert_equal('text/html', attachment[:preferences]['Mime-Type']) assert_equal('UTF-8', attachment[:preferences]['Charset']) - elsif attachment[:filename] == 'somename.png' + when 'somename.png' assert_nil(attachment[:preferences]['Content-ID']) assert_nil(attachment[:preferences]['content-alternative']) assert_equal('image/png', attachment[:preferences]['Mime-Type'])