Update active record relations DSL count to accept a block argument #2154
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
While working on a Rails application, I have code that is of the format
Model.count {|m| m.foo_relation.boolean?}
.I don't want to write this as
.select{}.count
as that would violate the Rubocop::Cop::Performance::CopThe fix is to update the type signatures DSL for active record relations to allow
count
to accept an optional block argument.see https://edgeapi.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-count
Implementation
Added to a
create_block_param
call for active record relationscount
method,lib/tapioca/dsl/compilers/active_record_relations.rb
Tests
Updated existing tests for active record relations
count
method to accept an optional block parameter.