Class: GLRubocop::GLCops::NoTransactionInControllers
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- GLRubocop::GLCops::NoTransactionInControllers
- Defined in:
- lib/gl_rubocop/gl_cops/no_transaction_in_controllers.rb
Overview
This cop bans the use of ActiveRecord transactions within controllers.
Per our controller standards RFC, opening a database transaction in a controller entangles the networking layer with the database layer and violates separation of concerns. Transactional logic belongs in a GLCommand or service object.
Good:
# app/commands/transfer_funds.rb
ActiveRecord::Base.transaction do
# ...
end
Bad:
# app/controllers/transfers_controller.rb
ActiveRecord::Base.transaction do
# ...
end
Constant Summary collapse
- MSG =
'Database transactions are not allowed in controllers. Move transactional ' \ 'logic into a GLCommand or service object.'.freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
30 31 32 33 34 |
# File 'lib/gl_rubocop/gl_cops/no_transaction_in_controllers.rb', line 30 def on_send(node) return unless transaction_on_const?(node) add_offense(node) end |