From b3b76acc8934c1aebae322cc5fda4168dfc6267e Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 7 May 2015 09:23:16 +0200 Subject: [PATCH] Corrected with rubocop cop 'Style/WordArray'. --- .rubocop.yml | 5 -- app/controllers/ical_tickets_controller.rb | 5 +- app/controllers/search_controller.rb | 2 +- app/models/application_model/assets.rb | 2 +- .../application_model/search_index_base.rb | 2 +- app/models/channel/email_parser.rb | 2 +- app/models/object_manager.rb | 4 +- app/models/observer/user/geo.rb | 4 +- app/models/organization/assets.rb | 2 +- app/models/package.rb | 2 +- app/models/ticket/article/assets.rb | 2 +- app/models/ticket/assets.rb | 2 +- app/models/ticket/screen_options.rb | 2 +- app/models/ticket/search_index.rb | 2 +- app/models/ticket/state.rb | 2 +- app/models/user/assets.rb | 2 +- app/models/user/search_index.rb | 2 +- db/migrate/20130817000001_update_auth.rb | 2 +- ...000001_update_overview_and_ticket_state.rb | 6 +-- db/migrate/20150206000002_create_address.rb | 2 +- db/migrate/20150223000001_update_overview2.rb | 6 +-- db/seeds.rb | 50 +++++++++---------- lib/auto_wizard.rb | 2 +- test/unit/assets_test.rb | 2 +- test/unit/auth_test.rb | 2 +- test/unit/rest_test.rb | 2 +- test/unit/session_basic_test.rb | 4 +- test/unit/session_collections_test.rb | 2 +- test/unit/ticket_sla_test.rb | 2 +- 29 files changed, 59 insertions(+), 67 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 4287d55ce..3b8d266ea 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -215,11 +215,6 @@ Style/SignalException: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#fail-method' Enabled: false -Style/WordArray: - Description: 'Use %w or %W for arrays of words.' - StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-w' - Enabled: false - Metrics/AbcSize: Description: >- A calculated magnitude based on number of assignments, diff --git a/app/controllers/ical_tickets_controller.rb b/app/controllers/ical_tickets_controller.rb index a54513bb4..ce4caa5a2 100644 --- a/app/controllers/ical_tickets_controller.rb +++ b/app/controllers/ical_tickets_controller.rb @@ -75,10 +75,7 @@ class IcalTicketsController < ApplicationController 'tickets.owner_id' => current_user.id, 'tickets.state_id' => Ticket::State.where( state_type_id: Ticket::StateType.where( - name: [ - 'new', - 'open', - ], + name: %w(new open), ), ), } diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index f98623c37..a7e5e3529 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -20,7 +20,7 @@ class SearchController < ApplicationController assets = {} result = [] if SearchIndexBackend.enabled? - items = SearchIndexBackend.search( query, limit, ['User', 'Organization'] ) + items = SearchIndexBackend.search( query, limit, %w(User Organization) ) items.each { |item| require item[:type].to_filename record = Kernel.const_get( item[:type] ).find( item[:id] ) diff --git a/app/models/application_model/assets.rb b/app/models/application_model/assets.rb index b20fb8ab9..ac7a3dbec 100644 --- a/app/models/application_model/assets.rb +++ b/app/models/application_model/assets.rb @@ -30,7 +30,7 @@ returns end return data if !self['created_by_id'] && !self['updated_by_id'] - ['created_by_id', 'updated_by_id'].each {|item| + %w(created_by_id updated_by_id).each {|item| next if !self[ item ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] user = User.lookup( id: self[ item ] ) diff --git a/app/models/application_model/search_index_base.rb b/app/models/application_model/search_index_base.rb index 41a253f19..a4eaff4c8 100644 --- a/app/models/application_model/search_index_base.rb +++ b/app/models/application_model/search_index_base.rb @@ -72,7 +72,7 @@ returns def search_index_data attributes = {} - ['name', 'note'].each { |key| + %w(name note).each { |key| if self[key] && !self[key].empty? attributes[key] = self[key] end diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index f519ee85d..4491f8241 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -503,7 +503,7 @@ class Channel::EmailParser roles = Role.where( name: 'Customer' ) # fillup - ['firstname', 'lastname'].each { |item| + %w(firstname lastname).each { |item| if data[item.to_sym] == nil data[item.to_sym] = '' end diff --git a/app/models/object_manager.rb b/app/models/object_manager.rb index 5fcfc773c..aafd10ff5 100644 --- a/app/models/object_manager.rb +++ b/app/models/object_manager.rb @@ -11,7 +11,7 @@ list all backend managed object =end def self.list_objects - ['Ticket', 'TicketArticle', 'User', 'Organization', 'Group' ] + %w(Ticket TicketArticle User Organization Group) end =begin @@ -23,7 +23,7 @@ list all frontend managed object =end def self.list_frontend_objects - ['Ticket', 'User', 'Organization' ] #, 'Group' ] + %w(Ticket User Organization) #, 'Group' ] end end diff --git a/app/models/observer/user/geo.rb b/app/models/observer/user/geo.rb index 15d874b08..959c67472 100644 --- a/app/models/observer/user/geo.rb +++ b/app/models/observer/user/geo.rb @@ -13,7 +13,7 @@ class Observer::User::Geo < ActiveRecord::Observer # check if geo need to be updated def check_geo(record) - location = ['street', 'zip', 'city', 'country'] + location = %w(street zip city country) # check if geo update is needed based on old/new location if record.id @@ -42,7 +42,7 @@ class Observer::User::Geo < ActiveRecord::Observer # update geo data of user def geo_update(record) address = '' - location = ['street', 'zip', 'city', 'country'] + location = %w(street zip city country) location.each { |item| if record[item] && record[item] != '' address = address + ',' + record[item] diff --git a/app/models/organization/assets.rb b/app/models/organization/assets.rb index b146372c2..d5417a19c 100644 --- a/app/models/organization/assets.rb +++ b/app/models/organization/assets.rb @@ -40,7 +40,7 @@ returns } end end - ['created_by_id', 'updated_by_id'].each {|item| + %w(created_by_id updated_by_id).each {|item| next if !self[ item ] if !data[ User.to_app_model ][ self[ item ] ] user = User.lookup( id: self[ item ] ) diff --git a/app/models/package.rb b/app/models/package.rb index 800fb8e35..6db62f8d9 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -311,7 +311,7 @@ class Package < ApplicationModel # reload .rb files in case they have changed def self.reload_classes - ['app', 'lib'].each {|dir| + %w(app lib).each {|dir| Dir.glob( Rails.root.join( dir + '/**/*') ).each {|entry| if entry =~ /\.rb$/ begin diff --git a/app/models/ticket/article/assets.rb b/app/models/ticket/article/assets.rb index 355b21ab5..4e297749e 100644 --- a/app/models/ticket/article/assets.rb +++ b/app/models/ticket/article/assets.rb @@ -41,7 +41,7 @@ returns data[ Ticket::Article.to_app_model ][ self.id ]['attachments'] = self.attachments end - ['created_by_id', 'updated_by_id'].each {|item| + %w(created_by_id updated_by_id).each {|item| next if !self[ item ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] user = User.lookup( id: self[ item ] ) diff --git a/app/models/ticket/assets.rb b/app/models/ticket/assets.rb index cf31c19ea..2a14711eb 100644 --- a/app/models/ticket/assets.rb +++ b/app/models/ticket/assets.rb @@ -29,7 +29,7 @@ returns if !data[ Ticket.to_app_model ][ self.id ] data[ Ticket.to_app_model ][ self.id ] = self.attributes_with_associations end - ['created_by_id', 'updated_by_id', 'owner_id', 'customer_id'].each {|item| + %w(created_by_id updated_by_id owner_id customer_id).each {|item| next if !self[ item ] if !data[ User.to_app_model ] || !data[ User.to_app_model ][ self[ item ] ] user = User.lookup( id: self[ item ] ) diff --git a/app/models/ticket/screen_options.rb b/app/models/ticket/screen_options.rb index 453968b64..1f4cdd42d 100644 --- a/app/models/ticket/screen_options.rb +++ b/app/models/ticket/screen_options.rb @@ -83,7 +83,7 @@ returns type_ids = [] if params[:ticket] - types = ['note', 'phone'] + types = %w(note phone) if params[:ticket].group.email_address_id types.push 'email' end diff --git a/app/models/ticket/search_index.rb b/app/models/ticket/search_index.rb index 3a1f7a7cd..91f7d17cb 100644 --- a/app/models/ticket/search_index.rb +++ b/app/models/ticket/search_index.rb @@ -63,7 +63,7 @@ returns article_attributes = article.attributes # remove note needed attributes - ignore = ['created_by_id', 'updated_by_id', 'updated_at', 'references', 'message_id_md5', 'message_id', 'in_reply_to', 'ticket_id'] + ignore = %w(created_by_id updated_by_id updated_at references message_id_md5 message_id in_reply_to ticket_id) ignore.each {|attribute| article_attributes.delete( attribute ) } diff --git a/app/models/ticket/state.rb b/app/models/ticket/state.rb index b43c168dd..a38866f51 100644 --- a/app/models/ticket/state.rb +++ b/app/models/ticket/state.rb @@ -46,7 +46,7 @@ returns: =end def ignore_escalation? - ignore_escalation = ['removed', 'closed', 'merged'] + ignore_escalation = %w(removed closed merged) return true if ignore_escalation.include?( self.name ) false end diff --git a/app/models/user/assets.rb b/app/models/user/assets.rb index 962f88d2c..0c12df87d 100644 --- a/app/models/user/assets.rb +++ b/app/models/user/assets.rb @@ -74,7 +74,7 @@ returns data = organization.assets( data ) end end - ['created_by_id', 'updated_by_id'].each {|item| + %w(created_by_id updated_by_id).each {|item| next if !self[ item ] if !data[ User.to_app_model ][ self[ item ] ] user = User.lookup( id: self[ item ] ) diff --git a/app/models/user/search_index.rb b/app/models/user/search_index.rb index 736be53a8..5baa99a71 100644 --- a/app/models/user/search_index.rb +++ b/app/models/user/search_index.rb @@ -18,7 +18,7 @@ returns def search_index_data attributes = { 'fullname' => "#{ self['firstname'] } #{ self['lastname'] }" } - ['login', 'firstname', 'lastname', 'phone', 'email', 'city', 'country', 'note', 'created_at'].each { |key| + %w(login firstname lastname phone email city country note created_at).each { |key| if self[key] && (!self.respond_to?('empty?') || !self[key].empty?) attributes[key] = self[key] end diff --git a/db/migrate/20130817000001_update_auth.rb b/db/migrate/20130817000001_update_auth.rb index 96903113b..d7cdd5e0a 100644 --- a/db/migrate/20130817000001_update_auth.rb +++ b/db/migrate/20130817000001_update_auth.rb @@ -35,7 +35,7 @@ class UpdateAuth < ActiveRecord::Migration uid: 'mail', base: 'dc=example,dc=org', always_filter: '', - always_roles: ['Admin', 'Agent'], + always_roles: %w(Admin Agent), always_groups: ['Users'], sync_params: { firstname: 'sn', diff --git a/db/migrate/20150112000001_update_overview_and_ticket_state.rb b/db/migrate/20150112000001_update_overview_and_ticket_state.rb index 2c627400e..80bbe28d2 100644 --- a/db/migrate/20150112000001_update_overview_and_ticket_state.rb +++ b/db/migrate/20150112000001_update_overview_and_ticket_state.rb @@ -23,9 +23,9 @@ class UpdateOverviewAndTicketState < ActiveRecord::Migration direction: 'ASC', }, view: { - d: [ 'title', 'customer', 'group', 'created_at' ], - s: [ 'title', 'customer', 'group', 'created_at' ], - m: [ 'number', 'title', 'customer', 'group', 'created_at' ], + d: %w(title customer group created_at), + s: %w(title customer group created_at), + m: %w(number title customer group created_at), view_mode_default: 's', }, ) diff --git a/db/migrate/20150206000002_create_address.rb b/db/migrate/20150206000002_create_address.rb index 0e2466b29..96a34e330 100644 --- a/db/migrate/20150206000002_create_address.rb +++ b/db/migrate/20150206000002_create_address.rb @@ -19,7 +19,7 @@ class CreateAddress < ActiveRecord::Migration end } - ['street', 'zip', 'city', 'department'].each {|attribute_name| + %w(street zip city department).each {|attribute_name| attribute = ObjectManager::Attribute.get( object: 'User', name: attribute_name, diff --git a/db/migrate/20150223000001_update_overview2.rb b/db/migrate/20150223000001_update_overview2.rb index 7d87c3fb9..6ee9eca81 100644 --- a/db/migrate/20150223000001_update_overview2.rb +++ b/db/migrate/20150223000001_update_overview2.rb @@ -20,9 +20,9 @@ class UpdateOverview2 < ActiveRecord::Migration direction: 'ASC', }, view: { - d: [ 'title', 'customer', 'group', 'created_at' ], - s: [ 'title', 'customer', 'group', 'created_at' ], - m: [ 'number', 'title', 'customer', 'group', 'created_at' ], + d: %w(title customer group created_at), + s: %w(title customer group created_at), + m: %w(number title customer group created_at), view_mode_default: 's', }, ) diff --git a/db/seeds.rb b/db/seeds.rb index 2b5b06a8f..0c4e2b6b9 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -363,7 +363,7 @@ Setting.create_if_not_exists( uid: 'mail', base: 'dc=example,dc=org', always_filter: '', - always_roles: ['Admin', 'Agent'], + always_roles: %w(Admin Agent), always_groups: ['Users'], sync_params: { firstname: 'sn', @@ -1432,9 +1432,9 @@ Overview.create_if_not_exists( direction: 'ASC', }, view: { - d: [ 'title', 'customer', 'group', 'created_at' ], - s: [ 'title', 'customer', 'group', 'created_at' ], - m: [ 'number', 'title', 'customer', 'group', 'created_at' ], + d: %w(title customer group created_at), + s: %w(title customer group created_at), + m: %w(number title customer group created_at), view_mode_default: 's', }, ) @@ -1454,9 +1454,9 @@ Overview.create_if_not_exists( direction: 'ASC', }, view: { - d: [ 'title', 'customer', 'group', 'created_at' ], - s: [ 'title', 'customer', 'group', 'created_at' ], - m: [ 'number', 'title', 'customer', 'group', 'created_at' ], + d: %w(title customer group created_at), + s: %w(title customer group created_at), + m: %w(number title customer group created_at), view_mode_default: 's', }, ) @@ -1475,9 +1475,9 @@ Overview.create_if_not_exists( direction: 'ASC', }, view: { - d: [ 'title', 'customer', 'group', 'created_at' ], - s: [ 'title', 'customer', 'group', 'created_at' ], - m: [ 'number', 'title', 'customer', 'group', 'created_at' ], + d: %w(title customer group created_at), + s: %w(title customer group created_at), + m: %w(number title customer group created_at), view_mode_default: 's', }, ) @@ -1495,9 +1495,9 @@ Overview.create_if_not_exists( direction: 'ASC', }, view: { - d: [ 'title', 'customer', 'group', 'state', 'owner', 'created_at' ], - s: [ 'title', 'customer', 'group', 'state', 'owner', 'created_at' ], - m: [ 'number', 'title', 'customer', 'group', 'state', 'owner', 'created_at' ], + d: %w(title customer group state owner created_at), + s: %w(title customer group state owner created_at), + m: %w(number title customer group state owner created_at), view_mode_default: 's', }, ) @@ -1516,9 +1516,9 @@ Overview.create_if_not_exists( direction: 'ASC', }, view: { - d: [ 'title', 'customer', 'group', 'owner', 'created_at' ], - s: [ 'title', 'customer', 'group', 'owner', 'created_at' ], - m: [ 'number', 'title', 'customer', 'group', 'owner', 'created_at' ], + d: %w(title customer group owner created_at), + s: %w(title customer group owner created_at), + m: %w(number title customer group owner created_at), view_mode_default: 's', }, ) @@ -1536,9 +1536,9 @@ Overview.create_if_not_exists( direction: 'ASC', }, view: { - d: [ 'title', 'customer', 'group', 'owner', 'escalation_time' ], - s: [ 'title', 'customer', 'group', 'owner', 'escalation_time' ], - m: [ 'number', 'title', 'customer', 'group', 'owner', 'escalation_time' ], + d: %w(title customer group owner escalation_time), + s: %w(title customer group owner escalation_time), + m: %w(number title customer group owner escalation_time), view_mode_default: 's', }, ) @@ -1558,9 +1558,9 @@ Overview.create_if_not_exists( direction: 'DESC', }, view: { - d: [ 'title', 'customer', 'state', 'created_at' ], - s: [ 'number', 'title', 'state', 'created_at' ], - m: [ 'number', 'title', 'state', 'created_at' ], + d: %w(title customer state created_at), + s: %w(number title state created_at), + m: %w(number title state created_at), view_mode_default: 's', }, ) @@ -1579,9 +1579,9 @@ Overview.create_if_not_exists( direction: 'DESC', }, view: { - d: [ 'title', 'customer', 'state', 'created_at' ], - s: [ 'number', 'title', 'customer', 'state', 'created_at' ], - m: [ 'number', 'title', 'customer', 'state', 'created_at' ], + d: %w(title customer state created_at), + s: %w(number title customer state created_at), + m: %w(number title customer state created_at), view_mode_default: 's', }, ) diff --git a/lib/auto_wizard.rb b/lib/auto_wizard.rb index c3ed73378..c8bafe2c4 100644 --- a/lib/auto_wizard.rb +++ b/lib/auto_wizard.rb @@ -34,7 +34,7 @@ returns # create Users if auto_wizard_hash['Users'] - roles = Role.where( name: ['Agent', 'Admin'] ) + roles = Role.where( name: %w(Agent Admin) ) groups = Group.all auto_wizard_hash['Users'].each { |user_data| diff --git a/test/unit/assets_test.rb b/test/unit/assets_test.rb index d499e0434..52e90ec5f 100644 --- a/test/unit/assets_test.rb +++ b/test/unit/assets_test.rb @@ -4,7 +4,7 @@ require 'test_helper' class AssetsTest < ActiveSupport::TestCase test 'user' do - roles = Role.where( name: [ 'Agent', 'Admin'] ) + roles = Role.where( name: %w(Agent Admin) ) groups = Group.all org = Organization.create_or_update( name: 'some org', diff --git a/test/unit/auth_test.rb b/test/unit/auth_test.rb index 0227e8fb6..2f30d0d38 100644 --- a/test/unit/auth_test.rb +++ b/test/unit/auth_test.rb @@ -15,7 +15,7 @@ Setting.create_or_update( uid: 'mail', base: 'dc=example,dc=org', always_filter: '', - always_roles: ['Admin', 'Agent'], + always_roles: %w(Admin Agent), always_groups: ['Users'], sync_params: { firstname: 'sn', diff --git a/test/unit/rest_test.rb b/test/unit/rest_test.rb index eb64ae390..37ef2ceeb 100644 --- a/test/unit/rest_test.rb +++ b/test/unit/rest_test.rb @@ -12,7 +12,7 @@ class RestTest < ActiveSupport::TestCase end # create agent - roles = Role.where( name: ['Admin', 'Agent'] ) + roles = Role.where( name: %w(Admin Agent) ) groups = Group.all UserInfo.current_user_id = 1 diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index 18f16782b..02e53a465 100644 --- a/test/unit/session_basic_test.rb +++ b/test/unit/session_basic_test.rb @@ -181,7 +181,7 @@ class SessionBasicTest < ActiveSupport::TestCase end user = User.lookup(id: 1) - roles = Role.where( name: [ 'Agent', 'Admin'] ) + roles = Role.where( name: %w(Agent Admin) ) user.roles = roles user.save @@ -258,7 +258,7 @@ class SessionBasicTest < ActiveSupport::TestCase test 'c activity stream' do # create users - roles = Role.where( name: [ 'Agent', 'Admin'] ) + roles = Role.where( name: %w(Agent Admin) ) groups = Group.all UserInfo.current_user_id = 2 diff --git a/test/unit/session_collections_test.rb b/test/unit/session_collections_test.rb index 639f84dd9..f570f39b9 100644 --- a/test/unit/session_collections_test.rb +++ b/test/unit/session_collections_test.rb @@ -9,7 +9,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase UserInfo.current_user_id = 1 # create users - roles = Role.where( name: [ 'Agent', 'Admin'] ) + roles = Role.where( name: %w(Agent Admin) ) groups = Group.all agent1 = User.create_or_update( diff --git a/test/unit/ticket_sla_test.rb b/test/unit/ticket_sla_test.rb index b032d94b1..d1d2caccf 100644 --- a/test/unit/ticket_sla_test.rb +++ b/test/unit/ticket_sla_test.rb @@ -49,7 +49,7 @@ class TicketSlaTest < ActiveSupport::TestCase sla = Sla.create( name: 'test sla 2', - condition: { 'tickets.priority_id' => ['1', '2', '3'] }, + condition: { 'tickets.priority_id' => %w(1 2 3) }, data: { 'Mon' => 'Mon', 'Tue' => 'Tue', 'Wed' => 'Wed', 'Thu' => 'Thu', 'Fri' => 'Fri', 'Sat' => 'Sat', 'Sun' => 'Sun', 'beginning_of_workday' => '8:00',