chanzuckerberg / sorbet-rails

A set of tools to make the Sorbet typechecker work with Ruby on Rails seamlessly.
MIT License
638 stars 83 forks source link

Fix select sig #466

Closed hdoan741 closed 3 years ago

hdoan741 commented 3 years ago

I've found a more prevalent use of select with a block. In this PR we change select to support a block instead, and introduce select_columns for the less popular usage, selecting a list of columns from the db.

This is the old signature for select:

-  sig { params(args: T.untyped).returns(Wizard::ActiveRecord_Relation) }
-  def select(*args); end

And the new signatures look like this

+  sig { params(block: T.proc.params(e: ActiveStorage::Attachment).returns(T::Boolean)).returns(T::Array[Wizard]) }
+  def select(&block); end
+
+  sig { params(args: T.any(String, Symbol)).returns(Wizard::ActiveRecord_Relation) }
+  def select_columns(*args); end

See documentation https://apidock.com/rails/ActiveRecord/QueryMethods/select

codecov[bot] commented 3 years ago

Codecov Report

Merging #466 (c6a3238) into master (96093e6) will increase coverage by 0.19%. The diff coverage is 100.00%.

:exclamation: Current head c6a3238 differs from pull request most recent head a03de2a. Consider uploading reports for the commit a03de2a to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##           master     #466      +/-   ##
==========================================
+ Coverage   97.44%   97.63%   +0.19%     
==========================================
  Files         115      115              
  Lines        2894     2923      +29     
==========================================
+ Hits         2820     2854      +34     
+ Misses         74       69       -5     
Impacted Files Coverage Δ
...rbet-rails/model_plugins/active_record_querying.rb 100.00% <100.00%> (ø)
lib/sorbet-rails/model_utils.rb 98.38% <100.00%> (ø)
...sorbet-rails/rails_mixins/custom_finder_methods.rb 100.00% <100.00%> (ø)
spec/support/v5.2/sorbet_test_cases.rb 100.00% <100.00%> (ø)
spec/support/v6.0/sorbet_test_cases.rb 100.00% <100.00%> (ø)
spec/support/v6.1/sorbet_test_cases.rb 100.00% <100.00%> (ø)
spec/sorbet_spec.rb 100.00% <0.00%> (+13.51%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 96093e6...a03de2a. Read the comment docs.