Maintenance: Apply Rubocop also to files in .gitlab, .github, .rubocop and to RSpec support files.
This commit is contained in:
parent
365b3eaf1f
commit
e63510c4d0
24 changed files with 50 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Zammad
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Zammad
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Zammad
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Zammad
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue