From e63510c4d0a13fde3f12198518a951ec4dc75412 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Mon, 19 Jul 2021 12:24:09 +0000 Subject: [PATCH] Maintenance: Apply Rubocop also to files in .gitlab, .github, .rubocop and to RSpec support files. --- .gitlab/configure_environment.rb | 10 +++++----- .rubocop/cop/zammad/exists_condition.rb | 4 +++- .rubocop/cop/zammad/exists_date_time_precision.rb | 2 ++ .rubocop/cop/zammad/exists_reset_column_information.rb | 2 ++ .rubocop/cop/zammad/have_no_over_not_to.rb | 9 +++++---- .rubocop/cop/zammad/no_to_sym_on_string.rb | 2 ++ .rubocop/cop/zammad/prefer_negated_if_over_unless.rb | 2 ++ .rubocop/default.yml | 8 ++++++++ spec/factories/ticket/article.rb | 1 + .../trigger_webhook_job/record_payload/base_example.rb | 1 + spec/models/contexts/factory_context.rb | 4 ++-- spec/rails_helper.rb | 2 +- spec/support/active_job.rb | 2 +- spec/support/avatar_check.rb | 2 +- spec/support/cache.rb | 2 +- spec/support/db_migration.rb | 2 +- spec/support/faker.rb | 2 +- spec/support/knowledge_base_contexts.rb | 6 ++++-- spec/support/log_spec_name.rb | 2 +- spec/support/searchindex_backend.rb | 2 +- spec/support/sends_notification_emails.rb | 2 +- spec/support/system_init_done.rb | 2 +- spec/support/time_helper.rb | 2 +- spec/support/user_info.rb | 4 ++-- 24 files changed, 50 insertions(+), 27 deletions(-) diff --git a/.gitlab/configure_environment.rb b/.gitlab/configure_environment.rb index e61e17c19..dc20777f9 100755 --- a/.gitlab/configure_environment.rb +++ b/.gitlab/configure_environment.rb @@ -15,11 +15,11 @@ require 'resolv' class ConfigureEnvironment - @env_file_content = <<~EOF - #!/bin/bash - FRESHENVFILE=fresh.env && test -f $FRESHENVFILE && source $FRESHENVFILE - true - EOF + @env_file_content = <<~ENV_FILE_CONTENT + #!/bin/bash + FRESHENVFILE=fresh.env && test -f $FRESHENVFILE && source $FRESHENVFILE + true + ENV_FILE_CONTENT def self.configure_redis if ENV['REDIS_URL'].nil? || ENV['REDIS_URL'].empty? # rubocop:disable Rails/Blank diff --git a/.rubocop/cop/zammad/exists_condition.rb b/.rubocop/cop/zammad/exists_condition.rb index 6670a63f7..14cd0e1fd 100644 --- a/.rubocop/cop/zammad/exists_condition.rb +++ b/.rubocop/cop/zammad/exists_condition.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + module RuboCop module Cop module Zammad @@ -84,7 +86,7 @@ module RuboCop def handle_node(node) if node.send_type? - check_offense(*find_by_condition?(node)) # rubocop:disable Rails/DynamicFindBy + check_offense(*find_by_condition?(node)) elsif %i[and or begin].include?(node.type) check_node(node) end diff --git a/.rubocop/cop/zammad/exists_date_time_precision.rb b/.rubocop/cop/zammad/exists_date_time_precision.rb index 21b7e59a7..b38a43484 100644 --- a/.rubocop/cop/zammad/exists_date_time_precision.rb +++ b/.rubocop/cop/zammad/exists_date_time_precision.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + module RuboCop module Cop module Zammad diff --git a/.rubocop/cop/zammad/exists_reset_column_information.rb b/.rubocop/cop/zammad/exists_reset_column_information.rb index 250fa4bad..c7d0dd532 100644 --- a/.rubocop/cop/zammad/exists_reset_column_information.rb +++ b/.rubocop/cop/zammad/exists_reset_column_information.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + module RuboCop module Cop module Zammad diff --git a/.rubocop/cop/zammad/have_no_over_not_to.rb b/.rubocop/cop/zammad/have_no_over_not_to.rb index c409867ff..ee7a3fa60 100644 --- a/.rubocop/cop/zammad/have_no_over_not_to.rb +++ b/.rubocop/cop/zammad/have_no_over_not_to.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + require 'capybara/rspec/matchers' module RuboCop @@ -23,8 +25,8 @@ module RuboCop have_not_no?(matcher_name) && capybara_matcher?(matcher_name) end - def have_not_no?(matcher_name) - matcher_name.match?(/^have_(?!no)/) + def have_not_no?(matcher_name) # rubocop:disable Naming/PredicateName + matcher_name.match?(%r{^have_(?!no)}) end def capybara_matcher?(matcher_name) @@ -53,10 +55,9 @@ module RuboCop end def message(node) - message = format(MSG, replacement: alternative_matcher(node), original: original_matcher(node)) + format(MSG, replacement: alternative_matcher(node), original: original_matcher(node)) end end end end end - diff --git a/.rubocop/cop/zammad/no_to_sym_on_string.rb b/.rubocop/cop/zammad/no_to_sym_on_string.rb index fd122a9cd..4a1561cec 100644 --- a/.rubocop/cop/zammad/no_to_sym_on_string.rb +++ b/.rubocop/cop/zammad/no_to_sym_on_string.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + module RuboCop module Cop module Zammad diff --git a/.rubocop/cop/zammad/prefer_negated_if_over_unless.rb b/.rubocop/cop/zammad/prefer_negated_if_over_unless.rb index 2478085d7..eb506dfe7 100644 --- a/.rubocop/cop/zammad/prefer_negated_if_over_unless.rb +++ b/.rubocop/cop/zammad/prefer_negated_if_over_unless.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + module RuboCop module Cop module Zammad diff --git a/.rubocop/default.yml b/.rubocop/default.yml index 6f4eb5a73..62e7ea2ac 100644 --- a/.rubocop/default.yml +++ b/.rubocop/default.yml @@ -12,9 +12,17 @@ inherit_from: - todo.yml - todo.rspec.yml +inherit_mode: + merge: + - Include + AllCops: NewCops: enable DisplayCopNames: true + Include: + - '.gitlab/**/*.rb' + - '.github/**/*.rb' + - '.rubocop/**/*.rb' Exclude: - 'bin/*' - 'db/schema.rb' diff --git a/spec/factories/ticket/article.rb b/spec/factories/ticket/article.rb index 8be69d0e0..c7e84b90c 100644 --- a/spec/factories/ticket/article.rb +++ b/spec/factories/ticket/article.rb @@ -8,6 +8,7 @@ FactoryBot.define do from { 'factory-customer-1@example.com' } to { 'factory-customer-1@example.com' } subject { 'factory article' } + message_id { 'factory@id_com_1' } body { 'some message 123' } internal { false } diff --git a/spec/jobs/trigger_webhook_job/record_payload/base_example.rb b/spec/jobs/trigger_webhook_job/record_payload/base_example.rb index d279f8b28..45fab6959 100644 --- a/spec/jobs/trigger_webhook_job/record_payload/base_example.rb +++ b/spec/jobs/trigger_webhook_job/record_payload/base_example.rb @@ -13,6 +13,7 @@ RSpec.shared_examples 'TriggerWebhookJob::RecordPayload backend' do |factory| describe '#generate' do subject(:generate) { described_class.new(record).generate } + let(:resolved_associations) { described_class.const_get(:ASSOCIATIONS).map(&:to_s) } let(:record) { build(factory) } diff --git a/spec/models/contexts/factory_context.rb b/spec/models/contexts/factory_context.rb index c036865d5..b1d7e0714 100644 --- a/spec/models/contexts/factory_context.rb +++ b/spec/models/contexts/factory_context.rb @@ -1,7 +1,7 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -RSpec.shared_context 'factory' do +RSpec.shared_context 'factory' do # rubocop:disable RSpec/ContextWording it 'saves successfully' do - expect(subject).to be_persisted + expect(subject).to be_persisted # rubocop:disable RSpec/NamedSubject end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 91ef32706..1d48f429b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -37,7 +37,7 @@ RSpec.configure do |config| # make usage of time travel helpers possible config.include ActiveSupport::Testing::TimeHelpers - config.after(:each) do + config.after do travel_back end diff --git a/spec/support/active_job.rb b/spec/support/active_job.rb index 4fda9be98..eaae485da 100644 --- a/spec/support/active_job.rb +++ b/spec/support/active_job.rb @@ -42,7 +42,7 @@ RSpec.configure do |config| # Workaround needed for behavior change introduced in Rails >= 5.2 # see: https://github.com/rails/rails/issues/37270 - config.before(:each) do + config.before do (ActiveJob::Base.descendants << ActiveJob::Base).each(&:disable_test_adapter) end end diff --git a/spec/support/avatar_check.rb b/spec/support/avatar_check.rb index 286fa34e2..4a2e72365 100644 --- a/spec/support/avatar_check.rb +++ b/spec/support/avatar_check.rb @@ -14,7 +14,7 @@ module ZammadSpecSupportAvatarCheck # @example # it 'does stuff with avatar check', perform_avatar_for_email_check: true do # - before(:each) do |example| + before do |example| if !example.metadata[:perform_avatar_for_email_check] allow(Avatar).to receive(:auto_detection).and_return(false) end diff --git a/spec/support/cache.rb b/spec/support/cache.rb index 0d5a6e52a..8b9ee8a3f 100644 --- a/spec/support/cache.rb +++ b/spec/support/cache.rb @@ -3,7 +3,7 @@ RSpec.configure do |config| # Cache setup must be the first before hook # Otherwise authenticated_as hook fails with random errors - config.prepend_before(:each) do + config.prepend_before do # clear the cache otherwise it won't # be able to recognize the rollbacks # done by RSpec diff --git a/spec/support/db_migration.rb b/spec/support/db_migration.rb index 530129e74..be6b0eeb9 100644 --- a/spec/support/db_migration.rb +++ b/spec/support/db_migration.rb @@ -157,7 +157,7 @@ module DbMigrationHelper # @example # it 'does stuff in an unitialized system', system_init_done: false do # - before(:each) do |example| + before do |example| initialized = example.metadata.fetch(:system_init_done, true) system_init_done(initialized) end diff --git a/spec/support/faker.rb b/spec/support/faker.rb index 462df8dd2..f607753bd 100644 --- a/spec/support/faker.rb +++ b/spec/support/faker.rb @@ -1,7 +1,7 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ RSpec.configure do |config| - config.after(:each) do + config.after do Faker::UniqueGenerator.clear end end diff --git a/spec/support/knowledge_base_contexts.rb b/spec/support/knowledge_base_contexts.rb index 4ac6bac35..d1db022be 100644 --- a/spec/support/knowledge_base_contexts.rb +++ b/spec/support/knowledge_base_contexts.rb @@ -1,6 +1,6 @@ # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ -RSpec.shared_context 'basic Knowledge Base', current_user_id: 1 do +RSpec.shared_context 'basic Knowledge Base', current_user_id: 1 do # rubocop:disable RSpec/ContextWording let :knowledge_base do create(:knowledge_base) end @@ -38,10 +38,12 @@ RSpec.shared_context 'basic Knowledge Base', current_user_id: 1 do end end -RSpec.shared_context 'Knowledge Base menu items', current_user_id: 1 do +RSpec.shared_context 'Knowledge Base menu items', current_user_id: 1 do # rubocop:disable RSpec/ContextWording + # rubocop:disable RSpec/LetSetup let!(:menu_item_1) { create(:knowledge_base_menu_item, :for_header, kb_locale: primary_locale) } let!(:menu_item_2) { create(:knowledge_base_menu_item, :for_header, kb_locale: primary_locale) } let!(:menu_item_3) { create(:knowledge_base_menu_item, :for_footer, kb_locale: primary_locale) } let!(:menu_item_4) { create(:knowledge_base_menu_item, :for_footer, kb_locale: alternative_locale) } let!(:menu_item_5) { create(:knowledge_base_menu_item, :for_footer, kb_locale: alternative_locale) } + # rubocop:enable RSpec/LetSetup end diff --git a/spec/support/log_spec_name.rb b/spec/support/log_spec_name.rb index 0045693ba..0c7252801 100644 --- a/spec/support/log_spec_name.rb +++ b/spec/support/log_spec_name.rb @@ -2,7 +2,7 @@ RSpec.configure do |config| - config.prepend_before(:example) do |example| + config.prepend_before do |example| Rails.logger.info "=== running RSpec example '#{example.metadata[:full_description]}'" end end diff --git a/spec/support/searchindex_backend.rb b/spec/support/searchindex_backend.rb index fe066b68b..56bbc24f2 100644 --- a/spec/support/searchindex_backend.rb +++ b/spec/support/searchindex_backend.rb @@ -10,7 +10,7 @@ module SearchindexBackendHelper # Execute in RSpec class context base.class_exec do - after(:each) do + after do next if ENV['ES_URL'].blank? Rake::Task['searchindex:drop'].execute diff --git a/spec/support/sends_notification_emails.rb b/spec/support/sends_notification_emails.rb index 33db27f36..4497deb74 100644 --- a/spec/support/sends_notification_emails.rb +++ b/spec/support/sends_notification_emails.rb @@ -39,7 +39,7 @@ module SendsNotificationEmailsHelper # @return [nil] def not_sent(args) check_in_progress! - expect(NotificationFactory::Mailer).to_not have_received(:notification).with( + expect(NotificationFactory::Mailer).not_to have_received(:notification).with( hash_including(args) ) end diff --git a/spec/support/system_init_done.rb b/spec/support/system_init_done.rb index a7310b336..c0240b013 100644 --- a/spec/support/system_init_done.rb +++ b/spec/support/system_init_done.rb @@ -8,7 +8,7 @@ module SystemInitDoneHelper # just mock the Setting check for `system_init_done` # and return the given parameter value - expect(Setting).to receive(:exists?).with(name: 'system_init_done').and_return(state) + allow(Setting).to receive(:exists?).with(name: 'system_init_done').and_return(state) end end diff --git a/spec/support/time_helper.rb b/spec/support/time_helper.rb index ca5e61323..93a9d4945 100644 --- a/spec/support/time_helper.rb +++ b/spec/support/time_helper.rb @@ -5,7 +5,7 @@ RSpec.configure do |config| config.include ActiveSupport::Testing::TimeHelpers # avoid stuck time issues - config.after(:each) do + config.after do travel_back end end diff --git a/spec/support/user_info.rb b/spec/support/user_info.rb index 973bc682c..533a6e265 100644 --- a/spec/support/user_info.rb +++ b/spec/support/user_info.rb @@ -12,12 +12,12 @@ # if it's a Proc it will get evaluated RSpec.configure do |config| - config.before(:each) do |example| + config.before do |example| current_user_id = example.metadata[:current_user_id] UserInfo.current_user_id = current_user_id.is_a?(Proc) ? instance_exec(¤t_user_id) : current_user_id end - config.after(:each) do |_example| + config.after do |_example| UserInfo.current_user_id = nil end end