From 79d4284365a56646deb65ee88bd2444be15d03d5 Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Fri, 4 May 2018 14:00:15 +0800 Subject: [PATCH] Fix rubocop violations --- .../concerns/creates_ticket_articles.rb | 4 ++-- app/controllers/form_controller.rb | 4 ++-- app/controllers/import_zendesk_controller.rb | 2 +- app/controllers/settings_controller.rb | 2 +- app/models/channel/driver/pop3.rb | 2 +- app/models/channel/filter/identify_sender.rb | 2 +- app/models/history.rb | 2 -- app/models/link.rb | 2 -- app/models/object_manager/attribute.rb | 2 +- app/models/organization.rb | 2 -- app/models/store.rb | 1 - app/models/tag.rb | 2 -- app/models/ticket.rb | 2 -- app/models/ticket/article.rb | 2 -- app/models/ticket/state.rb | 1 - lib/html_sanitizer.rb | 2 +- lib/version.rb | 2 +- test/browser/agent_ticket_tag_test.rb | 6 +++--- test/browser_test_helper.rb | 16 ++++++++-------- 19 files changed, 22 insertions(+), 36 deletions(-) diff --git a/app/controllers/concerns/creates_ticket_articles.rb b/app/controllers/concerns/creates_ticket_articles.rb index 1569a7436..82a2001dc 100644 --- a/app/controllers/concerns/creates_ticket_articles.rb +++ b/app/controllers/concerns/creates_ticket_articles.rb @@ -36,7 +36,7 @@ module CreatesTicketArticles clean_params.delete(:sender) clean_params.delete(:origin_by_id) type = Ticket::Article::Type.lookup(id: clean_params[:type_id]) - if type.name !~ /^(note|web)$/ + unless type.name.match?(/^(note|web)$/) clean_params[:type_id] = Ticket::Article::Type.lookup(name: 'note').id end clean_params.delete(:type) @@ -89,7 +89,7 @@ module CreatesTicketArticles preferences[store_key] = attachment[key] end - if attachment[:data] !~ %r{^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$} + unless attachment[:data].match?(%r{^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$}) raise Exceptions::UnprocessableEntity, "Invalid base64 for attachment with index '#{index}'" end diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index d0a535ddf..832419d2e 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -43,7 +43,7 @@ class FormController < ApplicationController end if params[:email].blank? errors['email'] = 'required' - elsif params[:email] !~ /@/ + elsif !/@/.match?(params[:email]) errors['email'] = 'invalid' elsif params[:email].match?(/(>|<|\||\!|"|ยง|'|\$|%|&|\(|\)|\?|\s|\.\.)/) errors['email'] = 'invalid' @@ -67,7 +67,7 @@ class FormController < ApplicationController Rails.logger.info "Can't verify email #{params[:email]}: #{message}" # ignore 450, graylistings - if message !~ /450/ + unless message.match?(/450/) errors['email'] = message end end diff --git a/app/controllers/import_zendesk_controller.rb b/app/controllers/import_zendesk_controller.rb index 11d24cf2e..c9ed0758d 100644 --- a/app/controllers/import_zendesk_controller.rb +++ b/app/controllers/import_zendesk_controller.rb @@ -39,7 +39,7 @@ class ImportZendeskController < ApplicationController end # since 2016-10-15 a redirect to a marketing page has been implemented - if response.body !~ /#{params[:url]}/ + unless response.body.match?(/#{params[:url]}/) render json: { result: 'invalid', message_human: 'Hostname not found!', diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index 6d332edb0..bb14774ce 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -45,7 +45,7 @@ class SettingsController < ApplicationController end # validate image - if clean_params[:logo] !~ /^data:image/i + unless clean_params[:logo].match?(/^data:image/i) render json: { result: 'invalid', message: 'Invalid payload, need data:image in logo param', diff --git a/app/models/channel/driver/pop3.rb b/app/models/channel/driver/pop3.rb index 549a678d9..64cba4d1d 100644 --- a/app/models/channel/driver/pop3.rb +++ b/app/models/channel/driver/pop3.rb @@ -91,7 +91,7 @@ returns next if !mail # check how many content messages we have, for notice used - if mail !~ /x-zammad-ignore/i + unless mail.match?(/x-zammad-ignore/i) content_messages += 1 break if content_max_check < content_messages end diff --git a/app/models/channel/filter/identify_sender.rb b/app/models/channel/filter/identify_sender.rb index e1c0955f2..d5e722b16 100644 --- a/app/models/channel/filter/identify_sender.rb +++ b/app/models/channel/filter/identify_sender.rb @@ -144,7 +144,7 @@ module Channel::Filter::IdentifySender end def self.user_create(data, role_ids = nil) - if data[:email] !~ /@/ + unless data[:email].match?(/@/) data[:email] += '@local' end user = User.find_by(email: data[:email].downcase) diff --git a/app/models/history.rb b/app/models/history.rb index 15fae7bc8..149668af2 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -4,8 +4,6 @@ class History < ApplicationModel include History::Assets self.table_name = 'histories' - - # rubocop:disable Rails/InverseOf belongs_to :history_type, class_name: 'History::Type' belongs_to :history_object, class_name: 'History::Object' belongs_to :history_attribute, class_name: 'History::Attribute' diff --git a/app/models/link.rb b/app/models/link.rb index 0361ce474..5ac666184 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,8 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ class Link < ApplicationModel - - # rubocop:disable Rails/InverseOf belongs_to :link_type, class_name: 'Link::Type' belongs_to :link_object, class_name: 'Link::Object' # rubocop:enable Rails/InverseOf diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb index bccea00cf..1d7129e44 100644 --- a/app/models/object_manager/attribute.rb +++ b/app/models/object_manager/attribute.rb @@ -756,7 +756,7 @@ to send no browser reload event, pass false if !data_type raise 'Need data_type param' end - if data_type !~ /^(input|user_autocompletion|checkbox|select|tree_select|datetime|date|tag|richtext|textarea|integer|autocompletion_ajax|boolean|user_permission|active)$/ + unless data_type.match?(/^(input|user_autocompletion|checkbox|select|tree_select|datetime|date|tag|richtext|textarea|integer|autocompletion_ajax|boolean|user_permission|active)$/) raise "Invalid data_type param '#{data_type}'" end diff --git a/app/models/organization.rb b/app/models/organization.rb index 3c2f8c45a..d168cb156 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -12,8 +12,6 @@ class Organization < ApplicationModel include Organization::Assets include Organization::Search include Organization::SearchIndex - - # rubocop:disable Rails/InverseOf has_many :members, class_name: 'User' # rubocop:enable Rails/InverseOf diff --git a/app/models/store.rb b/app/models/store.rb index 0a3d78ead..b8c09758e 100644 --- a/app/models/store.rb +++ b/app/models/store.rb @@ -4,7 +4,6 @@ require_dependency 'store/object' require_dependency 'store/file' class Store < ApplicationModel - # rubocop:disable Rails/InverseOf belongs_to :store_object, class_name: 'Store::Object' belongs_to :store_file, class_name: 'Store::File' # rubocop:enable Rails/InverseOf diff --git a/app/models/tag.rb b/app/models/tag.rb index 8410b2aa3..9de2e3b66 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,8 +1,6 @@ # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ class Tag < ApplicationModel - - # rubocop:disable Rails/InverseOf belongs_to :tag_object, class_name: 'Tag::Object' belongs_to :tag_item, class_name: 'Tag::Item' # rubocop:enable Rails/InverseOf diff --git a/app/models/ticket.rb b/app/models/ticket.rb index f71bc5300..decdd40ca 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -57,8 +57,6 @@ class Ticket < ApplicationModel belongs_to :organization has_many :articles, class_name: 'Ticket::Article', after_add: :cache_update, after_remove: :cache_update, dependent: :destroy, inverse_of: :ticket has_many :ticket_time_accounting, class_name: 'Ticket::TimeAccounting', dependent: :destroy, inverse_of: :ticket - - # rubocop:disable Rails/InverseOf belongs_to :state, class_name: 'Ticket::State' belongs_to :priority, class_name: 'Ticket::Priority' belongs_to :owner, class_name: 'User' diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index a6442bc1d..acaed55f0 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -11,8 +11,6 @@ class Ticket::Article < ApplicationModel belongs_to :ticket has_one :ticket_time_accounting, class_name: 'Ticket::TimeAccounting', foreign_key: :ticket_article_id, dependent: :destroy, inverse_of: :ticket_article - - # rubocop:disable Rails/InverseOf belongs_to :type, class_name: 'Ticket::Article::Type' belongs_to :sender, class_name: 'Ticket::Article::Sender' belongs_to :created_by, class_name: 'User' diff --git a/app/models/ticket/state.rb b/app/models/ticket/state.rb index 6b126269b..680710e2d 100644 --- a/app/models/ticket/state.rb +++ b/app/models/ticket/state.rb @@ -3,7 +3,6 @@ class Ticket::State < ApplicationModel include ChecksLatestChangeObserved belongs_to :state_type, class_name: 'Ticket::StateType', inverse_of: :states - # rubocop:disable Rails/InverseOf belongs_to :next_state, class_name: 'Ticket::State' # rubocop:enable Rails/InverseOf diff --git a/lib/html_sanitizer.rb b/lib/html_sanitizer.rb index 3fc361c69..9cc444a3d 100644 --- a/lib/html_sanitizer.rb +++ b/lib/html_sanitizer.rb @@ -134,7 +134,7 @@ satinize html string based on whiltelist value = node[key] node.delete(key) next if value.blank? - if value !~ /%|px|em/i + unless value.match?(/%|px|em/i) value += 'px' end node['style'] += "#{key}:#{value}" diff --git a/lib/version.rb b/lib/version.rb index c1cbbc853..7fd5c736f 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -18,6 +18,6 @@ returns File.read(Rails.root.join('VERSION')).strip rescue => e Rails.logger.error "VERSION file could not be read: #{e}" - return '' + '' end end diff --git a/test/browser/agent_ticket_tag_test.rb b/test/browser/agent_ticket_tag_test.rb index 1d881b5e7..7abcd0c64 100644 --- a/test/browser/agent_ticket_tag_test.rb +++ b/test/browser/agent_ticket_tag_test.rb @@ -37,7 +37,7 @@ class AgentTicketTagTest < TestCase css: '.active .newTicket button.js-submit', ) sleep 5 - if @browser.current_url !~ /#{Regexp.quote('#ticket/zoom/')}/ + unless @browser.current_url.match?(/#{Regexp.quote('#ticket/zoom/')}/) raise 'Unable to create ticket!' end @@ -69,7 +69,7 @@ class AgentTicketTagTest < TestCase click(css: '#global-search') click(css: '.active .newTicket button.js-submit') sleep 5 - if @browser.current_url !~ /#{Regexp.quote('#ticket/zoom/')}/ + unless @browser.current_url.match?(/#{Regexp.quote('#ticket/zoom/')}/) raise 'Unable to create ticket!' end @@ -428,7 +428,7 @@ class AgentTicketTagTest < TestCase css: '.active .newTicket button.js-submit', ) sleep 5 - if @browser.current_url !~ /#{Regexp.quote('#ticket/zoom/')}/ + unless @browser.current_url.match?(/#{Regexp.quote('#ticket/zoom/')}/) raise 'Unable to create ticket!' end diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 44fa08113..ef158a54a 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -104,7 +104,7 @@ class TestCase < Test::Unit::TestCase browser_width = ENV['BROWSER_WIDTH'] || 1024 browser_height = ENV['BROWSER_HEIGHT'] || 800 local_browser.manage.window.resize_to(browser_width, browser_height) - if ENV['REMOTE_URL'] !~ /saucelabs|(grid|ci)\.(zammad\.org|znuny\.com)/i + unless ENV['REMOTE_URL'].match?(/saucelabs|(grid|ci)\.(zammad\.org|znuny\.com)/i) if @browsers.count == 1 local_browser.manage.window.move_to(0, 0) else @@ -362,7 +362,7 @@ class TestCase < Test::Unit::TestCase instance = params[:browser] || @browser sleep 0.7 current_url = instance.current_url - if current_url !~ /#{Regexp.quote(params[:url])}/ + unless current_url.match?(/#{Regexp.quote(params[:url])}/) screenshot(browser: instance, comment: 'location_check_failed') raise "url #{current_url} is not matching #{params[:url]}" end @@ -1352,7 +1352,7 @@ wait untill text in selector disabppears if params[:value] begin text = instance.find_elements(css: params[:css])[0].text - if text !~ /#{params[:value]}/i + unless text.match?(/#{params[:value]}/i) assert(true, "not matching '#{params[:value]}' in text '#{text}'") sleep 1 return true @@ -2427,7 +2427,7 @@ wait untill text in selector disabppears element.click sleep 1 number = instance.find_elements(css: '.content.active .ticketZoom-header .ticket-number')[0].text - if number !~ /#{params[:number]}/ + unless number.match?(/#{params[:number]}/) screenshot(browser: instance, comment: 'ticket_open_by_overview_open_failed_failed') raise "unable to open ticket #{params[:number]}!" end @@ -2473,7 +2473,7 @@ wait untill text in selector disabppears instance.execute_script("$(\".js-global-search-result a:contains('#{params[:number]}') .nav-tab-icon\").first().click()") sleep 1 number = instance.find_elements(css: '.content.active .ticketZoom-header .ticket-number')[0].text - if number !~ /#{params[:number]}/ + unless number.match?(/#{params[:number]}/) screenshot(browser: instance, comment: 'ticket_open_by_search_failed') raise "unable to search/find ticket #{params[:number]}!" end @@ -2509,7 +2509,7 @@ wait untill text in selector disabppears instance.execute_script("$(\".js-global-search-result a:contains('#{params[:title]}') .nav-tab-icon\").click()") sleep 1 title = instance.find_elements(css: '.content.active .ticketZoom-header .js-objectTitle')[0].text - if title !~ /#{params[:title]}/ + unless title.match?(/#{params[:title]}/) screenshot(browser: instance, comment: 'ticket_open_by_title_failed') raise "unable to search/find ticket #{params[:title]}!" end @@ -2597,7 +2597,7 @@ wait untill text in selector disabppears instance.execute_script("$(\".js-global-search-result a:contains('#{params[:value]}') .nav-tab-icon\").click()") sleep 1 name = instance.find_elements(css: '.content.active h1')[0].text - if name !~ /#{params[:value]}/ + unless name.match?(/#{params[:value]}/) screenshot(browser: instance, comment: 'organization_open_by_search_failed') raise "unable to search/find org #{params[:value]}!" end @@ -2632,7 +2632,7 @@ wait untill text in selector disabppears instance.execute_script("$(\".js-global-search-result a:contains('#{params[:value]}') .nav-tab-icon\").click()") sleep 1 name = instance.find_elements(css: '.content.active h1')[0].text - if name !~ /#{params[:value]}/ + unless name.match?(/#{params[:value]}/) screenshot(browser: instance, comment: 'user_open_by_search_failed') raise "unable to search/find user #{params[:value]}!" end