Corrected with rubocop cop 'Lint/UnusedBlockArgument'.

This commit is contained in:
Thorsten Eckel 2015-05-07 11:49:46 +02:00
parent 1ac1cf4184
commit c282fd2b37
22 changed files with 55 additions and 58 deletions

View file

@ -200,11 +200,6 @@ Style/RedundantBegin:
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#begin-implicit' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#begin-implicit'
Enabled: false Enabled: false
Lint/UnusedBlockArgument:
Description: 'Checks for unused block arguments.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
Enabled: false
Style/SignalException: Style/SignalException:
Description: 'Checks for proper usage of fail and raise.' Description: 'Checks for proper usage of fail and raise.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#fail-method' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#fail-method'

View file

@ -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
provider_map.each {|provider, settings| provider_map.each {|_provider, settings|
domains.each {|domain_to_check| domains.each {|domain_to_check|
next if domain_to_check !~ /#{settings[:domain]}/i next if domain_to_check !~ /#{settings[:domain]}/i
@ -616,7 +616,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end end
result = email_probe_outbound( params[:outbound], params[:meta][:email], subject ) result = email_probe_outbound( params[:outbound], params[:meta][:email], subject )
(1..5).each {|loop| (1..5).each {
sleep 10 sleep 10
# fetch mailbox # fetch mailbox
@ -769,7 +769,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
white_map = { white_map = {
'Recipient address rejected' => true, 'Recipient address rejected' => true,
} }
white_map.each {|key, message| white_map.each {|key, _message|
next if e.message !~ /#{Regexp.escape(key)}/i next if e.message !~ /#{Regexp.escape(key)}/i

View file

@ -112,7 +112,7 @@ class LongPollingController < ApplicationController
begin begin
# update last ping # update last ping
4.times {|loop| 4.times {
sleep 0.25 sleep 0.25
} }
#sleep 1 #sleep 1
@ -128,7 +128,7 @@ class LongPollingController < ApplicationController
render json: queue render json: queue
return return
end end
8.times {|loop| 8.times {
sleep 0.25 sleep 0.25
} }
#sleep 2 #sleep 2

View file

@ -761,7 +761,7 @@ log object update activity stream, if configured - will be executed automaticall
end end
log = false log = false
self.changes.each {|key, value| self.changes.each {|key, _value|
# do not log created_at and updated_at attributes # do not log created_at and updated_at attributes
next if ignore_attributes[key.to_sym] == true next if ignore_attributes[key.to_sym] == true

View file

@ -335,7 +335,7 @@ class Channel::EmailParser
} }
# filter( channel, mail ) # filter( channel, mail )
filters.each {|prio, backend| filters.each {|_prio, backend|
begin begin
backend.run( channel, mail ) backend.run( channel, mail )
rescue Exception => e rescue Exception => e
@ -484,7 +484,7 @@ class Channel::EmailParser
} }
# filter( channel, mail ) # filter( channel, mail )
filters.each {|prio, backend| filters.each {|_prio, backend|
begin begin
backend.run( channel, mail, ticket, article, user ) backend.run( channel, mail, ticket, article, user )
rescue Exception => e rescue Exception => e
@ -529,7 +529,7 @@ class Channel::EmailParser
def set_attributes_by_x_headers( item_object, header_name, mail ) def set_attributes_by_x_headers( item_object, header_name, mail )
# loop all x-zammad-hedaer-* headers # loop all x-zammad-hedaer-* headers
item_object.attributes.each {|key, value| item_object.attributes.each {|key, _value|
# ignore read only attributes # ignore read only attributes
next if key == 'updated_at' next if key == 'updated_at'

View file

@ -7,7 +7,7 @@ module Channel::Filter::Trusted
# check if trust x-headers # check if trust x-headers
if !channel[:trusted] if !channel[:trusted]
mail.each {|key, value| mail.each {|key, _value|
if key =~ /^x-zammad/i if key =~ /^x-zammad/i
mail.delete(key) mail.delete(key)
end end

View file

@ -19,7 +19,7 @@ class Observer::Ticket::Notification < ActiveRecord::Observer
# get uniq objects # get uniq objects
list_objects = get_uniq_changes(list) list_objects = get_uniq_changes(list)
list_objects.each {|ticket_id, item| list_objects.each {|_ticket_id, item|
# send background job # send background job
Delayed::Job.enqueue( Observer::Ticket::Notification::BackgroundJob.new( item ) ) Delayed::Job.enqueue( Observer::Ticket::Notification::BackgroundJob.new( item ) )

View file

@ -25,8 +25,9 @@ class Setting < ApplicationModel
# config lookups # config lookups
config.each { |key, value| config.each { |key, value|
next if value.class.to_s != 'String' next if value.class.to_s != 'String'
config[key].gsub!( /\#\{config\.(.+?)\}/ ) { |s|
s = config[$1].to_s config[key].gsub!( /\#\{config\.(.+?)\}/ ) {
config[$1].to_s
} }
} }

View file

@ -18,7 +18,7 @@ returns
def self.generate def self.generate
# generate number # generate number
(1..50_000).each { |i| (1..50_000).each {
number = adapter.generate number = adapter.generate
ticket = Ticket.where( number: number ).first ticket = Ticket.where( number: number ).first
return number if !ticket return number if !ticket

View file

@ -31,7 +31,7 @@ module Ticket::Number::Increment
min_digs = min_digs.to_i - 1 min_digs = min_digs.to_i - 1
end end
fillup = Setting.get('system_id') || '1' fillup = Setting.get('system_id') || '1'
( 1..100 ).each do |i| ( 1..100 ).each do |_i|
if ( fillup.length.to_i + counter_increment.to_s.length.to_i ) < min_digs.to_i if ( fillup.length.to_i + counter_increment.to_s.length.to_i ) < min_digs.to_i
fillup = fillup + '0' fillup = fillup + '0'
end end

View file

@ -72,7 +72,7 @@ class String
# find <a href=....> and replace it with [x] # find <a href=....> and replace it with [x]
link_list = '' link_list = ''
counter = 0 counter = 0
string.gsub!( /<a\s.*?href=("|')(.+?)("|').*?>/ix ) { |item| string.gsub!( /<a\s.*?href=("|')(.+?)("|').*?>/ix ) {
link = $2 link = $2
counter = counter + 1 counter = counter + 1
link_list += "[#{counter}] #{link}\n" link_list += "[#{counter}] #{link}\n"
@ -121,12 +121,12 @@ class String
string.gsub!( '&nbsp;', ' ' ) string.gsub!( '&nbsp;', ' ' )
# encode html entities like "&#8211;" # encode html entities like "&#8211;"
string.gsub!( /(&\#(\d+);?)/x ) { |item| string.gsub!( /(&\#(\d+);?)/x ) {
$2.chr $2.chr
} }
# encode html entities like "&#3d;" # encode html entities like "&#3d;"
string.gsub!( /(&\#[xX]([0-9a-fA-F]+);?)/x ) { |item| string.gsub!( /(&\#[xX]([0-9a-fA-F]+);?)/x ) {
chr_orig = $1 chr_orig = $1
hex = $2.hex hex = $2.hex
if hex if hex

View file

@ -14,7 +14,7 @@ module FillDB
# organizations # organizations
organization_pool = [] organization_pool = []
if organizations && !organizations.zero? if organizations && !organizations.zero?
(1..organizations).each {|count| (1..organizations).each {
organization = Organization.create( name: 'FillOrganization::' + rand(999_999).to_s, active: true ) organization = Organization.create( name: 'FillOrganization::' + rand(999_999).to_s, active: true )
organization_pool.push organization organization_pool.push organization
} }
@ -27,7 +27,7 @@ module FillDB
if agents && !agents.zero? if agents && !agents.zero?
roles = Role.where( name: [ 'Agent'] ) roles = Role.where( name: [ 'Agent'] )
groups_all = Group.all groups_all = Group.all
(1..agents).each {|count| (1..agents).each {
suffix = rand(99_999).to_s suffix = rand(99_999).to_s
user = User.create_or_update( user = User.create_or_update(
login: "filldb-agent-#{suffix}", login: "filldb-agent-#{suffix}",
@ -51,7 +51,7 @@ module FillDB
if customers && !customers.zero? if customers && !customers.zero?
roles = Role.where( name: [ 'Customer'] ) roles = Role.where( name: [ 'Customer'] )
groups_all = Group.all groups_all = Group.all
(1..customers).each {|count| (1..customers).each {
suffix = rand(99_999).to_s suffix = rand(99_999).to_s
organization = nil organization = nil
if !organization_pool.empty? && rand(2) == 1 if !organization_pool.empty? && rand(2) == 1
@ -77,7 +77,7 @@ module FillDB
group_pool = [] group_pool = []
if groups && !groups.zero? if groups && !groups.zero?
puts "1..#{groups}" puts "1..#{groups}"
(1..groups).each {|count| (1..groups).each {
group = Group.create( name: 'FillGroup::' + rand(999_999).to_s, active: true ) group = Group.create( name: 'FillGroup::' + rand(999_999).to_s, active: true )
group_pool.push group group_pool.push group
Role.where(name: 'Agent').first.users.where(active: true).each {|user| Role.where(name: 'Agent').first.users.where(active: true).each {|user|
@ -95,7 +95,7 @@ module FillDB
priority_pool = Ticket::Priority.all priority_pool = Ticket::Priority.all
state_pool = Ticket::State.all state_pool = Ticket::State.all
if tickets && !tickets.zero? if tickets && !tickets.zero?
(1..tickets).each {|count| (1..tickets).each {
customer = customer_pool[ rand(customer_pool.length - 1) ] customer = customer_pool[ rand(customer_pool.length - 1) ]
agent = agent_pool[ rand(agent_pool.length - 1) ] agent = agent_pool[ rand(agent_pool.length - 1) ]
ticket = Ticket.create( ticket = Ticket.create(

View file

@ -81,10 +81,11 @@ module NotificationFactory
} }
# translate # translate
data[:string].gsub!( /i18n\((|.+?)\)/ ) { |placeholder| data[:string].gsub!( /i18n\((|.+?)\)/ ) {
string = $1 string = $1
locale = data[:locale] || 'en' locale = data[:locale] || 'en'
placeholder = Translation.translate( locale, string )
Translation.translate( locale, string )
} }
data[:string] data[:string]

View file

@ -36,8 +36,8 @@ class Sessions::Client
user_id_last_run = user.id user_id_last_run = user.id
# release old objects # release old objects
backend_pool.each {|pool| backend_pool.collect! {
pool = nil nil
} }
# create new pool # create new pool

View file

@ -2,7 +2,7 @@ $LOAD_PATH << './lib'
require 'rubygems' require 'rubygems'
namespace :searchindex do namespace :searchindex do
task :drop, [:opts] => :environment do |t, args| task :drop, [:opts] => :environment do |_t, _args|
# drop indexes # drop indexes
puts 'drop indexes...' puts 'drop indexes...'
@ -12,7 +12,7 @@ namespace :searchindex do
end end
task :create, [:opts] => :environment do |t, args| task :create, [:opts] => :environment do |_t, _args|
# create indexes # create indexes
puts 'create indexes...' puts 'create indexes...'
@ -39,7 +39,7 @@ namespace :searchindex do
end end
task :reload, [:opts] => :environment do |t, args| task :reload, [:opts] => :environment do |_t, _args|
puts 'reload data...' puts 'reload data...'
User.search_index_reload User.search_index_reload
@ -48,7 +48,7 @@ namespace :searchindex do
end end
task :rebuild, [:opts] => :environment do |t, args| task :rebuild, [:opts] => :environment do |_t, _args|
Rake::Task['searchindex:drop'].execute Rake::Task['searchindex:drop'].execute
Rake::Task['searchindex:create'].execute Rake::Task['searchindex:create'].execute

View file

@ -3,7 +3,7 @@ require 'rubygems'
namespace :test do namespace :test do
desc 'Start browser tests' desc 'Start browser tests'
task :browser, [:opts] => :environment do |t, args| task :browser, [:opts] => :environment do |_t, args|
start = Time.now() start = Time.now()
if !args.opts if !args.opts

View file

@ -69,10 +69,10 @@ put working hours matrix and timezone in function, returns UTC working hours mat
Sat: [], Sat: [],
Sun: [], Sun: [],
} }
(1..hours_to_shift).each {|count| (1..hours_to_shift).each {
working_hours.each {|day, value| working_hours.each {|day, value|
next if !working_hours[day] next if !value
to_move = working_hours[day].shift to_move = working_hours[day].shift
if day == :Mon if day == :Mon

View file

@ -243,14 +243,14 @@ EventMachine.run {
# websocket # websocket
log 'notice', "Status: websocket clients: #{ @clients.size }" log 'notice', "Status: websocket clients: #{ @clients.size }"
@clients.each { |client_id, client| @clients.each { |client_id, _client|
log 'notice', 'working...', client_id log 'notice', 'working...', client_id
} }
# ajax # ajax
client_list = Sessions.list client_list = Sessions.list
clients = 0 clients = 0
client_list.each {|client_id, client| client_list.each {|_client_id, client|
next if client[:meta][:type] == 'websocket' next if client[:meta][:type] == 'websocket'
clients = clients + 1 clients = clients + 1
} }

View file

@ -68,7 +68,7 @@ class TestCase < Test::Unit::TestCase
def teardown def teardown
return if !@browsers return if !@browsers
@browsers.each { |hash, local_browser| @browsers.each { |_hash, local_browser|
screenshot( browser: local_browser, comment: 'teardown' ) screenshot( browser: local_browser, comment: 'teardown' )
browser_instance_close(local_browser) browser_instance_close(local_browser)
} }
@ -149,7 +149,7 @@ class TestCase < Test::Unit::TestCase
instance.find_elements( { css: 'a[href="#current_user"]' } )[0].click instance.find_elements( { css: 'a[href="#current_user"]' } )[0].click
sleep 0.1 sleep 0.1
instance.find_elements( { css: 'a[href="#logout"]' } )[0].click instance.find_elements( { css: 'a[href="#logout"]' } )[0].click
(1..6).each {|loop| (1..6).each {
sleep 1 sleep 1
login = instance.find_elements( { css: '#login' } )[0] login = instance.find_elements( { css: '#login' } )[0]
if login if login
@ -760,7 +760,7 @@ class TestCase < Test::Unit::TestCase
end end
loops = (timeout).to_i * 2 loops = (timeout).to_i * 2
text = '' text = ''
(1..loops).each { |loop| (1..loops).each {
element = instance.find_elements( { css: params[:css] } )[0] element = instance.find_elements( { css: params[:css] } )[0]
if element #&& element.displayed? if element #&& element.displayed?
begin begin
@ -820,7 +820,7 @@ wait untill text in selector disabppears
end end
loops = (timeout).to_i loops = (timeout).to_i
text = '' text = ''
(1..loops).each { |loop| (1..loops).each {
element = instance.find_elements( { css: params[:css] } )[0] element = instance.find_elements( { css: params[:css] } )[0]
if !element #|| element.displayed? if !element #|| element.displayed?
assert( true, 'not found' ) assert( true, 'not found' )
@ -942,7 +942,7 @@ wait untill text in selector disabppears
end end
instance.find_elements( { css: '.modal button.js-submit' } )[0].click instance.find_elements( { css: '.modal button.js-submit' } )[0].click
(1..12).each {|loop| (1..12).each {
element = instance.find_elements( { css: 'body' } )[0] element = instance.find_elements( { css: 'body' } )[0]
text = element.text text = element.text
if text =~ /#{Regexp.quote(data[:name])}/ if text =~ /#{Regexp.quote(data[:name])}/
@ -1063,7 +1063,7 @@ wait untill text in selector disabppears
#instance.execute_script( '$(".content.active .newTicket form").submit();' ) #instance.execute_script( '$(".content.active .newTicket form").submit();' )
instance.find_elements( { css: '.active .newTicket button.submit' } )[0].click instance.find_elements( { css: '.active .newTicket button.submit' } )[0].click
sleep 1 sleep 1
(1..10).each {|loop| (1..10).each {
if instance.current_url =~ /#{Regexp.quote('#ticket/zoom/')}/ if instance.current_url =~ /#{Regexp.quote('#ticket/zoom/')}/
assert( true, 'ticket created' ) assert( true, 'ticket created' )
sleep 2.5 sleep 2.5
@ -1220,7 +1220,7 @@ wait untill text in selector disabppears
if data[:state] || data[:group] || data[:body] if data[:state] || data[:group] || data[:body]
found = nil found = nil
(1..5).each {|loop| (1..5).each {
if !found if !found
begin begin
text = instance.find_elements( { css: '.content.active .js-reset' } )[0].text text = instance.find_elements( { css: '.content.active .js-reset' } )[0].text
@ -1246,7 +1246,7 @@ wait untill text in selector disabppears
instance.find_elements( { css: '.content.active button.js-submit' } )[0].click instance.find_elements( { css: '.content.active button.js-submit' } )[0].click
(1..10).each {|loop| (1..10).each {
begin begin
text = instance.find_elements( { css: '.content.active .js-reset' } )[0].text text = instance.find_elements( { css: '.content.active .js-reset' } )[0].text
if !text || text.empty? if !text || text.empty?
@ -1408,7 +1408,7 @@ wait untill text in selector disabppears
#puts url.inspect #puts url.inspect
#puts element.inspect #puts element.inspect
} }
overviews.each {|url, value| overviews.each {|url, _value|
count = instance.find_elements( { css: ".content.active .sidebar a[href=\"#{url}\"] .badge" } )[0].text count = instance.find_elements( { css: ".content.active .sidebar a[href=\"#{url}\"] .badge" } )[0].text
overviews[url] = count.to_i overviews[url] = count.to_i
} }
@ -1576,7 +1576,7 @@ wait untill text in selector disabppears
element.clear element.clear
element.send_keys( data[:first_response_time] ) element.send_keys( data[:first_response_time] )
instance.find_elements( { css: '.modal button.js-submit' } )[0].click instance.find_elements( { css: '.modal button.js-submit' } )[0].click
(1..8).each {|loop| (1..8).each {
element = instance.find_elements( { css: 'body' } )[0] element = instance.find_elements( { css: 'body' } )[0]
text = element.text text = element.text
if text =~ /#{Regexp.quote(data[:name])}/ if text =~ /#{Regexp.quote(data[:name])}/
@ -1623,7 +1623,7 @@ wait untill text in selector disabppears
element.clear element.clear
element.send_keys( data[:content] ) element.send_keys( data[:content] )
instance.find_elements( { css: '.modal button.js-submit' } )[0].click instance.find_elements( { css: '.modal button.js-submit' } )[0].click
(1..8).each {|loop| (1..8).each {
element = instance.find_elements( { css: 'body' } )[0] element = instance.find_elements( { css: 'body' } )[0]
text = element.text text = element.text
if text =~ /#{Regexp.quote(data[:name])}/ if text =~ /#{Regexp.quote(data[:name])}/
@ -1667,7 +1667,7 @@ wait untill text in selector disabppears
element.clear element.clear
element.send_keys( data[:body] ) element.send_keys( data[:body] )
instance.find_elements( { css: '.modal button.js-submit' } )[0].click instance.find_elements( { css: '.modal button.js-submit' } )[0].click
(1..12).each {|loop| (1..12).each {
element = instance.find_elements( { css: 'body' } )[0] element = instance.find_elements( { css: 'body' } )[0]
text = element.text text = element.text
if text =~ /#{Regexp.quote(data[:name])}/ if text =~ /#{Regexp.quote(data[:name])}/
@ -1719,7 +1719,7 @@ wait untill text in selector disabppears
dropdown.select_by( :text, data[:signature]) dropdown.select_by( :text, data[:signature])
end end
instance.find_elements( { css: '.modal button.js-submit' } )[0].click instance.find_elements( { css: '.modal button.js-submit' } )[0].click
(1..12).each {|loop| (1..12).each {
element = instance.find_elements( { css: 'body' } )[0] element = instance.find_elements( { css: 'body' } )[0]
text = element.text text = element.text
if text =~ /#{Regexp.quote(data[:name])}/ if text =~ /#{Regexp.quote(data[:name])}/

View file

@ -165,7 +165,7 @@ class TwitterTest < ActiveSupport::TestCase
# fetch check system account # fetch check system account
article = nil article = nil
(1..4).each {|loop| (1..4).each {
next if article next if article
sleep 25 sleep 25

View file

@ -46,7 +46,7 @@ class ActiveSupport::TestCase
return if Delayed::Job.all.empty? return if Delayed::Job.all.empty?
Delayed::Job.where('failed_at != NULL').each {|job| Delayed::Job.where('failed_at != NULL').each {|job|
assert( false, "not processable job #{jobs.inspect}" ) assert( false, "not processable job #{job.inspect}" )
} }
Delayed::Job.all.destroy_all Delayed::Job.all.destroy_all
end end

View file

@ -300,7 +300,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
if message['event'] == 'resetCollection' if message['event'] == 'resetCollection'
#puts "rc: " #puts "rc: "
if message['data'] if message['data']
message['data'].each {|key, value| message['data'].each {|key, _value|
#puts "rc: #{key}" #puts "rc: #{key}"
collections_result[key] = true collections_result[key] = true
} }
@ -308,7 +308,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
end end
} }
#puts "c: #{collections_result.inspect}" #puts "c: #{collections_result.inspect}"
collections_orig.each {|key, value| collections_orig.each {|key, _value|
assert_equal( collections_orig[key], collections_result[key], "collection message for #{key} #{type}-check (client_id #{client_id})" ) assert_equal( collections_orig[key], collections_result[key], "collection message for #{key} #{type}-check (client_id #{client_id})" )
} }
end end