From 0703c53732854dccd76652453ee080db88d60d3c Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 10:22:36 +0200 Subject: [PATCH 01/31] Added exception for unkonwn twitter article type. --- lib/tweet.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tweet.rb b/lib/tweet.rb index 171b1b0bb..b18d6fb86 100644 --- a/lib/tweet.rb +++ b/lib/tweet.rb @@ -195,7 +195,6 @@ class Tweet def from_article(article) - tweet = nil if article[:type] == 'twitter direct-message' @@ -206,7 +205,6 @@ class Tweet article[:body], {} ) - elsif article[:type] == 'twitter status' Rails.logger.debug "Create tweet from article..." @@ -217,6 +215,8 @@ class Tweet in_reply_to_status_id: article[:in_reply_to] } ) + else + fail "Can't handle unknown twitter article type 'article[:type]'." end Rails.logger.debug tweet.inspect From 5a28d2a47aa8a8c4303b0ae6c30b1630d4c7d6b2 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 10:26:37 +0200 Subject: [PATCH 02/31] Fixed typos. --- app/assets/javascripts/app/controllers/ticket_zoom.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee index d2da185fd..6d39c03f4 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom.js.coffee @@ -25,7 +25,7 @@ class App.TicketZoom extends App.Controller @sidebarState = {} @ticketLastAttributes = {} - # if we are in init task startup, ognore overview_dd + # if we are in init task startup, ignore overview_id if !params.init @overview_id = params.overview_id else From f259dd34596aece1e19cd66c973d04984e9978d5 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 11:42:54 +0200 Subject: [PATCH 03/31] Replaced group attribute with group_id since names can change. --- app/controllers/channels_controller.rb | 10 +++++----- app/models/channel/twitter.rb | 8 ++++---- lib/tweet.rb | 12 ++++++------ test/integration/twitter_test.rb | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index f1b5f08c0..0876ba4f8 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -44,24 +44,24 @@ Example: { "item":"#otrs", "type": "mixed", # optional, possible 'mixed' (default), 'recent', 'popular' - "group": "OTRS", + "group_id:": 1, "limit": 1, # optional }, { "item":"#zombie23", - "group": "Zombie Apocalypse Early Warning System", + "group_id:": 2, }, { "item":"#otterhub", - "group": "Community", + "group_id:": 3, } ], "mentions" { - "group": "Twitter", + "group_id:": 4, "limit": 100, # optional }, "direct_messages": { - "group": "Twitter", + "group_id:": 4, "limit": 1, # optional } } diff --git a/app/models/channel/twitter.rb b/app/models/channel/twitter.rb index 43ebda8e4..548c49032 100644 --- a/app/models/channel/twitter.rb +++ b/app/models/channel/twitter.rb @@ -8,7 +8,7 @@ class Channel::Twitter @tweet = Tweet.new( @channel[:options][:auth] ) @sync = @channel[:options][:sync] - Rails.logger.debug "twitter fetch started" + Rails.logger.debug 'twitter fetch started' fetch_search fetch_mentions @@ -55,7 +55,7 @@ class Channel::Twitter break if search[:limit] && search[:limit] <= counter break if Ticket::Article.find_by( message_id: tweet.id.to_s ) - @tweet.to_group( tweet, search[:group] ) + @tweet.to_group( tweet, search[:group_id] ) counter += 1 } @@ -75,7 +75,7 @@ class Channel::Twitter break if @sync[:mentions][:limit] && @sync[:mentions][:limit] <= counter break if Ticket::Article.find_by( message_id: tweet.id.to_s ) - @tweet.to_group( tweet, @sync[:mentions][:group] ) + @tweet.to_group( tweet, @sync[:mentions][:group_id] ) counter += 1 } @@ -94,7 +94,7 @@ class Channel::Twitter break if @sync[:direct_messages][:limit] && @sync[:direct_messages][:limit] <= counter break if Ticket::Article.find_by( message_id: tweet.id.to_s ) - @tweet.to_group( tweet, @sync[:direct_messages][:group] ) + @tweet.to_group( tweet, @sync[:direct_messages][:group_id] ) counter += 1 } diff --git a/lib/tweet.rb b/lib/tweet.rb index b18d6fb86..44c19a07c 100644 --- a/lib/tweet.rb +++ b/lib/tweet.rb @@ -90,12 +90,12 @@ class Tweet user end - def to_ticket(tweet, user, group) + def to_ticket(tweet, user, group_id) Rails.logger.debug "Create ticket from tweet..." Rails.logger.debug tweet.inspect Rails.logger.debug user.inspect - Rails.logger.debug group.inspect + Rails.logger.debug group_id.inspect if tweet.class.to_s == 'Twitter::DirectMessage' ticket = Ticket.find_by( @@ -112,7 +112,7 @@ class Tweet Ticket.create( customer_id: user.id, title: "#{tweet.text[0, 37]}...", - group: Group.find_by( name: group ), + group_id: group_id, state: Ticket::State.find_by( name: 'new' ), priority: Ticket::Priority.find_by( name: '2 normal' ), ) @@ -154,7 +154,7 @@ class Tweet ) end - def to_group(tweet, group) + def to_group(tweet, group_id) Rails.logger.debug 'import tweet' @@ -178,10 +178,10 @@ class Tweet Rails.logger.debug 'import in_reply_tweet ' + tweet.in_reply_to_status_id.to_s parent_tweet = @client.status( tweet.in_reply_to_status_id ) - ticket = to_group( parent_tweet, group ) + ticket = to_group( parent_tweet, group_id ) end else - ticket = to_ticket(tweet, user, group) + ticket = to_ticket(tweet, user, group_id) end to_article(tweet, user, ticket) diff --git a/test/integration/twitter_test.rb b/test/integration/twitter_test.rb index b369cbaf1..4e82d674c 100644 --- a/test/integration/twitter_test.rb +++ b/test/integration/twitter_test.rb @@ -45,18 +45,18 @@ class TwitterTest < ActiveSupport::TestCase search: [ { term: '#citheo42', - group: 'Twitter', + group_id: 2, }, { term: '#citheo24', - group: 'Users', + group_id: 1, }, ], mentions: { - group: 'Twitter', + group_id: 2, }, direct_messages: { - group: 'Twitter', + group_id: 2, } } }, @@ -73,7 +73,7 @@ class TwitterTest < ActiveSupport::TestCase ticket = Ticket.create( title: text[0, 40], customer_id: user.id, - group: Group.find_by( name: 'Twitter' ), + group_id: 2, state: Ticket::State.find_by( name: 'new' ), priority: Ticket::Priority.find_by( name: '2 normal' ), updated_by_id: 1, From 54fd62487c4c352328eda7cc824053e4c784f852 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:18:01 +0200 Subject: [PATCH 04/31] Applied rubocop cop 'Style/SpaceInsideStringInterpolation'. --- app/controllers/long_polling_controller.rb | 4 ++-- app/controllers/rss_controller.rb | 2 +- .../ticket_overviews_controller.rb | 2 +- app/models/application_model.rb | 8 ++++---- app/models/avatar.rb | 2 +- app/models/channel/filter/database.rb | 6 +++--- app/models/scheduler.rb | 6 +++--- app/models/store.rb | 4 ++-- app/models/store/file.rb | 10 +++++----- app/models/store/provider/file.rb | 12 +++++------ app/models/ticket/overviews.rb | 2 +- app/models/user/search_index.rb | 2 +- lib/core_ext/string.rb | 2 +- lib/sessions.rb | 8 ++++---- lib/sessions/backend/activity_stream.rb | 4 ++-- lib/sessions/backend/collections/base.rb | 6 +++--- lib/sessions/backend/rss.rb | 4 ++-- lib/sessions/backend/ticket_create.rb | 4 ++-- lib/sessions/backend/ticket_overview_index.rb | 4 ++-- lib/sessions/backend/ticket_overview_list.rb | 4 ++-- lib/sessions/client.rb | 2 +- script/websocket-server.rb | 20 +++++++++---------- test/browser/agent_user_manage_test.rb | 2 +- test/browser_test_helper.rb | 2 +- test/unit/activity_stream_test.rb | 2 +- test/unit/online_notifiaction_test.rb | 2 +- test/unit/store_test.rb | 6 +++--- test/unit/tag_test.rb | 4 ++-- test/unit/user_test.rb | 12 +++++------ 29 files changed, 74 insertions(+), 74 deletions(-) diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index 8f292cbbb..223f96438 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -38,7 +38,7 @@ class LongPollingController < ApplicationController spool = Sessions.spool_list( params['data']['timestamp'], current_user.id ) spool.each { |item| if item[:type] == 'direct' - log "send spool to (user_id=#{ current_user.id })", client_id + log "send spool to (user_id=#{current_user.id})", client_id Sessions.send( client_id, item[:message] ) else log 'send spool', client_id @@ -159,6 +159,6 @@ class LongPollingController < ApplicationController end def log( data, client_id = '-' ) - logger.info "client(#{ client_id }) #{ data }" + logger.info "client(#{client_id}) #{data}" end end diff --git a/app/controllers/rss_controller.rb b/app/controllers/rss_controller.rb index 3a38bbf5f..8cd82f995 100644 --- a/app/controllers/rss_controller.rb +++ b/app/controllers/rss_controller.rb @@ -21,7 +21,7 @@ curl http://localhost/api/v1/rss_fetch.json -v -u #{login}:#{password} -H "Conte def fetch items = Rss.fetch(params[:url], params[:limit]) if items.nil? - render json: { message: "failed to fetch #{ params[:url] }", status: :unprocessable_entity } + render json: { message: "failed to fetch #{params[:url]}", status: :unprocessable_entity } return end render json: { items: items } diff --git a/app/controllers/ticket_overviews_controller.rb b/app/controllers/ticket_overviews_controller.rb index f74a634ba..c21144050 100644 --- a/app/controllers/ticket_overviews_controller.rb +++ b/app/controllers/ticket_overviews_controller.rb @@ -44,7 +44,7 @@ class TicketOverviewsController < ApplicationController array: true, ) if !overview - render json: { error: "No such view #{ params[:view] }!" }, status: :unprocessable_entity + render json: { error: "No such view #{params[:view]}!" }, status: :unprocessable_entity return end diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 1ccc18a31..c3290bf28 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -524,7 +524,7 @@ class OwnModel < ApplicationModel # return if we run import mode return if Setting.get('import_mode') - logger.debug "#{ self.class.name }.find(#{ id }) notify created " + created_at.to_s + logger.debug "#{self.class.name}.find(#{id}) notify created " + created_at.to_s class_name = self.class.name class_name.gsub!(/::/, '') Sessions.broadcast( @@ -553,7 +553,7 @@ class OwnModel < ApplicationModel # return if we run import mode return if Setting.get('import_mode') - logger.debug "#{ self.class.name }.find(#{ id }) notify UPDATED " + updated_at.to_s + logger.debug "#{self.class.name}.find(#{id}) notify UPDATED " + updated_at.to_s class_name = self.class.name class_name.gsub!(/::/, '') Sessions.broadcast( @@ -582,7 +582,7 @@ class OwnModel < ApplicationModel # return if we run import mode return if Setting.get('import_mode') - logger.debug "#{ self.class.name }.find(#{ id }) notify TOUCH " + updated_at.to_s + logger.debug "#{self.class.name}.find(#{id}) notify TOUCH " + updated_at.to_s class_name = self.class.name class_name.gsub!(/::/, '') Sessions.broadcast( @@ -610,7 +610,7 @@ class OwnModel < ApplicationModel # return if we run import mode return if Setting.get('import_mode') - logger.debug "#{ self.class.name }.find(#{ id }) notify DESTOY " + updated_at.to_s + logger.debug "#{self.class.name}.find(#{id}) notify DESTOY " + updated_at.to_s class_name = self.class.name class_name.gsub!(/::/, '') Sessions.broadcast( diff --git a/app/models/avatar.rb b/app/models/avatar.rb index a95cb0609..54bb963c0 100644 --- a/app/models/avatar.rb +++ b/app/models/avatar.rb @@ -288,7 +288,7 @@ return all avatars of an user data = avatar.attributes if avatar.store_resize_id file = Store.find(avatar.store_resize_id) - data['content'] = "data:#{ file.preferences['Mime-Type'] };base64,#{ Base64.strict_encode64( file.content ) }" + data['content'] = "data:#{file.preferences['Mime-Type']};base64,#{Base64.strict_encode64( file.content )}" end avatar_list.push data end diff --git a/app/models/channel/filter/database.rb b/app/models/channel/filter/database.rb index 1c1ad6a34..adc3d5c6d 100644 --- a/app/models/channel/filter/database.rb +++ b/app/models/channel/filter/database.rb @@ -19,10 +19,10 @@ module Channel::Filter::Database scan = mail[ key.downcase.to_sym ].scan(/#{value}/i) end if match && scan[0] - Rails.logger.info " matching #{ key.downcase }:'#{ mail[ key.downcase.to_sym ] }' on #{value}" + Rails.logger.info " matching #{key.downcase}:'#{mail[ key.downcase.to_sym ]}' on #{value}" match = true else - Rails.logger.info " is not matching #{ key.downcase }:'#{ mail[ key.downcase.to_sym ] }' on #{value}" + Rails.logger.info " is not matching #{key.downcase}:'#{mail[ key.downcase.to_sym ]}' on #{value}" match = false end rescue => e @@ -36,7 +36,7 @@ module Channel::Filter::Database next if !match filter[:perform].each {|key, value| - Rails.logger.info " perform '#{ key.downcase }' = '#{value}'" + Rails.logger.info " perform '#{key.downcase}' = '#{value}'" mail[ key.downcase.to_sym ] = value } } diff --git a/app/models/scheduler.rb b/app/models/scheduler.rb index 2eee1b719..11ecdbe9b 100644 --- a/app/models/scheduler.rb +++ b/app/models/scheduler.rb @@ -22,7 +22,7 @@ class Scheduler < ApplicationModel begin ActiveRecord::Base.connection.reconnect! rescue => e - logger.error "Can't reconnect to database #{ e.inspect }" + logger.error "Can't reconnect to database #{e.inspect}" end # read/load jobs and check if it is alredy started @@ -89,13 +89,13 @@ class Scheduler < ApplicationModel logger.info "execute #{job.method} (try_count #{try_count})..." eval job.method() # rubocop:disable Lint/Eval rescue => e - logger.error "execute #{job.method} (try_count #{try_count}) exited with error #{ e.inspect }" + logger.error "execute #{job.method} (try_count #{try_count}) exited with error #{e.inspect}" # reconnect in case db connection is lost begin ActiveRecord::Base.connection.reconnect! rescue => e - logger.error "Can't reconnect to database #{ e.inspect }" + logger.error "Can't reconnect to database #{e.inspect}" end try_run_max = 10 diff --git a/app/models/store.rb b/app/models/store.rb index 833acf063..e2cc3afcd 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -142,7 +142,7 @@ returns def content file = Store::File.find_by( id: store_file_id ) if !file - fail "No such file #{ store_file_id }!" + fail "No such file #{store_file_id}!" end file.content end @@ -150,7 +150,7 @@ returns def provider file = Store::File.find_by( id: store_file_id ) if !file - fail "No such file #{ store_file_id }!" + fail "No such file #{store_file_id}!" end file.provider end diff --git a/app/models/store/file.rb b/app/models/store/file.rb index cdbfbbfc1..44ddd024c 100644 --- a/app/models/store/file.rb +++ b/app/models/store/file.rb @@ -17,7 +17,7 @@ class Store if !adapter_name fail 'Missing storage_provider setting option' end - adapter = load_adapter( "Store::Provider::#{ adapter_name }" ) + adapter = load_adapter( "Store::Provider::#{adapter_name}" ) adapter.add( data, sha ) file = Store::File.create( provider: adapter_name, @@ -29,7 +29,7 @@ class Store # read content def content - adapter = self.class.load_adapter("Store::Provider::#{ provider }") + adapter = self.class.load_adapter("Store::Provider::#{provider}") if sha c = adapter.get( sha ) else @@ -62,8 +62,8 @@ class Store # e. g. Store::File.move('File', 'DB') # e. g. Store::File.move('DB', 'File') def self.move(source, target) - adapter_source = load_adapter("Store::Provider::#{ source }") - adapter_target = load_adapter("Store::Provider::#{ target }") + adapter_source = load_adapter("Store::Provider::#{source}") + adapter_target = load_adapter("Store::Provider::#{target}") Store::File.all.each {|item| next if item.provider == target @@ -86,7 +86,7 @@ class Store private def destroy_provider - adapter = self.class.load_adapter("Store::Provider::#{ provider }") + adapter = self.class.load_adapter("Store::Provider::#{provider}") adapter.delete( sha ) end end diff --git a/app/models/store/provider/file.rb b/app/models/store/provider/file.rb index 2629a762e..69ed9c9af 100644 --- a/app/models/store/provider/file.rb +++ b/app/models/store/provider/file.rb @@ -9,7 +9,7 @@ class Store::Provider::File # install file permission = '600' if !File.exist?( get_locaton(sha) ) - Rails.logger.debug "storge write '#{ get_locaton(sha) }' (#{permission})" + Rails.logger.debug "storge write '#{get_locaton(sha)}' (#{permission})" file = File.new( get_locaton(sha), 'wb' ) file.write( data ) file.close @@ -19,7 +19,7 @@ class Store::Provider::File # check sha local_sha = Digest::SHA256.hexdigest( get(sha) ) if sha != local_sha - fail "ERROR: Corrupt file in fs #{ get_locaton(sha) }, sha should be #{sha} but is #{local_sha}" + fail "ERROR: Corrupt file in fs #{get_locaton(sha)}, sha should be #{sha} but is #{local_sha}" end true @@ -27,9 +27,9 @@ class Store::Provider::File # read file from fs def self.get(sha) - Rails.logger.debug "read from fs #{ get_locaton(sha) }" + Rails.logger.debug "read from fs #{get_locaton(sha)}" if !File.exist?( get_locaton(sha) ) - fail "ERROR: No such file #{ get_locaton(sha) }" + fail "ERROR: No such file #{get_locaton(sha)}" end data = File.open( get_locaton(sha), 'rb' ) content = data.read @@ -37,7 +37,7 @@ class Store::Provider::File # check sha local_sha = Digest::SHA256.hexdigest( content ) if local_sha != sha - fail "ERROR: Corrupt file in fs #{ get_locaton(sha) }, sha should be #{sha} but is #{local_sha}" + fail "ERROR: Corrupt file in fs #{get_locaton(sha)}, sha should be #{sha} but is #{local_sha}" end content end @@ -45,7 +45,7 @@ class Store::Provider::File # unlink file from fs def self.delete(sha) if File.exist?( get_locaton(sha) ) - Rails.logger.info "storge remove '#{ get_locaton(sha) }'" + Rails.logger.info "storge remove '#{get_locaton(sha)}'" File.delete( get_locaton(sha) ) end end diff --git a/app/models/ticket/overviews.rb b/app/models/ticket/overviews.rb index ffd5e1f98..0e019258a 100644 --- a/app/models/ticket/overviews.rb +++ b/app/models/ticket/overviews.rb @@ -88,7 +88,7 @@ returns } if data[:view] && !overview_selected - fail "No such view '#{ data[:view] }'" + fail "No such view '#{data[:view]}'" end # sortby diff --git a/app/models/user/search_index.rb b/app/models/user/search_index.rb index 5a4757af4..870261db0 100644 --- a/app/models/user/search_index.rb +++ b/app/models/user/search_index.rb @@ -17,7 +17,7 @@ returns =end def search_index_data - attributes = { 'fullname' => "#{ self['firstname'] } #{ self['lastname'] }" } + attributes = { 'fullname' => "#{self['firstname']} #{self['lastname']}" } %w(login firstname lastname phone email address city country note created_at).each { |key| if self[key] && (!self.respond_to?('empty?') || !self[key].empty?) attributes[key] = self[key] diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb index 24c70d2c7..628abffab 100644 --- a/lib/core_ext/string.rb +++ b/lib/core_ext/string.rb @@ -57,7 +57,7 @@ class String return if ActiveRecord::Base.connection_config[:adapter] != 'mysql2' each_char.select {|c| if c.bytes.count > 3 - Rails.logger.warn "strip out 4 bytes utf8 chars '#{c}' of '#{ self }'" + Rails.logger.warn "strip out 4 bytes utf8 chars '#{c}' of '#{self}'" next end c diff --git a/lib/sessions.rb b/lib/sessions.rb index 7bb8032f3..b0d38a3af 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -295,7 +295,7 @@ returns def self.send( client_id, data ) path = "#{@path}/#{client_id}/" - filename = "send-#{ Time.now.utc.to_f }" + filename = "send-#{Time.now.utc.to_f}" check = true count = 0 while check @@ -458,7 +458,7 @@ returns begin message_parsed = JSON.parse( spool['msg'] ) rescue => e - log('error', "can't parse spool message: #{ message }, #{ e.inspect }") + log('error', "can't parse spool message: #{message}, #{e.inspect}") next end @@ -579,13 +579,13 @@ returns begin Sessions::Client.new(client_id) rescue => e - log('error', "thread_client #{client_id} exited with error #{ e.inspect }") + log('error', "thread_client #{client_id} exited with error #{e.inspect}") log('error', e.backtrace.join("\n ") ) sleep 10 begin ActiveRecord::Base.connection_pool.release_connection rescue => e - log('error', "Can't reconnect to database #{ e.inspect }") + log('error', "Can't reconnect to database #{e.inspect}") end try_run_max = 10 diff --git a/lib/sessions/backend/activity_stream.rb b/lib/sessions/backend/activity_stream.rb index 3d5697418..d3ee37ec4 100644 --- a/lib/sessions/backend/activity_stream.rb +++ b/lib/sessions/backend/activity_stream.rb @@ -29,7 +29,7 @@ class Sessions::Backend::ActivityStream end def client_key - "as::load::#{ self.class }::#{ @user.id }::#{ @client_id }" + "as::load::#{self.class}::#{@user.id}::#{@client_id}" end def push @@ -53,7 +53,7 @@ class Sessions::Backend::ActivityStream } end - @client.log "push activity_stream #{ data.first.class } for user #{ @user.id }" + @client.log "push activity_stream #{data.first.class} for user #{@user.id}" @client.send( event: 'activity_stream_rebuild', collection: 'activity_stream', diff --git a/lib/sessions/backend/collections/base.rb b/lib/sessions/backend/collections/base.rb index 012054574..187ff0269 100644 --- a/lib/sessions/backend/collections/base.rb +++ b/lib/sessions/backend/collections/base.rb @@ -16,7 +16,7 @@ class Sessions::Backend::Collections::Base end def client_key - "collections::load::#{ self.class }::#{ @user.id }::#{ @client_id }" + "collections::load::#{self.class}::#{@user.id}::#{@client_id}" end def push @@ -77,13 +77,13 @@ class Sessions::Backend::Collections::Base assets: assets, } end - @client.log "push assets for push_collection #{ items.first.class } for user #{ @user.id }" + @client.log "push assets for push_collection #{items.first.class} for user #{@user.id}" @client.send( data: assets, event: [ 'loadAssets' ], ) - @client.log "push push_collection #{ items.first.class } for user #{ @user.id }" + @client.log "push push_collection #{items.first.class} for user #{@user.id}" @client.send( event: 'resetCollection', data: { diff --git a/lib/sessions/backend/rss.rb b/lib/sessions/backend/rss.rb index e1ac50dac..f6f3e9835 100644 --- a/lib/sessions/backend/rss.rb +++ b/lib/sessions/backend/rss.rb @@ -10,7 +10,7 @@ class Sessions::Backend::Rss end def collection_key - "rss::load::#{ self.class }::#{ @user.id }" + "rss::load::#{self.class}::#{@user.id}" end def load @@ -29,7 +29,7 @@ class Sessions::Backend::Rss end def client_key - "rss::load::#{ self.class }::#{ @user.id }::#{ @client_id }" + "rss::load::#{self.class}::#{@user.id}::#{@client_id}" end def push diff --git a/lib/sessions/backend/ticket_create.rb b/lib/sessions/backend/ticket_create.rb index ed62673a3..cc3fcd501 100644 --- a/lib/sessions/backend/ticket_create.rb +++ b/lib/sessions/backend/ticket_create.rb @@ -27,7 +27,7 @@ class Sessions::Backend::TicketCreate end def client_key - "as::load::#{ self.class }::#{ @user.id }::#{ @client_id }" + "as::load::#{self.class}::#{@user.id}::#{@client_id}" end def push @@ -58,7 +58,7 @@ class Sessions::Backend::TicketCreate } end - @client.log "push ticket_create for user #{ @user.id }" + @client.log "push ticket_create for user #{@user.id}" @client.send( collection: 'ticket_create_attributes', data: data, diff --git a/lib/sessions/backend/ticket_overview_index.rb b/lib/sessions/backend/ticket_overview_index.rb index 2936e240f..5055a38ec 100644 --- a/lib/sessions/backend/ticket_overview_index.rb +++ b/lib/sessions/backend/ticket_overview_index.rb @@ -28,7 +28,7 @@ class Sessions::Backend::TicketOverviewIndex end def client_key - "as::load::#{ self.class }::#{ @user.id }::#{ @client_id }" + "as::load::#{self.class}::#{@user.id}::#{@client_id}" end def push @@ -56,7 +56,7 @@ class Sessions::Backend::TicketOverviewIndex } end - @client.log "push overview_index for user #{ @user.id }" + @client.log "push overview_index for user #{@user.id}" @client.send( event: ['ticket_overview_index'], data: data, diff --git a/lib/sessions/backend/ticket_overview_list.rb b/lib/sessions/backend/ticket_overview_list.rb index ab4c861a0..60ead97fe 100644 --- a/lib/sessions/backend/ticket_overview_list.rb +++ b/lib/sessions/backend/ticket_overview_list.rb @@ -38,7 +38,7 @@ class Sessions::Backend::TicketOverviewList end def client_key - "as::load::#{ self.class }::#{ @user.id }::#{ @client_id }" + "as::load::#{self.class}::#{@user.id}::#{@client_id}" end def push @@ -102,7 +102,7 @@ class Sessions::Backend::TicketOverviewList results.push result else - @client.log "push overview_list for user #{ @user.id }" + @client.log "push overview_list for user #{@user.id}" # send update to browser @client.send( diff --git a/lib/sessions/client.rb b/lib/sessions/client.rb index 1c16890af..f5270f109 100644 --- a/lib/sessions/client.rb +++ b/lib/sessions/client.rb @@ -71,6 +71,6 @@ class Sessions::Client end def log( msg ) - Rails.logger.debug "client(#{ @client_id }) #{ msg }" + Rails.logger.debug "client(#{@client_id}) #{msg}" end end diff --git a/script/websocket-server.rb b/script/websocket-server.rb index 272f71e72..578b4fdcf 100755 --- a/script/websocket-server.rb +++ b/script/websocket-server.rb @@ -59,7 +59,7 @@ if ARGV[0] != 'start' && ARGV[0] != 'stop' exit end -puts "Starting websocket server on #{ @options[:b] }:#{ @options[:p] } (secure:#{ @options[:s] },pid:#{@options[:i]})" +puts "Starting websocket server on #{@options[:b]}:#{@options[:p]} (secure:#{@options[:s]},pid:#{@options[:i]})" #puts options.inspect if ARGV[0] == 'stop' @@ -119,11 +119,11 @@ EventMachine.run { ws.onmessage { |msg| client_id = ws.object_id.to_s - log 'debug', "received: #{ msg } ", client_id + log 'debug', "received: #{msg} ", client_id begin data = JSON.parse(msg) rescue => e - log 'error', "can't parse message: #{ msg }, #{ e.inspect }", client_id + log 'error', "can't parse message: #{msg}, #{e.inspect}", client_id next end @@ -151,7 +151,7 @@ EventMachine.run { # create new msg to push to client if item[:type] == 'direct' - log 'notice', "send spool to (user_id=#{ @clients[client_id][:session]['id'] })", client_id + log 'notice', "send spool to (user_id=#{@clients[client_id][:session]['id']})", client_id websocket_send(client_id, item[:message]) else log 'notice', 'send spool', client_id @@ -198,13 +198,13 @@ EventMachine.run { # broadcast to recipient list if data['recipient'] if data['recipient'].class != Hash - log 'error', "recipient attribute isn't a hash '#{ data['recipient'].inspect }'" + log 'error', "recipient attribute isn't a hash '#{data['recipient'].inspect}'" else if !data['recipient'].key?('user_id') - log 'error', "need recipient.user_id attribute '#{ data['recipient'].inspect }'" + log 'error', "need recipient.user_id attribute '#{data['recipient'].inspect}'" else if data['recipient']['user_id'].class != Array - log 'error', "recipient.user_id attribute isn't an array '#{ data['recipient']['user_id'].inspect }'" + log 'error', "recipient.user_id attribute isn't an array '#{data['recipient']['user_id'].inspect}'" else data['recipient']['user_id'].each { |user_id| @@ -251,7 +251,7 @@ EventMachine.run { EventMachine.add_periodic_timer(20) { # websocket - log 'notice', "Status: websocket clients: #{ @clients.size }" + log 'notice', "Status: websocket clients: #{@clients.size}" @clients.each { |client_id, _client| log 'notice', 'working...', client_id } @@ -263,7 +263,7 @@ EventMachine.run { next if client[:meta][:type] == 'websocket' clients = clients + 1 } - log 'notice', "Status: ajax clients: #{ clients }" + log 'notice', "Status: ajax clients: #{clients}" client_list.each {|client_id, client| next if client[:meta][:type] == 'websocket' log 'notice', 'working...', client_id @@ -346,7 +346,7 @@ EventMachine.run { if !@options[:v] return if level == 'debug' end - puts "#{Time.now.utc.iso8601}:client(#{ client_id }) #{ data }" + puts "#{Time.now.utc.iso8601}:client(#{client_id}) #{data}" #puts "#{Time.now.utc.iso8601}:#{ level }:client(#{ client_id }) #{ data }" end diff --git a/test/browser/agent_user_manage_test.rb b/test/browser/agent_user_manage_test.rb index 3ab4a6aba..d3b0311ba 100644 --- a/test/browser/agent_user_manage_test.rb +++ b/test/browser/agent_user_manage_test.rb @@ -6,7 +6,7 @@ class AgentUserManageTest < TestCase customer_user_email = 'customer-test-' + rand(999_999).to_s + '@example.com' firstname = 'Customer Firstname' lastname = 'Customer Lastname' - fullname = "#{ firstname } #{ lastname } <#{ customer_user_email }>" + fullname = "#{firstname} #{lastname} <#{customer_user_email}>" @browser = browser_instance login( diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 52aff170e..44efd83b0 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -1095,7 +1095,7 @@ wait untill text in selector disabppears sleep 1 } screenshot( browser: instance, comment: 'ticket_create_failed' ) - fail "ticket creation failed, can't get zoom url (current url is '#{ instance.current_url }')" + fail "ticket creation failed, can't get zoom url (current url is '#{instance.current_url}')" end =begin diff --git a/test/unit/activity_stream_test.rb b/test/unit/activity_stream_test.rb index 2845209d8..d791a3d95 100644 --- a/test/unit/activity_stream_test.rb +++ b/test/unit/activity_stream_test.rb @@ -385,7 +385,7 @@ class ActivityStreamTest < ActiveSupport::TestCase 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'] }" ) + assert( false, "entry should not exist #{item['object']}/#{item['type']}/#{item['o_id']}" ) end end } diff --git a/test/unit/online_notifiaction_test.rb b/test/unit/online_notifiaction_test.rb index 10646a313..8456db4ec 100644 --- a/test/unit/online_notifiaction_test.rb +++ b/test/unit/online_notifiaction_test.rb @@ -337,7 +337,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase end } #puts "--- #{onine_notifications.inspect}" - assert( hit, "online notification exists not #{ check_item.inspect }" ) + assert( hit, "online notification exists not #{check_item.inspect}" ) } end diff --git a/test/unit/store_test.rb b/test/unit/store_test.rb index 52cb5ad0c..e409a6143 100644 --- a/test/unit/store_test.rb +++ b/test/unit/store_test.rb @@ -49,7 +49,7 @@ class StoreTest < ActiveSupport::TestCase # sha check sha_new = Digest::SHA256.hexdigest( attachments[0].content ) - assert_equal( sha, sha_new, "check file #{ file[:filename] }") + assert_equal( sha, sha_new, "check file #{file[:filename]}") # filename check assert_equal( file[:filename], attachments[0].filename ) @@ -75,7 +75,7 @@ class StoreTest < ActiveSupport::TestCase # sha check sha_new = Digest::SHA256.hexdigest( attachments[0].content ) - assert_equal( sha, sha_new, "check file #{ file[:filename] }") + assert_equal( sha, sha_new, "check file #{file[:filename]}") # filename check assert_equal( file[:filename], attachments[0].filename ) @@ -101,7 +101,7 @@ class StoreTest < ActiveSupport::TestCase # sha check sha_new = Digest::SHA256.hexdigest( attachments[0].content ) - assert_equal( sha, sha_new, "check file #{ file[:filename] }") + assert_equal( sha, sha_new, "check file #{file[:filename]}") # filename check assert_equal( file[:filename], attachments[0].filename ) diff --git a/test/unit/tag_test.rb b/test/unit/tag_test.rb index 7a290f453..e3fac8588 100644 --- a/test/unit/tag_test.rb +++ b/test/unit/tag_test.rb @@ -106,9 +106,9 @@ class TagTest < ActiveSupport::TestCase list = Tag.tag_list( tags ) test[:verify][:items].each {|key, value| if value == true - assert( list.include?( key ), "Tag verify - should exists but exists #{ key }") + assert( list.include?( key ), "Tag verify - should exists but exists #{key}") else - assert( !list.include?( key ), "Tag verify - exists but should not #{ key }") + assert( !list.include?( key ), "Tag verify - exists but should not #{key}") end } } diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 0992d91e9..a23afd6e0 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -255,15 +255,15 @@ class UserTest < ActiveSupport::TestCase test[:create_verify].each { |key, value| next if key == :image_md5 if user.respond_to?( key ) - assert_equal( value, user.send(key), "create check #{ key } in (#{ test[:name] })" ) + assert_equal( value, user.send(key), "create check #{key} in (#{test[:name]})" ) else - assert_equal( value, user[key], "create check #{ key } in (#{ test[:name] })" ) + assert_equal( value, user[key], "create check #{key} in (#{test[:name]})" ) end } if test[:create_verify][:image_md5] file = Avatar.get_by_hash( user.image ) file_md5 = Digest::MD5.hexdigest( file.content ) - assert_equal( test[:create_verify][:image_md5], file_md5, "create avatar md5 check in (#{ test[:name] })" ) + assert_equal( test[:create_verify][:image_md5], file_md5, "create avatar md5 check in (#{test[:name]})" ) end if test[:update] user.update_attributes( test[:update] ) @@ -271,16 +271,16 @@ class UserTest < ActiveSupport::TestCase test[:update_verify].each { |key, value| next if key == :image_md5 if user.respond_to?( key ) - assert_equal( value, user.send(key), "update check #{ key } in (#{ test[:name] })" ) + assert_equal( value, user.send(key), "update check #{key} in (#{test[:name]})" ) else - assert_equal( value, user[key], "update check #{ key } in (#{ test[:name] })" ) + assert_equal( value, user[key], "update check #{key} in (#{test[:name]})" ) end } if test[:update_verify][:image_md5] file = Avatar.get_by_hash( user.image ) file_md5 = Digest::MD5.hexdigest( file.content ) - assert_equal( test[:update_verify][:image_md5], file_md5, "update avatar md5 check in (#{ test[:name] })" ) + assert_equal( test[:update_verify][:image_md5], file_md5, "update avatar md5 check in (#{test[:name]})" ) end end From 9b6bf4e762095707b8fd671397c6b3d822791100 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:20:41 +0200 Subject: [PATCH 05/31] Applied rubocop cop 'Style/EmptyLines'. --- app/controllers/users_controller.rb | 1 - app/models/organization.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a3c68b268..29d270517 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -338,7 +338,6 @@ class UsersController < ApplicationController user_all = User.where('id != 1').order('created_at DESC').limit( params[:limit] || 20 ) end - # build result list if !params[:full] users = [] diff --git a/app/models/organization.rb b/app/models/organization.rb index 9b4909841..7b852171f 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -17,7 +17,6 @@ class Organization < ApplicationModel notify_clients_support latest_change_support - private def cache_delete From 78aacafe5485f90e3bcadb7abcb0ca1630833657 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:22:17 +0200 Subject: [PATCH 06/31] Applied rubocop cop 'Style/EmptyLines'. --- app/helpers/application_helper.rb | 2 +- lib/tweet.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 95c5f2c00..02ca60ce6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,7 +2,7 @@ module ApplicationHelper def inline_svg(path) - File.open("public/assets/images/#{path}", "rb") do |file| + File.open("public/assets/images/#{path}", 'rb') do |file| raw file.read end end diff --git a/lib/tweet.rb b/lib/tweet.rb index 44c19a07c..9a6df4c03 100644 --- a/lib/tweet.rb +++ b/lib/tweet.rb @@ -45,7 +45,7 @@ class Tweet def to_user(tweet) - Rails.logger.debug "Create user from tweet..." + Rails.logger.debug 'Create user from tweet...' Rails.logger.debug tweet.inspect # do tweet_user lookup @@ -92,7 +92,7 @@ class Tweet def to_ticket(tweet, user, group_id) - Rails.logger.debug "Create ticket from tweet..." + Rails.logger.debug 'Create ticket from tweet...' Rails.logger.debug tweet.inspect Rails.logger.debug user.inspect Rails.logger.debug group_id.inspect @@ -120,7 +120,7 @@ class Tweet def to_article(tweet, user, ticket) - Rails.logger.debug "Create article from tweet..." + Rails.logger.debug 'Create article from tweet...' Rails.logger.debug tweet.inspect Rails.logger.debug user.inspect Rails.logger.debug ticket.inspect @@ -207,7 +207,7 @@ class Tweet ) elsif article[:type] == 'twitter status' - Rails.logger.debug "Create tweet from article..." + Rails.logger.debug 'Create tweet from article...' tweet = @client.update( article[:body], From 9c3c2de3bed99e8b9d2f9cb3dcdbce9afc2334bb Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:25:02 +0200 Subject: [PATCH 07/31] Applied rubocop cop 'Style/GuardClause'. --- app/models/application_model.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/application_model.rb b/app/models/application_model.rb index c3290bf28..dada2bb6b 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -261,11 +261,9 @@ returns end # delete login caches - if self[:login] - key = "#{self.class}::#{login}" - Cache.delete(key) - end + return if !self[:login] + Cache.delete("#{self.class}::#{login}") end def self.cache_set(data_id, data) From ddd2162ec113583d70fb7393f8391350f799a612 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:26:30 +0200 Subject: [PATCH 08/31] Applied rubocop cop 'Style/SpaceBeforeBlockBraces'. --- app/models/channel/twitter.rb | 2 +- lib/models.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/channel/twitter.rb b/app/models/channel/twitter.rb index 548c49032..e57f9453c 100644 --- a/app/models/channel/twitter.rb +++ b/app/models/channel/twitter.rb @@ -50,7 +50,7 @@ class Channel::Twitter Rails.logger.debug " - searching for '#{search[:term]}'" counter = 0 - @tweet.client.search( search[:term], result_type: result_type ).collect{ |tweet| + @tweet.client.search( search[:term], result_type: result_type ).collect { |tweet| break if search[:limit] && search[:limit] <= counter break if Ticket::Article.find_by( message_id: tweet.id.to_s ) diff --git a/lib/models.rb b/lib/models.rb index 2d812e11b..a676f901f 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -94,7 +94,7 @@ returns # find relations via reflections list.each {|model_class, model_attributes| next if !model_attributes[:reflections] - model_attributes[:reflections].each{|reflection_key, reflection_value| + model_attributes[:reflections].each {|reflection_key, reflection_value| next if reflection_value.macro != :belongs_to if reflection_value.options[:class_name] == object_name count = model_class.where("#{reflection_value.name}_id = ?", object_id).count From 4c0fa5111d572e92c56a5df82379a8b5a91e4242 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:27:55 +0200 Subject: [PATCH 09/31] Applied rubocop cop 'Style/IndentHash'. --- app/models/observer/ticket/article/communicate_twitter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/observer/ticket/article/communicate_twitter.rb b/app/models/observer/ticket/article/communicate_twitter.rb index 3ef62d485..ff00a5f8e 100644 --- a/app/models/observer/ticket/article/communicate_twitter.rb +++ b/app/models/observer/ticket/article/communicate_twitter.rb @@ -22,11 +22,11 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer twitter = Channel::Twitter.new tweet = twitter.send({ - type: type['name'], + type: type['name'], to: record.to, body: record.body, in_reply_to: record.in_reply_to - }) + }) record.message_id = tweet.id record.save end From bc6a8ca169c8314626fdae20ea5c9a2fe4b581f6 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:30:05 +0200 Subject: [PATCH 10/31] Applied rubocop cop 'Style/RedundantBegin'. --- app/models/scheduler.rb | 50 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/app/models/scheduler.rb b/app/models/scheduler.rb index 11ecdbe9b..34560b518 100644 --- a/app/models/scheduler.rb +++ b/app/models/scheduler.rb @@ -82,37 +82,35 @@ class Scheduler < ApplicationModel end def self._start_job( job, try_count = 0, try_run_time = Time.zone.now ) + job.last_run = Time.zone.now + job.pid = Thread.current.object_id + job.save + logger.info "execute #{job.method} (try_count #{try_count})..." + eval job.method() # rubocop:disable Lint/Eval + rescue => e + logger.error "execute #{job.method} (try_count #{try_count}) exited with error #{e.inspect}" + + # reconnect in case db connection is lost begin - job.last_run = Time.zone.now - job.pid = Thread.current.object_id - job.save - logger.info "execute #{job.method} (try_count #{try_count})..." - eval job.method() # rubocop:disable Lint/Eval + ActiveRecord::Base.connection.reconnect! rescue => e - logger.error "execute #{job.method} (try_count #{try_count}) exited with error #{e.inspect}" + logger.error "Can't reconnect to database #{e.inspect}" + end - # reconnect in case db connection is lost - begin - ActiveRecord::Base.connection.reconnect! - rescue => e - logger.error "Can't reconnect to database #{e.inspect}" - end + try_run_max = 10 + try_count += 1 - try_run_max = 10 - try_count += 1 + # reset error counter if to old + if try_run_time + ( 60 * 5 ) < Time.zone.now + try_count = 0 + end + try_run_time = Time.zone.now - # reset error counter if to old - if try_run_time + ( 60 * 5 ) < Time.zone.now - try_count = 0 - end - try_run_time = Time.zone.now - - # restart job again - if try_run_max > try_count - _start_job( job, try_count, try_run_time) - else - raise "STOP thread for #{job.method} after #{try_count} tries" - end + # restart job again + if try_run_max > try_count + _start_job( job, try_count, try_run_time) + else + raise "STOP thread for #{job.method} after #{try_count} tries" end end From deb4dfdb9cb0495cfd3325bb60626cf2432284e4 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:31:27 +0200 Subject: [PATCH 11/31] Applied rubocop cop 'Style/HashSyntax'. --- test/browser/switch_to_user_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/browser/switch_to_user_test.rb b/test/browser/switch_to_user_test.rb index 12a8a45b6..514a8cefd 100644 --- a/test/browser/switch_to_user_test.rb +++ b/test/browser/switch_to_user_test.rb @@ -26,12 +26,12 @@ class SwitchToUserTest < TestCase ) watch_for( - :css => '.switchBackToUser', - :value => 'zammad looks like', + css: '.switchBackToUser', + value: 'zammad looks like', ) watch_for( - :css => '.switchBackToUser', - :value => 'Nicole', + css: '.switchBackToUser', + value: 'Nicole', ) login = @browser.find_elements( { css: '.user-menu .user a' } )[0].attribute('title') assert_equal(login, 'nicole.braun@zammad.org') From f18afea600c627a3148cca6378d1fc36d4b9bfd2 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:32:48 +0200 Subject: [PATCH 12/31] Applied rubocop cop 'Style/NumericLiterals'. --- test/unit/assets_test.rb | 2 +- test/unit/object_cache_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/assets_test.rb b/test/unit/assets_test.rb index 46dd6eaa9..fc7a33be8 100644 --- a/test/unit/assets_test.rb +++ b/test/unit/assets_test.rb @@ -86,7 +86,7 @@ class AssetsTest < ActiveSupport::TestCase # touch org, check if user1 has changed sleep 2 org2 = Organization.find(org.id) - org2.note = "some note...#{rand(9999999999999)}" + org2.note = "some note...#{rand(9_999_999_999_999)}" org2.save attributes = org2.attributes_with_associations diff --git a/test/unit/object_cache_test.rb b/test/unit/object_cache_test.rb index 6af04c1fc..5ca3cb821 100644 --- a/test/unit/object_cache_test.rb +++ b/test/unit/object_cache_test.rb @@ -54,7 +54,7 @@ class ObjectCacheTest < ActiveSupport::TestCase # update group group1 = groups.first - group1.note = "some note #{rand(9999999999)}" + group1.note = "some note #{rand(9_999_999_999)}" group1.save assets = user1.assets({}) From 1806193619f69e75aee35633e3723dfc7b9554d2 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:34:12 +0200 Subject: [PATCH 13/31] Applied rubocop cop 'Style/RedundantReturn'. --- lib/tweet.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/tweet.rb b/lib/tweet.rb index 9a6df4c03..abffd60e5 100644 --- a/lib/tweet.rb +++ b/lib/tweet.rb @@ -40,8 +40,7 @@ class Tweet Rails.logger.error "Twitter (#{tweet.id}): unknown user source" - return - end + end def to_user(tweet) From b9b39014aeacf75ab6150934fb9c616c224b52e8 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:35:28 +0200 Subject: [PATCH 14/31] Applied rubocop cop 'Style/WordArray'. --- lib/models.rb | 2 +- test/unit/model_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/models.rb b/lib/models.rb index a676f901f..d2f9d2761 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -81,7 +81,7 @@ returns list.each {|model_class, model_attributes| references[:model][model_class.to_s] = 0 next if !model_attributes[:attributes] - ['created_by_id', 'updated_by_id'].each {|item| + %w(created_by_id updated_by_id).each {|item| if model_attributes[:attributes].include?(item) count = model_class.where("#{item} = ?", object_id).count next if count == 0 diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index 6af3d2517..8ec188acf 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -6,7 +6,7 @@ class ModelTest < ActiveSupport::TestCase # create base groups = Group.where( name: 'Users' ) - roles = Role.where( name: ['Agent', 'Admin'] ) + roles = Role.where( name: %w(Agent Admin) ) agent1 = User.create_or_update( login: 'model-agent1@example.com', firstname: 'Model', From d52167f417526e87cc8706fc89af02e63265dc81 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:37:27 +0200 Subject: [PATCH 15/31] Applied rubocop cop 'Style/IndentationWidth'. --- test/unit/model_test.rb | 134 ++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index 8ec188acf..482c4b62f 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -5,73 +5,73 @@ class ModelTest < ActiveSupport::TestCase test 'references test' do # create base - groups = Group.where( name: 'Users' ) - roles = Role.where( name: %w(Agent Admin) ) - agent1 = User.create_or_update( - login: 'model-agent1@example.com', - firstname: 'Model', - lastname: 'Agent1', - email: 'model-agent1@example.com', - password: 'agentpw', - active: true, - roles: roles, - groups: groups, - updated_at: '2015-02-05 16:37:00', - updated_by_id: 1, - created_by_id: 1, - ) - organization1 = Organization.create_if_not_exists( - name: 'Model Org 1', - updated_at: '2015-02-05 16:37:00', - updated_by_id: 1, - created_by_id: 1, - ) - organization2 = Organization.create_if_not_exists( - name: 'Model Org 2', - updated_at: '2015-02-05 16:37:00', - updated_by_id: agent1.id, - created_by_id: 1, - ) - roles = Role.where( name: 'Customer' ) - customer1 = User.create_or_update( - login: 'model-customer1@example.com', - firstname: 'Model', - lastname: 'Customer1', - email: 'model-customer1@example.com', - password: 'customerpw', - active: true, - organization_id: organization1.id, - roles: roles, - updated_at: '2015-02-05 16:37:00', - updated_by_id: 1, - created_by_id: 1, - ) - customer2 = User.create_or_update( - login: 'model-customer2@example.com', - firstname: 'Model', - lastname: 'Customer2', - email: 'model-customer2@example.com', - password: 'customerpw', - active: true, - organization_id: nil, - roles: roles, - updated_at: '2015-02-05 16:37:00', - updated_by_id: agent1.id, - created_by_id: 1, - ) - customer3 = User.create_or_update( - login: 'model-customer3@example.com', - firstname: 'Model', - lastname: 'Customer3', - email: 'model-customer3@example.com', - password: 'customerpw', - active: true, - organization_id: nil, - roles: roles, - updated_at: '2015-02-05 16:37:00', - updated_by_id: agent1.id, - created_by_id: agent1.id, - ) + groups = Group.where( name: 'Users' ) + roles = Role.where( name: %w(Agent Admin) ) + agent1 = User.create_or_update( + login: 'model-agent1@example.com', + firstname: 'Model', + lastname: 'Agent1', + email: 'model-agent1@example.com', + password: 'agentpw', + active: true, + roles: roles, + groups: groups, + updated_at: '2015-02-05 16:37:00', + updated_by_id: 1, + created_by_id: 1, + ) + organization1 = Organization.create_if_not_exists( + name: 'Model Org 1', + updated_at: '2015-02-05 16:37:00', + updated_by_id: 1, + created_by_id: 1, + ) + organization2 = Organization.create_if_not_exists( + name: 'Model Org 2', + updated_at: '2015-02-05 16:37:00', + updated_by_id: agent1.id, + created_by_id: 1, + ) + roles = Role.where( name: 'Customer' ) + customer1 = User.create_or_update( + login: 'model-customer1@example.com', + firstname: 'Model', + lastname: 'Customer1', + email: 'model-customer1@example.com', + password: 'customerpw', + active: true, + organization_id: organization1.id, + roles: roles, + updated_at: '2015-02-05 16:37:00', + updated_by_id: 1, + created_by_id: 1, + ) + customer2 = User.create_or_update( + login: 'model-customer2@example.com', + firstname: 'Model', + lastname: 'Customer2', + email: 'model-customer2@example.com', + password: 'customerpw', + active: true, + organization_id: nil, + roles: roles, + updated_at: '2015-02-05 16:37:00', + updated_by_id: agent1.id, + created_by_id: 1, + ) + customer3 = User.create_or_update( + login: 'model-customer3@example.com', + firstname: 'Model', + lastname: 'Customer3', + email: 'model-customer3@example.com', + password: 'customerpw', + active: true, + organization_id: nil, + roles: roles, + updated_at: '2015-02-05 16:37:00', + updated_by_id: agent1.id, + created_by_id: agent1.id, + ) references = Models.references('User', agent1.id) From 2327e2506e8ee9ddc9d2dccf46c1f924735befda Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:38:50 +0200 Subject: [PATCH 16/31] Applied rubocop cop 'Style/TrailingBlankLines'. --- lib/models.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models.rb b/lib/models.rb index d2f9d2761..a61d9d7c6 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -118,4 +118,4 @@ returns references end -end \ No newline at end of file +end From a43b603f84397d4a7ebb9ae170704c62b781cf1d Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 17:40:07 +0200 Subject: [PATCH 17/31] Applied rubocop cop 'Style/SpaceAroundOperators'. --- lib/models.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models.rb b/lib/models.rb index a61d9d7c6..1ec694f53 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -102,7 +102,7 @@ returns Rails.logger.debug "FOUND (by ref without class) #{model_class}->#{reflection_value.name} #{count}!" references[:model][model_class.to_s] += count end - if !reflection_value.options[:class_name] && reflection_value.name == object_name.downcase.to_sym + if !reflection_value.options[:class_name] && reflection_value.name == object_name.downcase.to_sym count = model_class.where("#{reflection_value.name}_id = ?", object_id).count next if count == 0 Rails.logger.debug "FOUND (by ref with class) #{model_class}->#{reflection_value.name} #{count}!" From 7a02236f63c2e213b0b1bba57a969cecbfd59d21 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 18:51:22 +0200 Subject: [PATCH 18/31] Applied rubocop cop 'Style/Next'. --- lib/models.rb | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/models.rb b/lib/models.rb index 1ec694f53..c521535c2 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -82,12 +82,13 @@ returns references[:model][model_class.to_s] = 0 next if !model_attributes[:attributes] %w(created_by_id updated_by_id).each {|item| - if model_attributes[:attributes].include?(item) - count = model_class.where("#{item} = ?", object_id).count - next if count == 0 - Rails.logger.debug "FOUND (by id) #{model_class}->#{item} #{count}!" - references[:model][model_class.to_s] += count - end + + next if !model_attributes[:attributes].include?(item) + + count = model_class.where("#{item} = ?", object_id).count + next if count == 0 + Rails.logger.debug "FOUND (by id) #{model_class}->#{item} #{count}!" + references[:model][model_class.to_s] += count } } @@ -95,19 +96,24 @@ returns list.each {|model_class, model_attributes| next if !model_attributes[:reflections] model_attributes[:reflections].each {|reflection_key, reflection_value| + next if reflection_value.macro != :belongs_to + if reflection_value.options[:class_name] == object_name count = model_class.where("#{reflection_value.name}_id = ?", object_id).count next if count == 0 Rails.logger.debug "FOUND (by ref without class) #{model_class}->#{reflection_value.name} #{count}!" references[:model][model_class.to_s] += count end - if !reflection_value.options[:class_name] && reflection_value.name == object_name.downcase.to_sym - count = model_class.where("#{reflection_value.name}_id = ?", object_id).count - next if count == 0 - Rails.logger.debug "FOUND (by ref with class) #{model_class}->#{reflection_value.name} #{count}!" - references[:model][model_class.to_s] += count - end + + next if reflection_value.options[:class_name] + next if reflection_value.name != object_name.downcase.to_sym + + count = model_class.where("#{reflection_value.name}_id = ?", object_id).count + next if count == 0 + + Rails.logger.debug "FOUND (by ref with class) #{model_class}->#{reflection_value.name} #{count}!" + references[:model][model_class.to_s] += count } } From 0acd0b18617e4b29d41d00a3efeb7fe4bd74aee7 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 18:56:27 +0200 Subject: [PATCH 19/31] Applied rubocop cop 'Style/RegexpLiteral'. --- lib/models.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/models.rb b/lib/models.rb index c521535c2..911ac8153 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -27,9 +27,9 @@ returns dir = "#{Rails.root}/app/models/" Dir.glob( "#{dir}**/*.rb" ) do |entry| next if entry =~ /application_model/i - next if entry =~ /channel\//i - next if entry =~ /observer\//i - next if entry =~ /store\/provider\//i + next if entry =~ %r{channel/}i + next if entry =~ %r{observer/}i + next if entry =~ %r{store/provider/}i entry.gsub!(dir, '') entry = entry.to_classname model_class = load_adapter(entry) From cd800495d8194591e5e0d74eb162d3281b3750a2 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 18:58:15 +0200 Subject: [PATCH 20/31] Applied rubocop cop 'Lint/UnusedBlockArgument'. --- lib/models.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/models.rb b/lib/models.rb index 911ac8153..f2fe53553 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -95,7 +95,7 @@ returns # find relations via reflections list.each {|model_class, model_attributes| next if !model_attributes[:reflections] - model_attributes[:reflections].each {|reflection_key, reflection_value| + model_attributes[:reflections].each {|_reflection_key, reflection_value| next if reflection_value.macro != :belongs_to @@ -117,7 +117,7 @@ returns } } - references[:model].each {|k, v| + references[:model].each {|_k, v| next if v == 0 references[:total] += v } From e1a5a2f94bafe61367630fe69be5c536e8f7b771 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:03:48 +0200 Subject: [PATCH 21/31] Applied rubocop cop 'Lint/UnreachableCode'. --- app/models/application_model/assets.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/application_model/assets.rb b/app/models/application_model/assets.rb index f5bf4d5c0..9250740da 100644 --- a/app/models/application_model/assets.rb +++ b/app/models/application_model/assets.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ +#36 Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # rubocop:disable ClassAndModuleChildren module ApplicationModel::Assets @@ -32,7 +32,7 @@ returns return data if !self['created_by_id'] && !self['updated_by_id'] %w(created_by_id updated_by_id).each {|local_user_id| next if !self[ local_user_id ] - next data[ User.to_app_model ] && data[ User.to_app_model ][ self[ local_user_id ] ] + next if data[ User.to_app_model ] && data[ User.to_app_model ][ self[ local_user_id ] ] user = User.lookup( id: self[ local_user_id ] ) data = user.assets( data ) } From 37a9801d73dede64860c971c4fa8cee27f75bfcc Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:13:30 +0200 Subject: [PATCH 22/31] Added 'Metrics/ModuleLength' to V2 Rubocops. --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index d079c8dc1..2b6e174b9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -184,6 +184,10 @@ Metrics/BlockNesting: StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count' Enabled: false +Metrics/ModuleLength: + Description: 'Avoid modules longer than 100 lines of code.' + Enabled: false + # TODO Style/Documentation: From 08de22d863ac9d8c634e7b4ab604ca0b5673f7e7 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:21:30 +0200 Subject: [PATCH 23/31] Applied rubocop cop 'Style/AlignHash'. --- app/models/observer/ticket/article/communicate_twitter.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/observer/ticket/article/communicate_twitter.rb b/app/models/observer/ticket/article/communicate_twitter.rb index ff00a5f8e..fe1660644 100644 --- a/app/models/observer/ticket/article/communicate_twitter.rb +++ b/app/models/observer/ticket/article/communicate_twitter.rb @@ -23,9 +23,9 @@ class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer twitter = Channel::Twitter.new tweet = twitter.send({ type: type['name'], - to: record.to, - body: record.body, - in_reply_to: record.in_reply_to + to: record.to, + body: record.body, + in_reply_to: record.in_reply_to }) record.message_id = tweet.id record.save From b92e5c7532cc9449ee2c02b15f47609074c16a3e Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:36:13 +0200 Subject: [PATCH 24/31] Applied rubocop cop 'Style/Next' and 'Lint/UnneededDisable'. --- test/browser_test_helper.rb | 60 ++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 44efd83b0..3defb2aa9 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -1,5 +1,5 @@ ENV['RAILS_ENV'] = 'test' -# rubocop:disable Next, CyclomaticComplexity, PerceivedComplexity, HandleExceptions, ClassVars, NonLocalExitFromIterator +# rubocop:disable HandleExceptions, ClassVars, NonLocalExitFromIterator require File.expand_path('../../config/environment', __FILE__) require 'selenium-webdriver' @@ -152,11 +152,11 @@ class TestCase < Test::Unit::TestCase (1..6).each { sleep 1 login = instance.find_elements( { css: '#login' } )[0] - if login - screenshot( browser: instance, comment: 'logout_ok' ) - assert( true, 'logout ok' ) - return - end + + next if !login + screenshot( browser: instance, comment: 'logout_ok' ) + assert( true, 'logout ok' ) + return } screenshot( browser: instance, comment: 'logout_failed' ) fail 'no login box found, seems logout was not successfully!' @@ -578,23 +578,22 @@ class TestCase < Test::Unit::TestCase cookies.each {|cookie| #puts "CCC #{cookie.inspect}" # :name=>"_zammad_session_c25832f4de2", :value=>"adc31cd21615cb0a7ab269184ec8b76f", :path=>"/", :domain=>"localhost", :expires=>nil, :secure=>false} - if cookie[:name] =~ /#{params[:name]}/i - if params.key?( :value ) && cookie[:value].to_s =~ /#{params[:value]}/i - assert( true, "matching value '#{params[:value]}' in cookie '#{cookie}'" ) - else - fail "not matching value '#{params[:value]}' in cookie '#{cookie}'" - end - if params.key?( :expires ) && cookie[:expires].to_s =~ /#{params[:expires]}/i - assert( true, "matching expires '#{params[:expires].inspect}' in cookie '#{cookie}'" ) - else - fail "not matching expires '#{params[:expires]}' in cookie '#{cookie}'" - end + next if cookie[:name] !~ /#{params[:name]}/i - if params[:should_not_exist] - fail "cookie with name '#{params[:name]}' should not exist, but exists '#{cookies}'" - end - return + if params.key?( :value ) && cookie[:value].to_s =~ /#{params[:value]}/i + assert( true, "matching value '#{params[:value]}' in cookie '#{cookie}'" ) + else + fail "not matching value '#{params[:value]}' in cookie '#{cookie}'" end + if params.key?( :expires ) && cookie[:expires].to_s =~ /#{params[:expires]}/i + assert( true, "matching expires '#{params[:expires].inspect}' in cookie '#{cookie}'" ) + else + fail "not matching expires '#{params[:expires]}' in cookie '#{cookie}'" + end + + return if !params[:should_not_exist] + + fail "cookie with name '#{params[:name]}' should not exist, but exists '#{cookies}'" } if params[:should_not_exist] assert( true, "cookie with name '#{params[:name]}' is not existing" ) @@ -1226,17 +1225,18 @@ wait untill text in selector disabppears if data[:state] || data[:group] || data[:body] found = nil (1..10).each { - if !found - begin - text = instance.find_elements( { css: '.content.active .js-reset' } )[0].text - if text =~ /(Discard your unsaved changes.|Verwerfen der)/ - found = true - end - rescue - # try again + + next if found + + begin + text = instance.find_elements( { css: '.content.active .js-reset' } )[0].text + if text =~ /(Discard your unsaved changes.|Verwerfen der)/ + found = true end - sleep 1 + rescue + # try again end + sleep 1 } if !found screenshot( browser: instance, comment: 'ticket_update_discard_message_failed' ) From aaf19fa52b97e8c20fa474252d9c83e9addd852b Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:37:24 +0200 Subject: [PATCH 25/31] Applied rubocop cop 'Style/CommentIndentation'. --- test/unit/model_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index 482c4b62f..0aaf82dd8 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -4,7 +4,7 @@ require 'test_helper' class ModelTest < ActiveSupport::TestCase test 'references test' do - # create base + # create base groups = Group.where( name: 'Users' ) roles = Role.where( name: %w(Agent Admin) ) agent1 = User.create_or_update( From 81e14dd96197b2eae3cd465df254efb88ae050d1 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:40:58 +0200 Subject: [PATCH 26/31] Applied rubocop cop 'Style/Next' and 'Style/UselessAssignment' and 'Style/BlockNesting'. --- test/unit/online_notifiaction_test.rb | 45 +++++++++++++-------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/test/unit/online_notifiaction_test.rb b/test/unit/online_notifiaction_test.rb index 8456db4ec..dba6ca958 100644 --- a/test/unit/online_notifiaction_test.rb +++ b/test/unit/online_notifiaction_test.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -# rubocop:disable Next, UselessAssignment, BlockNesting require 'test_helper' class OnlineNotificationTest < ActiveSupport::TestCase @@ -283,14 +282,14 @@ class OnlineNotificationTest < ActiveSupport::TestCase notification_check( OnlineNotification.list(agent_user2, 10), test[:check] ) # check online notifications - if test[:update][:online_notification] - if test[:update][:online_notification][:seen_only_exists] - notifications = OnlineNotification.list_by_object( 'Ticket', ticket.id ) - assert( notification_seen_only_exists_exists( notifications ), 'not seen notifications for ticket available') - else - notifications = OnlineNotification.list_by_object( 'Ticket', ticket.id ) - assert( !notification_seen_only_exists_exists( notifications ), 'seen notifications for ticket available') - end + next if !test[:update][:online_notification] + + if test[:update][:online_notification][:seen_only_exists] + notifications = OnlineNotification.list_by_object( 'Ticket', ticket.id ) + assert( notification_seen_only_exists_exists( notifications ), 'not seen notifications for ticket available') + else + notifications = OnlineNotification.list_by_object( 'Ticket', ticket.id ) + assert( !notification_seen_only_exists_exists( notifications ), 'seen notifications for ticket available') end } @@ -322,27 +321,27 @@ class OnlineNotificationTest < ActiveSupport::TestCase } end - def notification_check( onine_notifications, checks ) + def notification_check( online_notifications, checks ) checks.each { |check_item| hit = false - onine_notifications.each {|onine_notification| - if onine_notification['o_id'] == check_item[:o_id] - if onine_notification['object'] == check_item[:object] - if onine_notification['type'] == check_item[:type] - if onine_notification['created_by_id'] == check_item[:created_by_id] - hit = true - end - end - end - end + online_notifications.each {|onine_notification| + + next if onine_notification['o_id'] != check_item[:o_id] + next if onine_notification['object'] != check_item[:object] + next if onine_notification['type'] != check_item[:type] + next if onine_notification['created_by_id'] != check_item[:created_by_id] + + hit = true + + break } - #puts "--- #{onine_notifications.inspect}" + #puts "--- #{online_notifications.inspect}" assert( hit, "online notification exists not #{check_item.inspect}" ) } end - def notification_seen_only_exists_exists( onine_notifications ) - onine_notifications.each {|onine_notification| + def notification_seen_only_exists_exists( online_notifications ) + online_notifications.each {|onine_notification| return false if !onine_notification['seen'] } true From 70e126a95ce8e70d29ec5c35c712366b3d878e1a Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:42:22 +0200 Subject: [PATCH 27/31] Applied rubocop cop 'Style/Next' and 'Style/UselessAssignment'. --- test/unit/package_test.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/unit/package_test.rb b/test/unit/package_test.rb index 8d58c6d17..0a8b8e8f1 100644 --- a/test/unit/package_test.rb +++ b/test/unit/package_test.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -# rubocop:disable Next, UselessAssignment require 'test_helper' class PackageTest < ActiveSupport::TestCase @@ -281,16 +280,17 @@ X3RhYmxlIDpzYW1wbGVfdGFibGVzDQogIGVuZA0KZW5k exists = Package.where( name: test[:verify][:package][:name], version: test[:verify][:package][:version] ).first assert( exists, "package '#{test[:verify][:package][:name]}' is not installed" ) end - if test[:verify] && test[:verify][:check_files] - test[:verify][:check_files].each {|item| - exists = File.exist?( item[:location] ) - if item[:result] - assert( exists, "'#{item[:location]}' exists" ) - else - assert( !exists, "'#{item[:location]}' doesn't exists" ) - end - } - end + next if !test[:verify] + next if !test[:verify][:check_files] + + test[:verify][:check_files].each {|item| + exists = File.exist?( item[:location] ) + if item[:result] + assert( exists, "'#{item[:location]}' exists" ) + else + assert( !exists, "'#{item[:location]}' doesn't exists" ) + end + } } end From efbeef41e177228b3fa364adc9a8d215a692cae6 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:43:38 +0200 Subject: [PATCH 28/31] Applied rubocop cop 'Style/Next'. --- test/unit/session_collections_test.rb | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/test/unit/session_collections_test.rb b/test/unit/session_collections_test.rb index f570f39b9..c6bd1942e 100644 --- a/test/unit/session_collections_test.rb +++ b/test/unit/session_collections_test.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -# rubocop:disable Next, CyclomaticComplexity require 'test_helper' class SessionCollectionsTest < ActiveSupport::TestCase @@ -139,22 +138,22 @@ class SessionCollectionsTest < ActiveSupport::TestCase def check_if_collection_exists(results, collection, attributes = nil) results.each {|result| next if !result - if result[:collection] && result[:collection][collection] + next if !result[:collection] + next if !result[:collection][collection] - # check just if collection exists - return true if !attributes + # check just if collection exists + return true if !attributes - # check if objetc with attributes in collection exists - result[:collection][collection].each {|item| - match_all = true - attributes.each {|key, value| - if item[ key.to_s ] != value - match_all = false - end - } - return true if match_all + # check if objetc with attributes in collection exists + result[:collection][collection].each {|item| + match_all = true + attributes.each {|key, value| + if item[ key.to_s ] != value + match_all = false + end } - end + return true if match_all + } } nil end From 0c0ebe76d4795b23d8e586468020087f5c23ca17 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:44:57 +0200 Subject: [PATCH 29/31] Applied rubocop cop 'Style/Next' and 'Style/UselessAssignment'. --- test/unit/session_enhanced_test.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/unit/session_enhanced_test.rb b/test/unit/session_enhanced_test.rb index 6fe37ac4c..c31561e59 100644 --- a/test/unit/session_enhanced_test.rb +++ b/test/unit/session_enhanced_test.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -# rubocop:disable Next, UselessAssignment require 'test_helper' class SessionEnhancedTest < ActiveSupport::TestCase @@ -297,15 +296,14 @@ class SessionEnhancedTest < ActiveSupport::TestCase messages.each {|message| #puts "" #puts "message: #{message.inspect}" - if message['event'] == 'resetCollection' - #puts "rc: " - if message['data'] - message['data'].each {|key, _value| - #puts "rc: #{key}" - collections_result[key] = true - } - end - end + next if message['event'] != 'resetCollection' + #puts "rc: " + next if !message['data'] + + message['data'].each {|key, _value| + #puts "rc: #{key}" + collections_result[key] = true + } } #puts "c: #{collections_result.inspect}" collections_orig.each {|key, _value| From c59f61670858425498c99ef5e969e16fbadac096 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:47:23 +0200 Subject: [PATCH 30/31] Applied rubocop cop 'Lint/UnneededDisable'. --- app/controllers/getting_started_controller.rb | 4 ++-- app/models/application_model/activity_stream_base.rb | 1 - app/models/application_model/assets.rb | 1 - app/models/application_model/background_job_search_index.rb | 1 - app/models/application_model/history_log_base.rb | 1 - app/models/application_model/search_index_base.rb | 1 - app/models/store/provider/file.rb | 2 -- app/models/ticket/activity_stream_log.rb | 1 - app/models/ticket/article.rb | 1 - app/models/ticket/article/activity_stream_log.rb | 1 - app/models/ticket/assets.rb | 1 - app/models/ticket/counter.rb | 1 - app/models/ticket/escalation.rb | 1 - app/models/ticket/history_log.rb | 1 - app/models/ticket/number/date.rb | 1 - app/models/ticket/overviews.rb | 1 - app/models/ticket/permission.rb | 1 - app/models/ticket/priority.rb | 1 - app/models/ticket/screen_options.rb | 1 - app/models/ticket/search.rb | 1 - app/models/ticket/search_index.rb | 1 - app/models/ticket/state.rb | 3 +-- app/models/ticket/state_type.rb | 3 +-- app/models/ticket/subject.rb | 1 - test/integration/elasticsearch_test.rb | 1 - test/integration/twitter_test.rb | 1 - test/integration_test_helper.rb | 1 - test/test_helper.rb | 1 - test/unit/history_test.rb | 1 - test/unit/rest_test.rb | 1 - test/unit/session_basic_test.rb | 1 - test/unit/session_basic_ticket_test.rb | 1 - 32 files changed, 4 insertions(+), 36 deletions(-) diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index a38be1db8..4147f56df 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -673,7 +673,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} message: e.to_s, subject: subject, } - return # rubocop:disable Lint/NonLocalExitFromIterator + return end next if !found @@ -735,7 +735,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} render json: { result: 'ok', } - return # rubocop:disable Lint/NonLocalExitFromIterator + return } # check delivery for 30 sek. diff --git a/app/models/application_model/activity_stream_base.rb b/app/models/application_model/activity_stream_base.rb index 7e7d42c7d..e4233237b 100644 --- a/app/models/application_model/activity_stream_base.rb +++ b/app/models/application_model/activity_stream_base.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module ApplicationModel::ActivityStreamBase =begin diff --git a/app/models/application_model/assets.rb b/app/models/application_model/assets.rb index 9250740da..1080db158 100644 --- a/app/models/application_model/assets.rb +++ b/app/models/application_model/assets.rb @@ -1,5 +1,4 @@ #36 Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module ApplicationModel::Assets =begin diff --git a/app/models/application_model/background_job_search_index.rb b/app/models/application_model/background_job_search_index.rb index bae7e1716..4d71aace3 100644 --- a/app/models/application_model/background_job_search_index.rb +++ b/app/models/application_model/background_job_search_index.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren class ApplicationModel::BackgroundJobSearchIndex def initialize(object, o_id) @object = object diff --git a/app/models/application_model/history_log_base.rb b/app/models/application_model/history_log_base.rb index f75166e1d..518b8318a 100644 --- a/app/models/application_model/history_log_base.rb +++ b/app/models/application_model/history_log_base.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module ApplicationModel::HistoryLogBase =begin diff --git a/app/models/application_model/search_index_base.rb b/app/models/application_model/search_index_base.rb index 326f713c7..863b9e481 100644 --- a/app/models/application_model/search_index_base.rb +++ b/app/models/application_model/search_index_base.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module ApplicationModel::SearchIndexBase =begin diff --git a/app/models/store/provider/file.rb b/app/models/store/provider/file.rb index 69ed9c9af..c83080a67 100644 --- a/app/models/store/provider/file.rb +++ b/app/models/store/provider/file.rb @@ -1,6 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren - class Store::Provider::File # write file to fs diff --git a/app/models/ticket/activity_stream_log.rb b/app/models/ticket/activity_stream_log.rb index 1533d6479..47c924d67 100644 --- a/app/models/ticket/activity_stream_log.rb +++ b/app/models/ticket/activity_stream_log.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::ActivityStreamLog =begin diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index 3869a3177..4f1806977 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren class Ticket::Article < ApplicationModel load 'ticket/article/assets.rb' include Ticket::Article::Assets diff --git a/app/models/ticket/article/activity_stream_log.rb b/app/models/ticket/article/activity_stream_log.rb index a3a7809b8..07365d6c7 100644 --- a/app/models/ticket/article/activity_stream_log.rb +++ b/app/models/ticket/article/activity_stream_log.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::Article::ActivityStreamLog =begin diff --git a/app/models/ticket/assets.rb b/app/models/ticket/assets.rb index a2fe4feef..5a75f2117 100644 --- a/app/models/ticket/assets.rb +++ b/app/models/ticket/assets.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::Assets =begin diff --git a/app/models/ticket/counter.rb b/app/models/ticket/counter.rb index d5210297d..ec0aa1d13 100644 --- a/app/models/ticket/counter.rb +++ b/app/models/ticket/counter.rb @@ -1,4 +1,3 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren class Ticket::Counter < ApplicationModel end diff --git a/app/models/ticket/escalation.rb b/app/models/ticket/escalation.rb index 66508ad2a..371d1625f 100644 --- a/app/models/ticket/escalation.rb +++ b/app/models/ticket/escalation.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::Escalation =begin diff --git a/app/models/ticket/history_log.rb b/app/models/ticket/history_log.rb index b9157ef8b..7410b0a14 100644 --- a/app/models/ticket/history_log.rb +++ b/app/models/ticket/history_log.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::HistoryLog =begin diff --git a/app/models/ticket/number/date.rb b/app/models/ticket/number/date.rb index d86dfa83d..42f0ef8c3 100644 --- a/app/models/ticket/number/date.rb +++ b/app/models/ticket/number/date.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::Number::Date module_function diff --git a/app/models/ticket/overviews.rb b/app/models/ticket/overviews.rb index 0e019258a..de346ddc6 100644 --- a/app/models/ticket/overviews.rb +++ b/app/models/ticket/overviews.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::Overviews =begin diff --git a/app/models/ticket/permission.rb b/app/models/ticket/permission.rb index 1e27ea837..4d4ba9b0e 100644 --- a/app/models/ticket/permission.rb +++ b/app/models/ticket/permission.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::Permission =begin diff --git a/app/models/ticket/priority.rb b/app/models/ticket/priority.rb index 652c70089..dd829a162 100644 --- a/app/models/ticket/priority.rb +++ b/app/models/ticket/priority.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren class Ticket::Priority < ApplicationModel self.table_name = 'ticket_priorities' validates :name, presence: true diff --git a/app/models/ticket/screen_options.rb b/app/models/ticket/screen_options.rb index 6ff37e375..adf41074e 100644 --- a/app/models/ticket/screen_options.rb +++ b/app/models/ticket/screen_options.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::ScreenOptions =begin diff --git a/app/models/ticket/search.rb b/app/models/ticket/search.rb index db14243ac..0a00baa50 100644 --- a/app/models/ticket/search.rb +++ b/app/models/ticket/search.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::Search =begin diff --git a/app/models/ticket/search_index.rb b/app/models/ticket/search_index.rb index 1a6bda4fb..75fc76b64 100644 --- a/app/models/ticket/search_index.rb +++ b/app/models/ticket/search_index.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::SearchIndex =begin diff --git a/app/models/ticket/state.rb b/app/models/ticket/state.rb index 99185a45b..a95eed6d0 100644 --- a/app/models/ticket/state.rb +++ b/app/models/ticket/state.rb @@ -1,7 +1,6 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren class Ticket::State < ApplicationModel - belongs_to :state_type, class_name: 'Ticket::StateType' + belongs_to :state_type, class_name: 'Ticket::StateType' validates :name, presence: true latest_change_support diff --git a/app/models/ticket/state_type.rb b/app/models/ticket/state_type.rb index a48b46082..6df994e30 100644 --- a/app/models/ticket/state_type.rb +++ b/app/models/ticket/state_type.rb @@ -1,7 +1,6 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren class Ticket::StateType < ApplicationModel - has_many :states, class_name: 'Ticket::State' + has_many :states, class_name: 'Ticket::State' validates :name, presence: true latest_change_support end diff --git a/app/models/ticket/subject.rb b/app/models/ticket/subject.rb index 18dbc327d..4c946891a 100644 --- a/app/models/ticket/subject.rb +++ b/app/models/ticket/subject.rb @@ -1,5 +1,4 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable ClassAndModuleChildren module Ticket::Subject =begin diff --git a/test/integration/elasticsearch_test.rb b/test/integration/elasticsearch_test.rb index ed2385a85..770ecf07e 100644 --- a/test/integration/elasticsearch_test.rb +++ b/test/integration/elasticsearch_test.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -# rubocop:disable UselessAssignment require 'integration_test_helper' class ElasticsearchTest < ActiveSupport::TestCase diff --git a/test/integration/twitter_test.rb b/test/integration/twitter_test.rb index 4e82d674c..9fbb24f9a 100644 --- a/test/integration/twitter_test.rb +++ b/test/integration/twitter_test.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -# rubocop:disable UselessAssignment require 'integration_test_helper' class TwitterTest < ActiveSupport::TestCase diff --git a/test/integration_test_helper.rb b/test/integration_test_helper.rb index e124cab15..5c596be20 100644 --- a/test/integration_test_helper.rb +++ b/test/integration_test_helper.rb @@ -1,5 +1,4 @@ ENV['RAILS_ENV'] = 'test' -# rubocop:disable ClassAndModuleChildren require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require 'cache' diff --git a/test/test_helper.rb b/test/test_helper.rb index d170f3842..c490c6b4b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,4 @@ ENV['RAILS_ENV'] = 'test' -# rubocop:disable ClassAndModuleChildren require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require 'cache' diff --git a/test/unit/history_test.rb b/test/unit/history_test.rb index 777b7875b..6a71bdb97 100644 --- a/test/unit/history_test.rb +++ b/test/unit/history_test.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -# rubocop:disable PerceivedComplexity, CyclomaticComplexity require 'test_helper' class HistoryTest < ActiveSupport::TestCase diff --git a/test/unit/rest_test.rb b/test/unit/rest_test.rb index 37ef2ceeb..4bc121fdd 100644 --- a/test/unit/rest_test.rb +++ b/test/unit/rest_test.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -# rubocop:disable UselessAssignment require 'test_helper' class RestTest < ActiveSupport::TestCase diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index 02e53a465..1b4551482 100644 --- a/test/unit/session_basic_test.rb +++ b/test/unit/session_basic_test.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -# rubocop:disable UselessAssignment require 'test_helper' class SessionBasicTest < ActiveSupport::TestCase diff --git a/test/unit/session_basic_ticket_test.rb b/test/unit/session_basic_ticket_test.rb index 2899a8403..29867dc6b 100644 --- a/test/unit/session_basic_ticket_test.rb +++ b/test/unit/session_basic_ticket_test.rb @@ -1,5 +1,4 @@ # encoding: utf-8 -# rubocop:disable UselessAssignment require 'test_helper' class SessionBasicTicketTest < ActiveSupport::TestCase From bd9d231de8136eb2e286017ad86dfa4c4a033973 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 3 Jul 2015 19:48:30 +0200 Subject: [PATCH 31/31] Applied rubocop cop 'Lint/DefEndAlignment'. --- lib/tweet.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tweet.rb b/lib/tweet.rb index abffd60e5..ffead1269 100644 --- a/lib/tweet.rb +++ b/lib/tweet.rb @@ -40,7 +40,7 @@ class Tweet Rails.logger.error "Twitter (#{tweet.id}): unknown user source" - end + end def to_user(tweet)