Maintenance: Add rubocop to check if a db_strategy is required in your spec test.
This commit is contained in:
parent
8d10872c5d
commit
ff28e17672
45
.rubocop/cop/zammad/exists_db_strategy.rb
Normal file
45
.rubocop/cop/zammad/exists_db_strategy.rb
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module Zammad
|
||||||
|
class ExistsDbStrategy < Base
|
||||||
|
def_node_matcher :migration_execute?, <<-PATTERN
|
||||||
|
$(send (const (const _ :ObjectManager ) :Attribute) :migration_execute)
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def_node_matcher :create_attribute?, <<-PATTERN
|
||||||
|
$(send _ :create_attribute ...)
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def_node_matcher :is_block?, <<-PATTERN
|
||||||
|
$(block ...)
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
def_node_matcher :has_reset?, <<-PATTERN
|
||||||
|
$(send _ {:describe :context :it} (_ ...) (hash ... (pair (sym :db_strategy) (sym {:reset :reset_all}))))
|
||||||
|
PATTERN
|
||||||
|
|
||||||
|
MSG = 'Add a `db_strategy: :reset` to your context/decribe when you are creating object manager attributes!'.freeze
|
||||||
|
|
||||||
|
def on_send(node)
|
||||||
|
return if !migration_execute?(node) && !create_attribute?(node)
|
||||||
|
|
||||||
|
reset = false
|
||||||
|
node_parent = node.parent
|
||||||
|
until node_parent.nil?
|
||||||
|
if is_block?(node_parent) && has_reset?(node_parent.children[0])
|
||||||
|
reset = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
node_parent = node_parent.parent
|
||||||
|
end
|
||||||
|
|
||||||
|
return if reset
|
||||||
|
|
||||||
|
add_offense(node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -314,3 +314,9 @@ Zammad/ExistsResetColumnInformation:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'db/migrate/201*_*.rb'
|
- 'db/migrate/201*_*.rb'
|
||||||
- 'db/migrate/2020*_*.rb'
|
- 'db/migrate/2020*_*.rb'
|
||||||
|
|
||||||
|
Zammad/ExistsDbStrategy:
|
||||||
|
Include:
|
||||||
|
- "spec/**/*.rb"
|
||||||
|
Exclude:
|
||||||
|
- spec/support/capybara/common_actions.rb
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
require_relative 'cop/zammad/exists_condition'
|
require_relative 'cop/zammad/exists_condition'
|
||||||
require_relative 'cop/zammad/exists_date_time_precision'
|
require_relative 'cop/zammad/exists_date_time_precision'
|
||||||
|
require_relative 'cop/zammad/exists_db_strategy'
|
||||||
require_relative 'cop/zammad/exists_reset_column_information'
|
require_relative 'cop/zammad/exists_reset_column_information'
|
||||||
require_relative 'cop/zammad/correct_migration_timestamp'
|
require_relative 'cop/zammad/correct_migration_timestamp'
|
||||||
require_relative 'cop/zammad/have_no_over_not_to'
|
require_relative 'cop/zammad/have_no_over_not_to'
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Ticket, sequencer: :sequence, db_strategy: 'reset' do
|
RSpec.describe ::Sequencer::Sequence::Import::Freshdesk::Ticket, sequencer: :sequence, db_strategy: :reset do
|
||||||
|
|
||||||
context 'when importing tickets from Freshdesk' do
|
context 'when importing tickets from Freshdesk' do
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue