Some new rubocop checks.

This commit is contained in:
Martin Edenhofer 2015-04-27 22:49:17 +02:00
parent c694f2f37e
commit 60121a25fb
13 changed files with 167 additions and 175 deletions

View file

@ -171,7 +171,7 @@ class ApplicationController < ActionController::Base
} }
end end
return { {
auth: true auth: true
} }
end end

View file

@ -173,7 +173,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
# check domain based attributes # check domain based attributes
providerMap = { provider_map = {
google: { google: {
domain: 'gmail.com|googlemail.com|gmail.de', domain: 'gmail.com|googlemail.com|gmail.de',
inbound: { inbound: {
@ -231,7 +231,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0] if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0]
domains.push mail_exchangers[0][0] domains.push mail_exchangers[0][0]
end end
providerMap.each {|provider, settings| provider_map.each {|provider, settings|
domains.each {|domain_to_check| domains.each {|domain_to_check|
if domain_to_check =~ /#{settings[:domain]}/i if domain_to_check =~ /#{settings[:domain]}/i
@ -259,9 +259,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
} }
# probe inbound # probe inbound
inboundMap = [] inbound_map = []
if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0] if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0]
inboundMx = [ inbound_mx = [
{ {
adapter: 'imap', adapter: 'imap',
options: { options: {
@ -283,9 +283,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
}, },
}, },
] ]
inboundMap = inboundMap + inboundMx inbound_map = inbound_map + inbound_mx
end end
inboundAuto = [ inbound_auto = [
{ {
adapter: 'imap', adapter: 'imap',
options: { options: {
@ -387,10 +387,10 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
}, },
}, },
] ]
inboundMap = inboundMap + inboundAuto inbound_map = inbound_map + inbound_auto
settings = {} settings = {}
success = false success = false
inboundMap.each {|config| inbound_map.each {|config|
logger.info "INBOUND PROBE: #{config.inspect}" logger.info "INBOUND PROBE: #{config.inspect}"
result = email_probe_inbound( config ) result = email_probe_inbound( config )
logger.info "INBOUND RESULT: #{result.inspect}" logger.info "INBOUND RESULT: #{result.inspect}"
@ -409,9 +409,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
# probe outbound # probe outbound
outboundMap = [] outbound_map = []
if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0] if mail_exchangers && mail_exchangers[0] && mail_exchangers[0][0]
outboundMx = [ outbound_mx = [
{ {
adapter: 'smtp', adapter: 'smtp',
options: { options: {
@ -453,9 +453,9 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
}, },
}, },
] ]
outboundMap = outboundMap + outboundMx outbound_map = outbound_map + outbound_mx
end end
outboundAuto = [ outbound_auto = [
{ {
adapter: 'smtp', adapter: 'smtp',
options: { options: {
@ -539,7 +539,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
] ]
success = false success = false
outboundMap.each {|config| outbound_map.each {|config|
logger.info "OUTBOUND PROBE: #{config.inspect}" logger.info "OUTBOUND PROBE: #{config.inspect}"
result = email_probe_outbound( config, params[:email] ) result = email_probe_outbound( config, params[:email] )
logger.info "OUTBOUND RESULT: #{result.inspect}" logger.info "OUTBOUND RESULT: #{result.inspect}"
@ -599,7 +599,6 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
result = email_probe_inbound( params ) result = email_probe_inbound( params )
render json: result render json: result
return
end end
def email_verify def email_verify
@ -737,7 +736,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
# test connection # test connection
translationMap = { translation_map = {
'authentication failed' => 'Authentication failed!', 'authentication failed' => 'Authentication failed!',
'Incorrect username' => 'Authentication failed!', 'Incorrect username' => 'Authentication failed!',
'getaddrinfo: nodename nor servname provided, or not known' => 'Hostname not found!', 'getaddrinfo: nodename nor servname provided, or not known' => 'Hostname not found!',
@ -747,10 +746,10 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
if params[:adapter] =~ /^smtp$/i if params[:adapter] =~ /^smtp$/i
# in case, fill missing params # in case, fill missing params
if !params[:options].has_key?(:port) if !params[:options].key?(:port)
params[:options][:port] = 25 params[:options][:port] = 25
end end
if !params[:options].has_key?(:ssl) if !params[:options].key?(:ssl)
params[:options][:ssl] = true params[:options][:ssl] = true
end end
@ -765,10 +764,10 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
# check if sending email was ok, but mailserver rejected # check if sending email was ok, but mailserver rejected
if !subject if !subject
whiteMap = { white_map = {
'Recipient address rejected' => true, 'Recipient address rejected' => true,
} }
whiteMap.each {|key, message| white_map.each {|key, message|
if e.message =~ /#{Regexp.escape(key)}/i if e.message =~ /#{Regexp.escape(key)}/i
result = { result = {
result: 'ok', result: 'ok',
@ -780,7 +779,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
} }
end end
message_human = '' message_human = ''
translationMap.each {|key, message| translation_map.each {|key, message|
if e.message =~ /#{Regexp.escape(key)}/i if e.message =~ /#{Regexp.escape(key)}/i
message_human = message message_human = message
end end
@ -806,7 +805,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
) )
rescue Exception => e rescue Exception => e
message_human = '' message_human = ''
translationMap.each {|key, message| translation_map.each {|key, message|
if e.message =~ /#{Regexp.escape(key)}/i if e.message =~ /#{Regexp.escape(key)}/i
message_human = message message_human = message
end end
@ -822,7 +821,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
result = { result = {
result: 'ok', result: 'ok',
} }
return result result
end end
def email_probe_inbound(params) def email_probe_inbound(params)
@ -833,7 +832,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
# connection test # connection test
translationMap = { translation_map = {
'authentication failed' => 'Authentication failed!', 'authentication failed' => 'Authentication failed!',
'Incorrect username' => 'Authentication failed!', 'Incorrect username' => 'Authentication failed!',
'getaddrinfo: nodename nor servname provided, or not known' => 'Hostname not found!', 'getaddrinfo: nodename nor servname provided, or not known' => 'Hostname not found!',
@ -846,7 +845,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
Channel::IMAP.new.fetch( { options: params[:options] }, 'check' ) Channel::IMAP.new.fetch( { options: params[:options] }, 'check' )
rescue Exception => e rescue Exception => e
message_human = '' message_human = ''
translationMap.each {|key, message| translation_map.each {|key, message|
if e.message =~ /#{Regexp.escape(key)}/i if e.message =~ /#{Regexp.escape(key)}/i
message_human = message message_human = message
end end
@ -869,7 +868,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
Channel::POP3.new.fetch( { options: params[:options] }, 'check' ) Channel::POP3.new.fetch( { options: params[:options] }, 'check' )
rescue Exception => e rescue Exception => e
message_human = '' message_human = ''
translationMap.each {|key, message| translation_map.each {|key, message|
if e.message =~ /#{Regexp.escape(key)}/i if e.message =~ /#{Regexp.escape(key)}/i
message_human = message message_human = message
end end
@ -885,7 +884,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
result = { result = {
result: 'ok', result: 'ok',
} }
return result result
end end
def mxers(domain) def mxers(domain)

View file

@ -29,7 +29,7 @@ class LongPollingController < ApplicationController
# error handling # error handling
if params['data']['timestamp'] if params['data']['timestamp']
log 'notice', "request spool data > '#{Time.at( params['data']['timestamp'] ).to_s}'", client_id log 'notice', "request spool data > '#{Time.at( params['data']['timestamp'] )}'", client_id
else else
log 'notice', 'request spool init data', client_id log 'notice', 'request spool init data', client_id
end end
@ -75,13 +75,13 @@ class LongPollingController < ApplicationController
if params['data']['recipient'] && params['data']['recipient']['user_id'] if params['data']['recipient'] && params['data']['recipient']['user_id']
params['data']['recipient']['user_id'].each { |user_id| params['data']['recipient']['user_id'].each { |user_id|
if local_client[:user]['id'].to_s == user_id.to_s if local_client[:user]['id'].to_s == user_id.to_s
log 'notice', "send broadcast from (#{client_id.to_s}) to (user_id #{user_id})", local_client_id log 'notice', "send broadcast from (#{client_id}) to (user_id #{user_id})", local_client_id
Sessions.send( local_client_id, params['data'] ) Sessions.send( local_client_id, params['data'] )
end end
} }
# broadcast every client # broadcast every client
else else
log 'notice', "send broadcast from (#{client_id.to_s})", local_client_id log 'notice', "send broadcast from (#{client_id})", local_client_id
Sessions.send( local_client_id, params['data'] ) Sessions.send( local_client_id, params['data'] )
end end
else else
@ -155,14 +155,14 @@ class LongPollingController < ApplicationController
return if !params[:client_id] return if !params[:client_id]
sessions = Sessions.sessions sessions = Sessions.sessions
return if !sessions.include?( params[:client_id].to_s ) return if !sessions.include?( params[:client_id].to_s )
return params[:client_id].to_s params[:client_id].to_s
end end
def log( level, data, client_id = '-' ) def log( level, data, client_id = '-' )
if false if false
return if level == 'debug' return if level == 'debug'
end end
puts "#{Time.now}:client(#{ client_id }) #{ data }" puts "#{Time.zone.now}:client(#{ client_id }) #{ data }"
# puts "#{Time.now}:#{ level }:client(#{ client_id }) #{ data }" # puts "#{Time.now}:#{ level }:client(#{ client_id }) #{ data }"
end end
end end

View file

@ -32,7 +32,7 @@ class TagsController < ApplicationController
object: params[:object], object: params[:object],
o_id: params[:o_id], o_id: params[:o_id],
item: params[:item], item: params[:item],
); )
if success if success
render json: success, status: :created render json: success, status: :created
else else
@ -46,7 +46,7 @@ class TagsController < ApplicationController
object: params[:object], object: params[:object],
o_id: params[:o_id], o_id: params[:o_id],
item: params[:item], item: params[:item],
); )
if success if success
render json: success, status: :created render json: success, status: :created
else else

View file

@ -38,11 +38,12 @@ class TaskbarController < ApplicationController
end end
private private
def access(taskbar) def access(taskbar)
if taskbar.user_id != current_user.id if taskbar.user_id != current_user.id
render json: { error: 'Not allowed to access this task.' }, status: :unprocessable_entity render json: { error: 'Not allowed to access this task.' }, status: :unprocessable_entity
return false return false
end end
return true true
end end
end end

View file

@ -360,7 +360,7 @@ class TicketsController < ApplicationController
limit = 100 limit = 100
assets = {} assets = {}
access_condition = Ticket.access_condition( current_user ) access_condition = Ticket.access_condition( current_user )
now = DateTime.now now = Time.zone.now
user_tickets_open_ids = [] user_tickets_open_ids = []
user_tickets_closed_ids = [] user_tickets_closed_ids = []
user_ticket_volume_by_year = [] user_ticket_volume_by_year = []
@ -395,8 +395,8 @@ class TicketsController < ApplicationController
# generate stats by user # generate stats by user
(0..11).each {|month_back| (0..11).each {|month_back|
date_to_check = DateTime.now - month_back.month date_to_check = Time.zone.now - month_back.month
date_start = "#{date_to_check.year}-#{date_to_check.month}-#{01} 00:00:00" date_start = "#{date_to_check.year}-#{date_to_check.month}-01 00:00:00"
date_end = "#{date_to_check.year}-#{date_to_check.month}-#{date_to_check.end_of_month.day} 00:00:00" date_end = "#{date_to_check.year}-#{date_to_check.month}-#{date_to_check.end_of_month.day} 00:00:00"
condition = { condition = {
@ -463,7 +463,7 @@ class TicketsController < ApplicationController
# generate stats by org # generate stats by org
(0..11).each {|month_back| (0..11).each {|month_back|
date_to_check = DateTime.now - month_back.month date_to_check = DateTime.now - month_back.month
date_start = "#{date_to_check.year}-#{date_to_check.month}-#{01} 00:00:00" date_start = "#{date_to_check.year}-#{date_to_check.month}-01 00:00:00"
date_end = "#{date_to_check.year}-#{date_to_check.month}-#{date_to_check.end_of_month.day} 00:00:00" date_end = "#{date_to_check.year}-#{date_to_check.month}-#{date_to_check.end_of_month.day} 00:00:00"
condition = { condition = {
@ -507,7 +507,7 @@ class TicketsController < ApplicationController
ticket_ids.push ticket.id ticket_ids.push ticket.id
assets = ticket.assets(assets) assets = ticket.assets(assets)
end end
return ticket_ids ticket_ids
end end
def article_create(ticket, params) def article_create(ticket, params)

View file

@ -644,7 +644,7 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
content: file_resize[:content], content: file_resize[:content],
mime_type: file_resize[:mime_type], mime_type: file_resize[:mime_type],
}, },
source: 'upload ' + Time.now.to_s, source: 'upload ' + Time.zone.now.to_s,
deletable: true, deletable: true,
) )
@ -719,7 +719,7 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
return true if is_role('Agent') return true if is_role('Agent')
response_access_deny response_access_deny
return false false
end end
def permission_check def permission_check
@ -730,7 +730,7 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
return true if is_role(Z_ROLENAME_CUSTOMER) && params[:id].to_i == current_user.id return true if is_role(Z_ROLENAME_CUSTOMER) && params[:id].to_i == current_user.id
response_access_deny response_access_deny
return false false
end end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module User::Permission module User
module Permission
=begin =begin
@ -32,5 +33,5 @@ returns
return true if data[:current_user].is_role('Agent') return true if data[:current_user].is_role('Agent')
false false
end end
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module User::Search module User
module Search
=begin =begin
@ -52,5 +53,5 @@ returns
end end
users users
end end
end
end end

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
module User::SearchIndex module User
module SearchIndex
=begin =begin
@ -26,3 +27,4 @@ returns
attributes attributes
end end
end end
end

View file

@ -220,9 +220,7 @@ class TestCase < Test::Unit::TestCase
else else
instance.find_elements( { partial_link_text: params[:text] } )[0].click instance.find_elements( { partial_link_text: params[:text] } )[0].click
end end
if !params[:fast] sleep 0.4 if !params[:fast]
sleep 0.4
end
end end
=begin =begin
@ -357,9 +355,7 @@ class TestCase < Test::Unit::TestCase
element = instance.find_elements( { css: params[:css] } )[0] element = instance.find_elements( { css: params[:css] } )[0]
checked = element.attribute('checked') checked = element.attribute('checked')
if !checked element.click if !checked
element.click
end
end end
=begin =begin
@ -378,9 +374,7 @@ class TestCase < Test::Unit::TestCase
element = instance.find_elements( { css: params[:css] } )[0] element = instance.find_elements( { css: params[:css] } )[0]
checked = element.attribute('checked') checked = element.attribute('checked')
if checked element.click if checked
element.click
end
end end
=begin =begin
@ -760,8 +754,6 @@ class TestCase < Test::Unit::TestCase
sleep 0.5 sleep 0.5
return true return true
end end
rescue
# just try again
end end
end end
sleep 0.5 sleep 0.5
@ -816,8 +808,6 @@ wait untill text in selector disabppears
sleep 1 sleep 1
return true return true
end end
rescue
# just try again
end end
end end
sleep 1 sleep 1
@ -839,7 +829,7 @@ wait untill text in selector disabppears
instance = params[:browser] || @browser instance = params[:browser] || @browser
for i in 1..100 (1..100).each do
sleep 1 sleep 1
begin begin
if instance.find_elements( { css: '.navigation .tasks .task:first-child' } )[0] if instance.find_elements( { css: '.navigation .tasks .task:first-child' } )[0]
@ -860,8 +850,6 @@ wait untill text in selector disabppears
else else
break break
end end
rescue
# just try again
end end
end end
sleep 1 sleep 1
@ -1047,7 +1035,7 @@ wait untill text in selector disabppears
sleep 2.5 sleep 2.5
id = instance.current_url id = instance.current_url
id.gsub!(//, ) id.gsub!(//, )
id.gsub!(/^.+?\/(\d+)$/, '\\1') id.gsub!(%r{^.+?/(\d+)$}, '\\1')
element = instance.find_elements( { css: '.active .page-header .ticket-number' } )[0] element = instance.find_elements( { css: '.active .page-header .ticket-number' } )[0]
if element if element
@ -1203,8 +1191,6 @@ wait untill text in selector disabppears
if text =~ /(Discard your unsaved changes.|Verwerfen der)/ if text =~ /(Discard your unsaved changes.|Verwerfen der)/
found = true found = true
end end
rescue
# just try again
end end
sleep 1 sleep 1
end end
@ -1227,8 +1213,6 @@ wait untill text in selector disabppears
if !text || text.empty? if !text || text.empty?
return true return true
end end
rescue
# just try again
end end
sleep 1 sleep 1
} }
@ -1374,7 +1358,7 @@ wait untill text in selector disabppears
overviews = {} overviews = {}
instance.find_elements( { css: '.content.active .sidebar a[href]' } ).each {|element| instance.find_elements( { css: '.content.active .sidebar a[href]' } ).each {|element|
url = element.attribute('href') url = element.attribute('href')
url.gsub!(/(http|https):\/\/.+?\/(.+?)$/, '\\2') url.gsub!(%r{(http|https)://.+?/(.+?)$}, '\\2')
overviews[url] = 0 overviews[url] = 0
#puts url.inspect #puts url.inspect
#puts element.inspect #puts element.inspect

View file

@ -3,7 +3,8 @@ require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help' require 'rails/test_help'
require 'cache' require 'cache'
class ActiveSupport::TestCase module ActiveSupport
class TestCase
# disable transactions # disable transactions
#self.use_transactional_fixtures = false #self.use_transactional_fixtures = false
@ -25,3 +26,4 @@ class ActiveSupport::TestCase
# Add more helper methods to be used by all tests here... # Add more helper methods to be used by all tests here...
end end
end

View file

@ -5,7 +5,8 @@ require 'cache'
require 'simplecov' require 'simplecov'
require 'simplecov-rcov' require 'simplecov-rcov'
class ActiveSupport::TestCase module ActiveSupport
class TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
# #
# Note: You'll currently still have to declare fixtures explicitly in integration tests # Note: You'll currently still have to declare fixtures explicitly in integration tests
@ -38,3 +39,4 @@ class ActiveSupport::TestCase
# Add more helper methods to be used by all tests here... # Add more helper methods to be used by all tests here...
end end
end