Module: DevDoc::Test::Lints::EnqueueDisableNaming
- Defined in:
- lib/dev_doc/test/lints/enqueue_disable_naming.rb
Overview
Naming tripwire for the sanctioned NoPerformLaterInModel escape:
every inline disable of that cop in app/models/ must sit inside an
explicitly named notify_* / send_* / deliver_* method.
Rationale
A model-level enqueue is legitimate only when it is inseparable from a
record state change (see the orchestration best-practice doc,
execution-flow category) — and the convention that makes that
legitimate is TWO-part: a justified per-line disable AND an explicit
method name that announces the side effect at every call site. The
meta-guard (Style/DisableCopsWithinSourceCodeDirective) reviews who
may disable; nothing machine-checks the naming half. This lint closes
that: a disable inside finalize or at class level fails the suite.
NOTE: Limitations:
- Enclosing-method detection is indentation-based (reliable under the
standard Layout cops); an
endkeyword inside a heredoc between thedefand the directive can misattribute the method. - The lint validates the NAME only. Whether the enqueue is genuinely state-coupled — the justification for the disable — stays with the reviewer.
Usage
Include this module in a Minitest test class (Rails test env). To change the accepted verb prefixes, redefine the constant on the test class:
class EnqueueDisableNamingTest < ActiveSupport::TestCase
include DevDoc::Test::Lints::EnqueueDisableNaming
# ENQUEUE_METHOD_NAME_PATTERN = /\A(?:notify|send|deliver|dispatch)_/
end
Constant Summary collapse
- ENQUEUE_METHOD_NAME_PATTERN =
Default verb prefixes. Per-project override: redefine the constant on the test class that includes this module.
EnqueueDisableNamingChecker::DEFAULT_NAME_PATTERN
Instance Method Summary collapse
Instance Method Details
#test_model_enqueue_disables_sit_in_explicitly_named_methods ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/dev_doc/test/lints/enqueue_disable_naming.rb', line 118 def test_model_enqueue_disables_sit_in_explicitly_named_methods offenders = EnqueueDisableNamingChecker.new( Rails.root, name_pattern: self.class::ENQUEUE_METHOD_NAME_PATTERN ).offenders assert offenders.empty?, (offenders) end |