From 6909430eac4565bdc062968bb1c5c0dce57f85c3 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 27 Apr 2015 21:56:07 +0200 Subject: [PATCH] Some new rubocop checks. --- test/browser/aaa_getting_started_test.rb | 16 +++---- .../agent_ticket_actions_level1_test.rb | 4 +- .../agent_ticket_actions_level2_test.rb | 1 - .../agent_ticket_actions_level4_test.rb | 2 +- .../agent_ticket_overview_level0_test.rb | 2 +- .../agent_ticket_overview_level1_test.rb | 4 +- test/browser/chat_test.rb | 1 + test/browser/prefereces_test.rb | 2 +- test/browser_test_helper.rb | 34 +++++++------- test/integration/elasticsearch_test.rb | 9 ++-- test/integration/otrs_import_test.rb | 28 +++++------ test/integration/twitter_test.rb | 13 ++--- test/ui_test.rb | 47 ------------------- 13 files changed, 59 insertions(+), 104 deletions(-) delete mode 100644 test/ui_test.rb diff --git a/test/browser/aaa_getting_started_test.rb b/test/browser/aaa_getting_started_test.rb index 43a4f3403..9f444a64f 100644 --- a/test/browser/aaa_getting_started_test.rb +++ b/test/browser/aaa_getting_started_test.rb @@ -167,9 +167,9 @@ class AaaGettingStartedTest < TestCase #return # TODO: temp disable accounts = [] (1..10).each {|count| - next if !ENV["MAILBOX_AUTO#{count.to_s}"] - mailbox_user = ENV["MAILBOX_AUTO#{count.to_s}"].split(':')[0] - mailbox_password = ENV["MAILBOX_AUTO#{count.to_s}"].split(':')[1] + next if !ENV["MAILBOX_AUTO#{count}"] + mailbox_user = ENV["MAILBOX_AUTO#{count}"].split(':')[0] + mailbox_password = ENV["MAILBOX_AUTO#{count}"].split(':')[1] account = { realname: 'auto account', email: mailbox_user, @@ -230,11 +230,11 @@ class AaaGettingStartedTest < TestCase #return # TODO: temp disable accounts = [] (1..10).each {|count| - next if !ENV["MAILBOX_MANUAL#{count.to_s}"] - mailbox_user = ENV["MAILBOX_MANUAL#{count.to_s}"].split(':')[0] - mailbox_password = ENV["MAILBOX_MANUAL#{count.to_s}"].split(':')[1] - mailbox_inbound = ENV["MAILBOX_MANUAL#{count.to_s}"].split(':')[2] - mailbox_outbound = ENV["MAILBOX_MANUAL#{count.to_s}"].split(':')[3] + next if !ENV["MAILBOX_MANUAL#{count}"] + mailbox_user = ENV["MAILBOX_MANUAL#{count}"].split(':')[0] + mailbox_password = ENV["MAILBOX_MANUAL#{count}"].split(':')[1] + mailbox_inbound = ENV["MAILBOX_MANUAL#{count}"].split(':')[2] + mailbox_outbound = ENV["MAILBOX_MANUAL#{count}"].split(':')[3] account = { realname: 'manual account', email: mailbox_user, diff --git a/test/browser/agent_ticket_actions_level1_test.rb b/test/browser/agent_ticket_actions_level1_test.rb index 4c6d9d4e2..d362bd576 100644 --- a/test/browser/agent_ticket_actions_level1_test.rb +++ b/test/browser/agent_ticket_actions_level1_test.rb @@ -34,7 +34,7 @@ class AgentTicketActionLevel1Test < TestCase tasks_close_all() # create second ticket to merge - ticket2 = ticket_create( + ticket_create( data: { customer: 'nico', group: 'Users', @@ -103,7 +103,7 @@ class AgentTicketActionLevel1Test < TestCase }, ) - ticket4 = ticket_create( + ticket_create( data: { customer: 'nico', group: 'Users', diff --git a/test/browser/agent_ticket_actions_level2_test.rb b/test/browser/agent_ticket_actions_level2_test.rb index 6057bed70..5ec2d98c5 100644 --- a/test/browser/agent_ticket_actions_level2_test.rb +++ b/test/browser/agent_ticket_actions_level2_test.rb @@ -5,7 +5,6 @@ class AgentTicketActionsLevel2Test < TestCase def test_work_with_two_browser_on_same_ticket # work on one ticket with two browsers - message = 'message 1äöüß ' + rand(99_999_999_999_999_999).to_s browser1 = browser_instance login( diff --git a/test/browser/agent_ticket_actions_level4_test.rb b/test/browser/agent_ticket_actions_level4_test.rb index 6390dc632..ce2d0f6ae 100644 --- a/test/browser/agent_ticket_actions_level4_test.rb +++ b/test/browser/agent_ticket_actions_level4_test.rb @@ -66,7 +66,7 @@ class AgentTicketActionLevel4Test < TestCase ) ticket_id = nil - if @browser.current_url =~ /ticket\/zoom\/(.+?)$/i + if @browser.current_url =~ %r{ticket/zoom/(.+?)$}i ticket_id = $1 end diff --git a/test/browser/agent_ticket_overview_level0_test.rb b/test/browser/agent_ticket_overview_level0_test.rb index bf7f342c6..f8b933ee6 100644 --- a/test/browser/agent_ticket_overview_level0_test.rb +++ b/test/browser/agent_ticket_overview_level0_test.rb @@ -2,7 +2,7 @@ require 'browser_test_helper' class AgentTicketOverviewLevel0Test < TestCase - def test_I + def test_i @browser = browser_instance login( username: 'master@example.com', diff --git a/test/browser/agent_ticket_overview_level1_test.rb b/test/browser/agent_ticket_overview_level1_test.rb index 70faf514e..1bdbe9a17 100644 --- a/test/browser/agent_ticket_overview_level1_test.rb +++ b/test/browser/agent_ticket_overview_level1_test.rb @@ -2,7 +2,7 @@ require 'browser_test_helper' class AgentTicketOverviewLevel1Test < TestCase - def test_I + def test_i name = 'name-' + rand(999_999).to_s browser1 = browser_instance @@ -24,7 +24,7 @@ class AgentTicketOverviewLevel1Test < TestCase tasks_close_all( browser: browser2 ) # create new overview - overview = overview_create( + overview_create( browser: browser1, data: { :name => name, diff --git a/test/browser/chat_test.rb b/test/browser/chat_test.rb index 24cbaf005..1d94eb657 100644 --- a/test/browser/chat_test.rb +++ b/test/browser/chat_test.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +# rubocop:disable all require 'browser_test_helper' class ChatTest < TestCase diff --git a/test/browser/prefereces_test.rb b/test/browser/prefereces_test.rb index 3f3ada209..fb4779f73 100644 --- a/test/browser/prefereces_test.rb +++ b/test/browser/prefereces_test.rb @@ -23,7 +23,7 @@ class PreferencesTest < TestCase ) # start ticket zoom - ticket = ticket_create( + ticket_create( data: { customer: 'nicole', group: 'Users', diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index b8d29ccf2..4ccdd6135 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -1,4 +1,5 @@ ENV['RAILS_ENV'] = 'test' +# rubocop:disable Next, CyclomaticComplexity, PerceivedComplexity require File.expand_path('../../config/environment', __FILE__) require 'selenium-webdriver' @@ -12,7 +13,7 @@ class TestCase < Test::Unit::TestCase if browser =~ /(internet_explorer|ie)/i return false end - return true + true end def browser_url @@ -44,7 +45,7 @@ class TestCase < Test::Unit::TestCase ) browser_instance_preferences(local_browser) @browsers[local_browser.hash] = local_browser - return local_browser + local_browser end def browser_instance_close(local_browser) @@ -548,19 +549,19 @@ class TestCase < Test::Unit::TestCase #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.has_key?( :value ) && cookie[:value].to_s =~ /#{params[:value]}/i - assert( true, "matching value '#{params[:value]}' in cookie '#{cookie.to_s}'" ) + if params.key?( :value ) && cookie[:value].to_s =~ /#{params[:value]}/i + assert( true, "matching value '#{params[:value]}' in cookie '#{cookie}'" ) else - raise "not matching value '#{params[:value]}' in cookie '#{cookie.to_s}'" + raise "not matching value '#{params[:value]}' in cookie '#{cookie}'" end - if params.has_key?( :expires ) && cookie[:expires].to_s =~ /#{params[:expires]}/i - assert( true, "matching expires '#{params[:expires].inspect}' in cookie '#{cookie.to_s}'" ) + if params.key?( :expires ) && cookie[:expires].to_s =~ /#{params[:expires]}/i + assert( true, "matching expires '#{params[:expires].inspect}' in cookie '#{cookie}'" ) else - raise "not matching expires '#{params[:expires]}' in cookie '#{cookie.to_s}'" + raise "not matching expires '#{params[:expires]}' in cookie '#{cookie}'" end if params[:should_not_exist] - raise "cookie with name '#{params[:name]}' should not exist, but exists '#{cookies.to_s}'" + raise "cookie with name '#{params[:name]}' should not exist, but exists '#{cookies}'" end return end @@ -569,7 +570,7 @@ class TestCase < Test::Unit::TestCase assert( true, "cookie with name '#{params[:name]}' is not existing" ) return end - raise "not matching name '#{params[:name]}' in cookie '#{cookies.to_s}'" + raise "not matching name '#{params[:name]}' in cookie '#{cookies}'" end =begin @@ -627,7 +628,7 @@ class TestCase < Test::Unit::TestCase end puts "tv #{params.inspect}" # verify modified - if data.has_key?(:modified) + if data.key?(:modified) exists = instance.find_elements( { css: '.tasks .active .icon' } )[0] is_modified = instance.find_elements( { css: '.tasks .active .icon.modified' } )[0] puts "m #{data[:modified].inspect}" @@ -1293,7 +1294,7 @@ wait untill text in selector disabppears sleep 1 instance.find_elements( { css: ".content.active .sidebar a[href=\"#{params[:link]}\"]" } )[0].click sleep 1 - element = instance.find_elements( { partial_link_text: params[:number] } )[0].click + instance.find_elements( { partial_link_text: params[:number] } )[0].click sleep 1 number = instance.find_elements( { css: '.active .page-header .ticket-number' } )[0].text if number !~ /#{params[:number]}/ @@ -1341,7 +1342,7 @@ wait untill text in selector disabppears sleep 1 # open ticket - element = instance.find_element( { partial_link_text: params[:number] } ).click + instance.find_element( { partial_link_text: params[:number] } ).click number = instance.find_elements( { css: '.active .page-header .ticket-number' } )[0].text if number !~ /#{params[:number]}/ raise "unable to search/find ticket #{params[:number]}!" @@ -1416,11 +1417,10 @@ wait untill text in selector disabppears element.clear element.send_keys( params[:value] ) sleep 2 - element = instance.find_element( { partial_link_text: params[:value] } ).click + instance.find_element( { partial_link_text: params[:value] } ).click name = instance.find_elements( { css: '.active h1' } )[0].text if name !~ /#{params[:value]}/ raise "unable to search/find org #{params[:value]}!" - return end assert( true, "org #{params[:value]} found" ) sleep 2 @@ -1446,7 +1446,7 @@ wait untill text in selector disabppears element.clear element.send_keys( params[:value] ) sleep 3 - element = instance.find_element( { partial_link_text: params[:value] } ).click + instance.find_element( { partial_link_text: params[:value] } ).click name = instance.find_elements( { css: '.active h1' } )[0].text if name !~ /#{params[:value]}/ raise "unable to search/find user #{params[:value]}!" @@ -1726,6 +1726,6 @@ wait untill text in selector disabppears def log(method, params) return if !@@debug - puts "#{Time.now.to_s}/#{method}: #{params.inspect}" + puts "#{Time.zone.now}/#{method}: #{params.inspect}" end end diff --git a/test/integration/elasticsearch_test.rb b/test/integration/elasticsearch_test.rb index dfc321b8d..374309685 100644 --- a/test/integration/elasticsearch_test.rb +++ b/test/integration/elasticsearch_test.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +# rubocop:disable UselessAssignment require 'integration_test_helper' class ElasticsearchTest < ActiveSupport::TestCase @@ -121,7 +122,7 @@ class ElasticsearchTest < ActiveSupport::TestCase Store.add( object: 'Ticket::Article', o_id: article1.id, - data: File.open("#{Rails.root.to_s}/test/fixtures/es-normal.txt", 'rb') { |file| file.read }, + data: File.open("#{Rails.root}/test/fixtures/es-normal.txt", 'rb') { |file| file.read }, filename: 'es-normal.txt', preferences: {}, created_by_id: 1, @@ -132,7 +133,7 @@ class ElasticsearchTest < ActiveSupport::TestCase Store.add( object: 'Ticket::Article', o_id: article1.id, - data: File.open("#{Rails.root.to_s}/test/fixtures/es-pdf1.pdf", 'rb') { |file| file.read }, + data: File.open("#{Rails.root}/test/fixtures/es-pdf1.pdf", 'rb') { |file| file.read }, filename: 'es-pdf1.pdf', preferences: {}, created_by_id: 1, @@ -143,7 +144,7 @@ class ElasticsearchTest < ActiveSupport::TestCase Store.add( object: 'Ticket::Article', o_id: article1.id, - data: File.open("#{Rails.root.to_s}/test/fixtures/es-box1.box", 'rb') { |file| file.read }, + data: File.open("#{Rails.root}/test/fixtures/es-box1.box", 'rb') { |file| file.read }, filename: 'mail1.box', preferences: {}, created_by_id: 1, @@ -154,7 +155,7 @@ class ElasticsearchTest < ActiveSupport::TestCase Store.add( object: 'Ticket::Article', o_id: article1.id, - data: File.open("#{Rails.root.to_s}/test/fixtures/es-too-big.txt", 'rb') { |file| file.read }, + data: File.open("#{Rails.root}/test/fixtures/es-too-big.txt", 'rb') { |file| file.read }, filename: 'es-too-big.txt', preferences: {}, created_by_id: 1, diff --git a/test/integration/otrs_import_test.rb b/test/integration/otrs_import_test.rb index 3c738030a..9e5e380d8 100644 --- a/test/integration/otrs_import_test.rb +++ b/test/integration/otrs_import_test.rb @@ -20,11 +20,11 @@ class OtrsImportTest < ActiveSupport::TestCase http = nil system_id = nil fqdn = nil - if ENV['IMPORT_OTRS_ENDPOINT'] =~ /^(http|https):\/\/((.+?)\..+?)\// - http = $1 - fqdn = $2 - system_id = $3 - system_id.gsub!(/[A-z]/, '') # strip chars + if ENV['IMPORT_OTRS_ENDPOINT'] =~ %r{^(http|https)://((.+?)\..+?)/} + http = $1 + fqdn = $2 + system_id = $3 + system_id.gsub!(/[A-z]/, '') # strip chars end assert_equal( system_id, Setting.get('system_id'), 'system_id' ) assert_equal( fqdn, Setting.get('fqdn'), 'fqdn' ) @@ -171,11 +171,11 @@ class OtrsImportTest < ActiveSupport::TestCase assert_equal( 'agent-2', ticket.owner.login ) assert_equal( 'partner', ticket.customer.login ) assert_equal( 'Partner der betreut', ticket.organization.name ) - assert_equal( Time.parse('2014-11-20 22:33:41 +0000').gmtime.to_s, ticket.created_at.to_s ) + assert_equal( Time.zone.parse('2014-11-20 22:33:41 +0000').gmtime.to_s, ticket.created_at.to_s ) assert_equal( nil, ticket.close_time ) # check history - # create entry + # - create entry # ticket is created with state closed ticket = Ticket.find(729) @@ -186,11 +186,11 @@ class OtrsImportTest < ActiveSupport::TestCase assert_equal( 'agent-2', ticket.owner.login ) assert_equal( 'jn2', ticket.customer.login ) assert_equal( 'Znuny GmbH', ticket.organization.name ) - assert_equal( Time.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.created_at.to_s ) - assert_equal( Time.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.close_time.to_s ) + assert_equal( Time.zone.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.created_at.to_s ) + assert_equal( Time.zone.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.close_time.to_s ) # check history - # create entry + # - create entry # ticket is created open and now closed ticket = Ticket.find(730) @@ -201,11 +201,11 @@ class OtrsImportTest < ActiveSupport::TestCase assert_equal( 'agent-2', ticket.owner.login ) assert_equal( 'betreuterkunde2', ticket.customer.login ) assert_equal( 'Noch ein betreuter Kunde', ticket.organization.name ) - assert_equal( Time.parse('2014-11-21 00:17:40 +0000').gmtime.to_s, ticket.created_at.to_s ) - assert_equal( Time.parse('2014-11-21 00:21:08 +0000').gmtime.to_s, ticket.close_time.to_s ) + assert_equal( Time.zone.parse('2014-11-21 00:17:40 +0000').gmtime.to_s, ticket.created_at.to_s ) + assert_equal( Time.zone.parse('2014-11-21 00:21:08 +0000').gmtime.to_s, ticket.close_time.to_s ) # check history - # create entry - # state change entry + # - create entry + # - state change entry end end diff --git a/test/integration/twitter_test.rb b/test/integration/twitter_test.rb index bda96f896..54013abf4 100644 --- a/test/integration/twitter_test.rb +++ b/test/integration/twitter_test.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +# rubocop:disable UselessAssignment require 'integration_test_helper' class TwitterTest < ActiveSupport::TestCase @@ -85,9 +86,9 @@ class TwitterTest < ActiveSupport::TestCase type_id: Ticket::Article::Type.where( name: 'twitter status' ).first.id, sender_id: Ticket::Article::Sender.where( name: 'Agent' ).first.id, body: text, -# :from => sender.name, -# :to => to, -# :message_id => tweet.id, + #:from => sender.name, + #:to => to, + #:message_id => tweet.id, internal: false, updated_by_id: 1, created_by_id: 1, @@ -179,13 +180,13 @@ class TwitterTest < ActiveSupport::TestCase puts '----------------------------------------' assert( article, 'inbound article created' ) -# ticket = Ticket.find( article.ticket.id ) + #ticket = Ticket.find( article.ticket.id ) ticket = article.ticket assert( ticket, 'ticket of inbound article exists' ) assert( ticket.articles, 'ticket.articles exists' ) article_count = ticket.articles.count assert( article_count ) -# assert_equal( ticket.state.name, 'new' ) + #assert_equal( ticket.state.name, 'new' ) # reply via ticket outbound_article = Ticket::Article.create( @@ -193,7 +194,7 @@ class TwitterTest < ActiveSupport::TestCase type_id: Ticket::Article::Type.where( name: 'twitter direct-message' ).first.id, sender_id: Ticket::Article::Sender.where( name: 'Agent' ).first.id, body: text, -# :from => sender.name, + #:from => sender.name, to: 'me_bauer', internal: false, updated_by_id: 1, diff --git a/test/ui_test.rb b/test/ui_test.rb deleted file mode 100644 index 3c0ada201..000000000 --- a/test/ui_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -ENV['RAILS_ENV'] = 'test' -require File.expand_path('../../config/environment', __FILE__) -require 'rails/test_help' -require 'test/unit' -require 'rubygems' -require 'selenium-webdriver' - -class ExampleTest < Test::Unit::TestCase - attr_reader :browser - - def setup - @browser = Selenium::WebDriver.for :chrome - end - - def teardown - browser.quit - end - - def test_first_page - browser.get 'http://portal.znuny.com/' - assert_equal browser.current_url, 'https://portal.znuny.com/#login' - end - - def test_login_failed - browser.get 'http://portal.znuny.com/' - element_username = browser.find_element name: 'username' - element_username.send_keys 'roy@kaldung.de' - element_password = browser.find_element name: 'password' - element_password.send_keys '123456' - element_password.submit - wait = Selenium::WebDriver::Wait.new(timeout: 10) # seconds - wait.until { browser.find_element(id: 'app') } - assert_equal browser.current_url, 'https://portal.znuny.com/#login' - end - - def test_login_passed - browser.get 'http://portal.znuny.com/' - element_username = browser.find_element name: 'username' - element_username.send_keys 'roy@kaldung.com' - element_password = browser.find_element name: 'password' - element_password.send_keys '090504' - element_password.submit - wait = Selenium::WebDriver::Wait.new(timeout: 10) # seconds - wait.until { browser.find_element(id: 'app') } - assert_equal browser.current_url, 'https://portal.znuny.com/#ticket_view/my_tickets' - end -end