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
|
class ConfigureEnvironment
|
||||||
|
|
||||||
@env_file_content = <<~EOF
|
@env_file_content = <<~ENV_FILE_CONTENT
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
FRESHENVFILE=fresh.env && test -f $FRESHENVFILE && source $FRESHENVFILE
|
FRESHENVFILE=fresh.env && test -f $FRESHENVFILE && source $FRESHENVFILE
|
||||||
true
|
true
|
||||||
EOF
|
ENV_FILE_CONTENT
|
||||||
|
|
||||||
def self.configure_redis
|
def self.configure_redis
|
||||||
if ENV['REDIS_URL'].nil? || ENV['REDIS_URL'].empty? # rubocop:disable Rails/Blank
|
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 RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Zammad
|
module Zammad
|
||||||
|
@ -84,7 +86,7 @@ module RuboCop
|
||||||
|
|
||||||
def handle_node(node)
|
def handle_node(node)
|
||||||
if node.send_type?
|
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)
|
elsif %i[and or begin].include?(node.type)
|
||||||
check_node(node)
|
check_node(node)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Zammad
|
module Zammad
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Zammad
|
module Zammad
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
require 'capybara/rspec/matchers'
|
require 'capybara/rspec/matchers'
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
|
@ -23,8 +25,8 @@ module RuboCop
|
||||||
have_not_no?(matcher_name) && capybara_matcher?(matcher_name)
|
have_not_no?(matcher_name) && capybara_matcher?(matcher_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def have_not_no?(matcher_name)
|
def have_not_no?(matcher_name) # rubocop:disable Naming/PredicateName
|
||||||
matcher_name.match?(/^have_(?!no)/)
|
matcher_name.match?(%r{^have_(?!no)})
|
||||||
end
|
end
|
||||||
|
|
||||||
def capybara_matcher?(matcher_name)
|
def capybara_matcher?(matcher_name)
|
||||||
|
@ -53,10 +55,9 @@ module RuboCop
|
||||||
end
|
end
|
||||||
|
|
||||||
def message(node)
|
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
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Zammad
|
module Zammad
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Zammad
|
module Zammad
|
||||||
|
|
|
@ -12,9 +12,17 @@ inherit_from:
|
||||||
- todo.yml
|
- todo.yml
|
||||||
- todo.rspec.yml
|
- todo.rspec.yml
|
||||||
|
|
||||||
|
inherit_mode:
|
||||||
|
merge:
|
||||||
|
- Include
|
||||||
|
|
||||||
AllCops:
|
AllCops:
|
||||||
NewCops: enable
|
NewCops: enable
|
||||||
DisplayCopNames: true
|
DisplayCopNames: true
|
||||||
|
Include:
|
||||||
|
- '.gitlab/**/*.rb'
|
||||||
|
- '.github/**/*.rb'
|
||||||
|
- '.rubocop/**/*.rb'
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'bin/*'
|
- 'bin/*'
|
||||||
- 'db/schema.rb'
|
- 'db/schema.rb'
|
||||||
|
|
|
@ -8,6 +8,7 @@ FactoryBot.define do
|
||||||
from { 'factory-customer-1@example.com' }
|
from { 'factory-customer-1@example.com' }
|
||||||
to { 'factory-customer-1@example.com' }
|
to { 'factory-customer-1@example.com' }
|
||||||
subject { 'factory article' }
|
subject { 'factory article' }
|
||||||
|
|
||||||
message_id { 'factory@id_com_1' }
|
message_id { 'factory@id_com_1' }
|
||||||
body { 'some message 123' }
|
body { 'some message 123' }
|
||||||
internal { false }
|
internal { false }
|
||||||
|
|
|
@ -13,6 +13,7 @@ RSpec.shared_examples 'TriggerWebhookJob::RecordPayload backend' do |factory|
|
||||||
|
|
||||||
describe '#generate' do
|
describe '#generate' do
|
||||||
subject(:generate) { described_class.new(record).generate }
|
subject(:generate) { described_class.new(record).generate }
|
||||||
|
|
||||||
let(:resolved_associations) { described_class.const_get(:ASSOCIATIONS).map(&:to_s) }
|
let(:resolved_associations) { described_class.const_get(:ASSOCIATIONS).map(&:to_s) }
|
||||||
let(:record) { build(factory) }
|
let(:record) { build(factory) }
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
# 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
|
it 'saves successfully' do
|
||||||
expect(subject).to be_persisted
|
expect(subject).to be_persisted # rubocop:disable RSpec/NamedSubject
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,7 +37,7 @@ RSpec.configure do |config|
|
||||||
|
|
||||||
# make usage of time travel helpers possible
|
# make usage of time travel helpers possible
|
||||||
config.include ActiveSupport::Testing::TimeHelpers
|
config.include ActiveSupport::Testing::TimeHelpers
|
||||||
config.after(:each) do
|
config.after do
|
||||||
travel_back
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ RSpec.configure do |config|
|
||||||
|
|
||||||
# Workaround needed for behavior change introduced in Rails >= 5.2
|
# Workaround needed for behavior change introduced in Rails >= 5.2
|
||||||
# see: https://github.com/rails/rails/issues/37270
|
# see: https://github.com/rails/rails/issues/37270
|
||||||
config.before(:each) do
|
config.before do
|
||||||
(ActiveJob::Base.descendants << ActiveJob::Base).each(&:disable_test_adapter)
|
(ActiveJob::Base.descendants << ActiveJob::Base).each(&:disable_test_adapter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ module ZammadSpecSupportAvatarCheck
|
||||||
# @example
|
# @example
|
||||||
# it 'does stuff with avatar check', perform_avatar_for_email_check: true do
|
# 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]
|
if !example.metadata[:perform_avatar_for_email_check]
|
||||||
allow(Avatar).to receive(:auto_detection).and_return(false)
|
allow(Avatar).to receive(:auto_detection).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
# Cache setup must be the first before hook
|
# Cache setup must be the first before hook
|
||||||
# Otherwise authenticated_as hook fails with random errors
|
# Otherwise authenticated_as hook fails with random errors
|
||||||
config.prepend_before(:each) do
|
config.prepend_before do
|
||||||
# clear the cache otherwise it won't
|
# clear the cache otherwise it won't
|
||||||
# be able to recognize the rollbacks
|
# be able to recognize the rollbacks
|
||||||
# done by RSpec
|
# done by RSpec
|
||||||
|
|
|
@ -157,7 +157,7 @@ module DbMigrationHelper
|
||||||
# @example
|
# @example
|
||||||
# it 'does stuff in an unitialized system', system_init_done: false do
|
# 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)
|
initialized = example.metadata.fetch(:system_init_done, true)
|
||||||
system_init_done(initialized)
|
system_init_done(initialized)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.after(:each) do
|
config.after do
|
||||||
Faker::UniqueGenerator.clear
|
Faker::UniqueGenerator.clear
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
# 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
|
let :knowledge_base do
|
||||||
create(:knowledge_base)
|
create(:knowledge_base)
|
||||||
end
|
end
|
||||||
|
@ -38,10 +38,12 @@ RSpec.shared_context 'basic Knowledge Base', current_user_id: 1 do
|
||||||
end
|
end
|
||||||
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_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_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_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_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) }
|
let!(:menu_item_5) { create(:knowledge_base_menu_item, :for_footer, kb_locale: alternative_locale) }
|
||||||
|
# rubocop:enable RSpec/LetSetup
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
RSpec.configure do |config|
|
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]}'"
|
Rails.logger.info "=== running RSpec example '#{example.metadata[:full_description]}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ module SearchindexBackendHelper
|
||||||
# Execute in RSpec class context
|
# Execute in RSpec class context
|
||||||
base.class_exec do
|
base.class_exec do
|
||||||
|
|
||||||
after(:each) do
|
after do
|
||||||
next if ENV['ES_URL'].blank?
|
next if ENV['ES_URL'].blank?
|
||||||
|
|
||||||
Rake::Task['searchindex:drop'].execute
|
Rake::Task['searchindex:drop'].execute
|
||||||
|
|
|
@ -39,7 +39,7 @@ module SendsNotificationEmailsHelper
|
||||||
# @return [nil]
|
# @return [nil]
|
||||||
def not_sent(args)
|
def not_sent(args)
|
||||||
check_in_progress!
|
check_in_progress!
|
||||||
expect(NotificationFactory::Mailer).to_not have_received(:notification).with(
|
expect(NotificationFactory::Mailer).not_to have_received(:notification).with(
|
||||||
hash_including(args)
|
hash_including(args)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ module SystemInitDoneHelper
|
||||||
|
|
||||||
# just mock the Setting check for `system_init_done`
|
# just mock the Setting check for `system_init_done`
|
||||||
# and return the given parameter value
|
# 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ RSpec.configure do |config|
|
||||||
config.include ActiveSupport::Testing::TimeHelpers
|
config.include ActiveSupport::Testing::TimeHelpers
|
||||||
|
|
||||||
# avoid stuck time issues
|
# avoid stuck time issues
|
||||||
config.after(:each) do
|
config.after do
|
||||||
travel_back
|
travel_back
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
# if it's a Proc it will get evaluated
|
# if it's a Proc it will get evaluated
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
|
||||||
config.before(:each) do |example|
|
config.before do |example|
|
||||||
current_user_id = example.metadata[:current_user_id]
|
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
|
UserInfo.current_user_id = current_user_id.is_a?(Proc) ? instance_exec(¤t_user_id) : current_user_id
|
||||||
end
|
end
|
||||||
|
|
||||||
config.after(:each) do |_example|
|
config.after do |_example|
|
||||||
UserInfo.current_user_id = nil
|
UserInfo.current_user_id = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue