sorbet-rails 0.7.31 → 0.7.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci-master.yml +1 -1
  3. data/.github/workflows/ci.yml +1 -1
  4. data/.github/workflows/publish-gem.yml +9 -19
  5. data/CONTRIBUTING.md +1 -0
  6. data/Gemfile +4 -0
  7. data/README.md +14 -3
  8. data/Rakefile +27 -1
  9. data/lib/sorbet-rails/active_record_rbi_formatter.rb +4 -4
  10. data/lib/sorbet-rails/model_plugins/active_record_querying.rb +27 -0
  11. data/lib/sorbet-rails/model_rbi_formatter.rb +3 -3
  12. data/lib/sorbet-rails/rails_mixins/active_record_overrides.rb +1 -1
  13. data/lib/sorbet-rails/rails_mixins/custom_finder_methods.rb +8 -0
  14. data/lib/sorbet-rails/tasks/rails_rbi.rake +15 -0
  15. data/sorbet-rails.gemspec +2 -2
  16. data/spec/bin/run_all_specs.sh +1 -0
  17. data/spec/custom_finder_methods_spec.rb +23 -0
  18. data/spec/generators/rails-template.rb +2 -7
  19. data/spec/rails_helper.rb +2 -0
  20. data/spec/rake_rails_rbi_models_spec.rb +1 -1
  21. data/spec/support/v5.2/Gemfile.lock +76 -67
  22. data/spec/support/v5.2/sorbet_test_cases.rb +8 -0
  23. data/spec/support/v6.0/Gemfile.lock +93 -85
  24. data/spec/support/v6.0/sorbet_test_cases.rb +8 -0
  25. data/spec/support/v6.1/Gemfile +1 -1
  26. data/spec/support/v6.1/Gemfile.lock +115 -108
  27. data/spec/support/v6.1/sorbet_test_cases.rb +11 -0
  28. data/spec/support/v7.0/.gitattributes +7 -0
  29. data/spec/support/v7.0/.gitignore +35 -0
  30. data/spec/support/v7.0/Gemfile +48 -0
  31. data/spec/support/v7.0/Gemfile.lock +218 -0
  32. data/spec/support/v7.0/README.md +24 -0
  33. data/spec/support/v7.0/Rakefile +6 -0
  34. data/spec/support/v7.0/app/assets/images/.keep +0 -0
  35. data/spec/support/v7.0/app/assets/stylesheets/application.css +1 -0
  36. data/spec/support/v7.0/app/controllers/application_controller.rb +3 -0
  37. data/spec/support/v7.0/app/controllers/concerns/.keep +0 -0
  38. data/spec/support/v7.0/app/helpers/application_helper.rb +3 -0
  39. data/spec/support/v7.0/app/helpers/bar_helper.rb +3 -0
  40. data/spec/support/v7.0/app/helpers/baz_helper.rb +3 -0
  41. data/spec/support/v7.0/app/helpers/foo_helper.rb +3 -0
  42. data/spec/support/v7.0/app/jobs/application_job.rb +8 -0
  43. data/spec/support/v7.0/app/jobs/award_house_point_hourglasses.rb +12 -0
  44. data/spec/support/v7.0/app/mailers/application_mailer.rb +5 -0
  45. data/spec/support/v7.0/app/mailers/daily_prophet_mailer.rb +9 -0
  46. data/spec/support/v7.0/app/mailers/hogwarts_acceptance_mailer.rb +29 -0
  47. data/spec/support/v7.0/app/models/application_record.rb +4 -0
  48. data/spec/support/v7.0/app/models/concerns/.keep +0 -0
  49. data/spec/support/v7.0/app/models/concerns/mythical.rb +11 -0
  50. data/spec/support/v7.0/app/models/headmaster.rb +8 -0
  51. data/spec/support/v7.0/app/models/potion.rb +6 -0
  52. data/spec/support/v7.0/app/models/robe.rb +4 -0
  53. data/spec/support/v7.0/app/models/school.rb +5 -0
  54. data/spec/support/v7.0/app/models/spell.rb +5 -0
  55. data/spec/support/v7.0/app/models/spell_book.rb +18 -0
  56. data/spec/support/v7.0/app/models/squib.rb +6 -0
  57. data/spec/support/v7.0/app/models/subject.rb +5 -0
  58. data/spec/support/v7.0/app/models/wand.rb +19 -0
  59. data/spec/support/v7.0/app/models/wizard.rb +65 -0
  60. data/spec/support/v7.0/app/views/layouts/application.html.erb +15 -0
  61. data/spec/support/v7.0/app/views/layouts/mailer.html.erb +13 -0
  62. data/spec/support/v7.0/app/views/layouts/mailer.text.erb +1 -0
  63. data/spec/support/v7.0/bin/bundle +114 -0
  64. data/spec/support/v7.0/bin/rails +4 -0
  65. data/spec/support/v7.0/bin/rake +4 -0
  66. data/spec/support/v7.0/bin/setup +33 -0
  67. data/spec/support/v7.0/config/application.rb +38 -0
  68. data/spec/support/v7.0/config/boot.rb +4 -0
  69. data/spec/support/v7.0/config/database.yml +25 -0
  70. data/spec/support/v7.0/config/environment.rb +6 -0
  71. data/spec/support/v7.0/config/environments/development.rb +69 -0
  72. data/spec/support/v7.0/config/environments/production.rb +83 -0
  73. data/spec/support/v7.0/config/environments/test.rb +61 -0
  74. data/spec/support/v7.0/config/initializers/content_security_policy.rb +26 -0
  75. data/spec/support/v7.0/config/initializers/filter_parameter_logging.rb +9 -0
  76. data/spec/support/v7.0/config/initializers/inflections.rb +17 -0
  77. data/spec/support/v7.0/config/initializers/permissions_policy.rb +12 -0
  78. data/spec/support/v7.0/config/initializers/sorbet_rails.rb +3 -0
  79. data/spec/support/v7.0/config/locales/en.yml +33 -0
  80. data/spec/support/v7.0/config/puma.rb +44 -0
  81. data/spec/support/v7.0/config/routes.rb +8 -0
  82. data/spec/support/v7.0/config/storage.yml +34 -0
  83. data/spec/support/v7.0/config.ru +6 -0
  84. data/spec/support/v7.0/db/migrate/20190620000001_create_wizards.rb +14 -0
  85. data/spec/support/v7.0/db/migrate/20190620000002_create_wands.rb +12 -0
  86. data/spec/support/v7.0/db/migrate/20190620000003_create_spell_books.rb +10 -0
  87. data/spec/support/v7.0/db/migrate/20190620000004_add_more_column_types_to_wands.rb +14 -0
  88. data/spec/support/v7.0/db/migrate/20190620000005_add_broom_to_wizard.rb +6 -0
  89. data/spec/support/v7.0/db/migrate/20190620000006_add_more_enums_to_wizard.rb +9 -0
  90. data/spec/support/v7.0/db/migrate/20190620000007_add_type_to_wizard.rb +6 -0
  91. data/spec/support/v7.0/db/migrate/20190620000008_add_robe_to_wizard.rb +8 -0
  92. data/spec/support/v7.0/db/migrate/20190620000009_add_school.rb +10 -0
  93. data/spec/support/v7.0/db/migrate/20190620000010_add_subject.rb +8 -0
  94. data/spec/support/v7.0/db/migrate/20190620000011_add_subjects_wizards.rb +8 -0
  95. data/spec/support/v7.0/db/migrate/20190620000012_add_spell.rb +8 -0
  96. data/spec/support/v7.0/db/migrate/20190620000013_add_spells_spell_books.rb +8 -0
  97. data/spec/support/v7.0/db/migrate/20190620000014_create_headmasters.rb +9 -0
  98. data/spec/support/v7.0/db/migrate/20190620000015_add_serialized_to_wizards.rb +9 -0
  99. data/spec/support/v7.0/db/schema.rb +98 -0
  100. data/spec/support/v7.0/db/seeds.rb +8 -0
  101. data/spec/support/v7.0/lib/assets/.keep +0 -0
  102. data/spec/support/v7.0/lib/mythical_rbi_plugin.rb +16 -0
  103. data/spec/support/v7.0/lib/tasks/.keep +0 -0
  104. data/spec/support/v7.0/log/.keep +0 -0
  105. data/spec/support/v7.0/sorbet_test_cases.rb +439 -0
  106. data/spec/support/v7.0/storage/.keep +0 -0
  107. data/spec/support/v7.0/tmp/.keep +0 -0
  108. data/spec/support/v7.0/tmp/pids/.keep +0 -0
  109. data/spec/support/v7.0/tmp/storage/.keep +0 -0
  110. data/spec/support/v7.0/vendor/.keep +0 -0
  111. data/spec/test_data/v5.2/expected_active_record_base.rbi +6 -0
  112. data/spec/test_data/v5.2/expected_active_record_relation.rbi +8 -2
  113. data/spec/test_data/v5.2/expected_attachment.rbi +3 -3
  114. data/spec/test_data/v5.2/expected_blob.rbi +3 -3
  115. data/spec/test_data/v5.2/expected_habtm_subjects.rbi +3 -3
  116. data/spec/test_data/v5.2/expected_habtm_wizards.rbi +3 -3
  117. data/spec/test_data/v5.2/expected_headmaster.rbi +3 -3
  118. data/spec/test_data/v5.2/expected_internal_metadata.rbi +3 -3
  119. data/spec/test_data/v5.2/expected_potion.rbi +3 -3
  120. data/spec/test_data/v5.2/expected_robe.rbi +3 -3
  121. data/spec/test_data/v5.2/expected_schema_migration.rbi +3 -3
  122. data/spec/test_data/v5.2/expected_school.rbi +3 -3
  123. data/spec/test_data/v5.2/expected_spell/habtm_spell_books.rbi +3 -3
  124. data/spec/test_data/v5.2/expected_spell.rbi +3 -3
  125. data/spec/test_data/v5.2/expected_spell_book/habtm_spell_books.rbi +3 -3
  126. data/spec/test_data/v5.2/expected_spell_book/habtm_spells.rbi +3 -3
  127. data/spec/test_data/v5.2/expected_spell_book.rbi +3 -3
  128. data/spec/test_data/v5.2/expected_squib.rbi +3 -3
  129. data/spec/test_data/v5.2/expected_subject/habtm_wizards.rbi +3 -3
  130. data/spec/test_data/v5.2/expected_subject.rbi +3 -3
  131. data/spec/test_data/v5.2/expected_wand.rbi +3 -3
  132. data/spec/test_data/v5.2/expected_wizard/habtm_subjects.rbi +3 -3
  133. data/spec/test_data/v5.2/expected_wizard.rbi +3 -3
  134. data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +3 -3
  135. data/spec/test_data/v6.0/expected_active_record_base.rbi +6 -0
  136. data/spec/test_data/v6.0/expected_active_record_relation.rbi +8 -2
  137. data/spec/test_data/v6.0/expected_attachment.rbi +3 -3
  138. data/spec/test_data/v6.0/expected_blob.rbi +3 -3
  139. data/spec/test_data/v6.0/expected_habtm_subjects.rbi +3 -3
  140. data/spec/test_data/v6.0/expected_habtm_wizards.rbi +3 -3
  141. data/spec/test_data/v6.0/expected_headmaster.rbi +3 -3
  142. data/spec/test_data/v6.0/expected_internal_metadata.rbi +3 -3
  143. data/spec/test_data/v6.0/expected_potion.rbi +3 -3
  144. data/spec/test_data/v6.0/expected_robe.rbi +3 -3
  145. data/spec/test_data/v6.0/expected_schema_migration.rbi +3 -3
  146. data/spec/test_data/v6.0/expected_school.rbi +3 -3
  147. data/spec/test_data/v6.0/expected_spell/habtm_spell_books.rbi +3 -3
  148. data/spec/test_data/v6.0/expected_spell.rbi +3 -3
  149. data/spec/test_data/v6.0/expected_spell_book/habtm_spell_books.rbi +3 -3
  150. data/spec/test_data/v6.0/expected_spell_book/habtm_spells.rbi +3 -3
  151. data/spec/test_data/v6.0/expected_spell_book.rbi +3 -3
  152. data/spec/test_data/v6.0/expected_squib.rbi +3 -3
  153. data/spec/test_data/v6.0/expected_subject/habtm_wizards.rbi +3 -3
  154. data/spec/test_data/v6.0/expected_subject.rbi +3 -3
  155. data/spec/test_data/v6.0/expected_wand.rbi +3 -3
  156. data/spec/test_data/v6.0/expected_wizard/habtm_subjects.rbi +3 -3
  157. data/spec/test_data/v6.0/expected_wizard.rbi +3 -3
  158. data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +3 -3
  159. data/spec/test_data/v6.1/expected_active_record_base.rbi +6 -0
  160. data/spec/test_data/v6.1/expected_active_record_relation.rbi +8 -2
  161. data/spec/test_data/v6.1/expected_attachment.rbi +9 -3
  162. data/spec/test_data/v6.1/expected_blob.rbi +9 -3
  163. data/spec/test_data/v6.1/expected_habtm_subjects.rbi +3 -3
  164. data/spec/test_data/v6.1/expected_habtm_wizards.rbi +3 -3
  165. data/spec/test_data/v6.1/expected_headmaster.rbi +9 -3
  166. data/spec/test_data/v6.1/expected_internal_metadata.rbi +9 -3
  167. data/spec/test_data/v6.1/expected_potion.rbi +9 -3
  168. data/spec/test_data/v6.1/expected_record.rbi +9 -3
  169. data/spec/test_data/v6.1/expected_robe.rbi +9 -3
  170. data/spec/test_data/v6.1/expected_schema_migration.rbi +9 -3
  171. data/spec/test_data/v6.1/expected_school.rbi +9 -3
  172. data/spec/test_data/v6.1/expected_spell/habtm_spell_books.rbi +9 -3
  173. data/spec/test_data/v6.1/expected_spell.rbi +9 -3
  174. data/spec/test_data/v6.1/expected_spell_book/habtm_spell_books.rbi +3 -3
  175. data/spec/test_data/v6.1/expected_spell_book/habtm_spells.rbi +9 -3
  176. data/spec/test_data/v6.1/expected_spell_book.rbi +9 -3
  177. data/spec/test_data/v6.1/expected_squib.rbi +9 -3
  178. data/spec/test_data/v6.1/expected_subject/habtm_wizards.rbi +9 -3
  179. data/spec/test_data/v6.1/expected_subject.rbi +9 -3
  180. data/spec/test_data/v6.1/expected_variant_record.rbi +9 -3
  181. data/spec/test_data/v6.1/expected_wand.rbi +9 -3
  182. data/spec/test_data/v6.1/expected_wizard/habtm_subjects.rbi +9 -3
  183. data/spec/test_data/v6.1/expected_wizard.rbi +9 -3
  184. data/spec/test_data/v6.1/expected_wizard_wo_spellbook.rbi +9 -3
  185. data/spec/test_data/v7.0/expected_active_record_base.rbi +119 -0
  186. data/spec/test_data/v7.0/expected_active_record_relation.rbi +180 -0
  187. data/spec/test_data/v7.0/expected_application_job.rbi +20 -0
  188. data/spec/test_data/v7.0/expected_application_mailer.rbi +5 -0
  189. data/spec/test_data/v7.0/expected_attachment.rbi +358 -0
  190. data/spec/test_data/v7.0/expected_award_house_point_hourglasses.rbi +20 -0
  191. data/spec/test_data/v7.0/expected_blob.rbi +394 -0
  192. data/spec/test_data/v7.0/expected_custom_application_job.rbi +21 -0
  193. data/spec/test_data/v7.0/expected_custom_application_mailer.rbi +6 -0
  194. data/spec/test_data/v7.0/expected_custom_award_house_point_hourglasses.rbi +21 -0
  195. data/spec/test_data/v7.0/expected_custom_daily_prophet_mailer.rbi +8 -0
  196. data/spec/test_data/v7.0/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  197. data/spec/test_data/v7.0/expected_daily_prophet_mailer.rbi +7 -0
  198. data/spec/test_data/v7.0/expected_headmaster.rbi +376 -0
  199. data/spec/test_data/v7.0/expected_helpers.rbi +27 -0
  200. data/spec/test_data/v7.0/expected_helpers_with_application_and_devise_helpers.rbi +34 -0
  201. data/spec/test_data/v7.0/expected_hogwarts_acceptance_mailer.rbi +20 -0
  202. data/spec/test_data/v7.0/expected_internal_metadata.rbi +346 -0
  203. data/spec/test_data/v7.0/expected_no_routes.rbi +4 -0
  204. data/spec/test_data/v7.0/expected_potion.rbi +328 -0
  205. data/spec/test_data/v7.0/expected_record.rbi +307 -0
  206. data/spec/test_data/v7.0/expected_robe.rbi +349 -0
  207. data/spec/test_data/v7.0/expected_routes.rbi +182 -0
  208. data/spec/test_data/v7.0/expected_schema_migration.rbi +319 -0
  209. data/spec/test_data/v7.0/expected_school.rbi +349 -0
  210. data/spec/test_data/v7.0/expected_spell/habtm_spell_books.rbi +367 -0
  211. data/spec/test_data/v7.0/expected_spell.rbi +340 -0
  212. data/spec/test_data/v7.0/expected_spell_book/habtm_spells.rbi +367 -0
  213. data/spec/test_data/v7.0/expected_spell_book.rbi +499 -0
  214. data/spec/test_data/v7.0/expected_squib.rbi +1204 -0
  215. data/spec/test_data/v7.0/expected_srb_tc_output.txt +1 -0
  216. data/spec/test_data/v7.0/expected_subject/habtm_wizards.rbi +367 -0
  217. data/spec/test_data/v7.0/expected_subject.rbi +340 -0
  218. data/spec/test_data/v7.0/expected_variant_record.rbi +382 -0
  219. data/spec/test_data/v7.0/expected_wand.rbi +611 -0
  220. data/spec/test_data/v7.0/expected_wizard/habtm_subjects.rbi +367 -0
  221. data/spec/test_data/v7.0/expected_wizard.rbi +1280 -0
  222. data/spec/test_data/v7.0/expected_wizard_wo_spellbook.rbi +1274 -0
  223. metadata +245 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c8486bf0c5537443c859e1f51c4aebd3e62bd16370f78526a4f2e879b148c81
4
- data.tar.gz: ffd9da9622e74e186ae94eb9547da174df0e86e294373b06bbdf4caf4d71736f
3
+ metadata.gz: d6ae993b835bd73f18fd64cacdf0fb9f3ba8e44d8ad42cb59fa103d1f2d8a481
4
+ data.tar.gz: d47b11ca70a73985bd8e811f56fee3394960c063b8e1850470f5ff1c1202bc63
5
5
  SHA512:
6
- metadata.gz: e9b9d08940d9c0c82984326439fd8c310955e6c3c59a1b6ed01c46c5ab05ca71680e9627f0bef456942ad2c08430d216ad969a0506c2478c0fec5863a3bb3d32
7
- data.tar.gz: 82f9e89b908de82b1a63f02f60cef7aea5ded0108c2717b3e3aa1ee0ac2ee534476327fb5483a155d98d95f9f35640534ce133a2b017daf31797844725a91138
6
+ metadata.gz: 372bb4773d316e81a5318e3749a215fec0c3c7c72dd1f363bb3c342775a93be4d82b634943d29e31552a912833ed1b3c4a4291f48acc982a9710cc28f59939b5
7
+ data.tar.gz: feaf6bcf6955f9eb9941f8f52e572c80a90a5bde285d9ccb3ec3741fad54ad51dec140dc591de041f676d26728a5c2da6b26470ed0da30b21d07b0dbe1fb2d03
@@ -15,7 +15,7 @@ jobs:
15
15
  fail-fast: false
16
16
  matrix:
17
17
  ruby: [2.5, 2.6, 2.7]
18
- rails: [5.2, 6.0, 6.1]
18
+ rails: [5.2, 6.0, 6.1, 7.0]
19
19
 
20
20
  env:
21
21
  RAILS_VERSION: ${{ matrix.rails }}
@@ -11,7 +11,7 @@ jobs:
11
11
  fail-fast: false
12
12
  matrix:
13
13
  ruby: [2.5, 2.6, 2.7]
14
- rails: [5.2, 6.0, 6.1]
14
+ rails: [5.2, 6.0, 6.1, 7.0]
15
15
 
16
16
  env:
17
17
  RAILS_VERSION: ${{ matrix.rails }}
@@ -1,27 +1,17 @@
1
1
  name: publish-gem
2
2
 
3
3
  on:
4
- # pull_request: # test with pull request
5
- push:
6
- branches: # Trigger only on the main branch to avoid duplicate runs on PR branches
7
- - master
4
+ workflow_dispatch:
8
5
 
9
6
  jobs:
10
7
  build:
11
8
  runs-on: ubuntu-latest
12
-
13
- env:
14
- RAILS_VERSION: 6.0
15
-
16
9
  steps:
17
- - uses: actions/checkout@v2
18
- - uses: ruby/setup-ruby@v1
19
- with:
20
- ruby-version: 2.7
21
- # bundler-cache: true -- this messes up some dynamic constants
22
- - run: "./spec/bin/run_spec.sh"
23
- - run: bundle exec srb tc
24
- - name: Release Gem
25
- uses: dawidd6/action-publish-gem@v1
26
- with:
27
- api_key: ${{secrets.RUBYGEMS_API_KEY}}
10
+ - uses: actions/checkout@v2
11
+ - uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.7
14
+ - name: Release Gem
15
+ uses: dawidd6/action-publish-gem@v1
16
+ with:
17
+ api_key: ${{secrets.RUBYGEMS_API_KEY}}
data/CONTRIBUTING.md CHANGED
@@ -90,6 +90,7 @@ You can also switch to a version of Rails with `RAILS_VERSION`:
90
90
  ❯ RAILS_VERSION=5.2 ./spec/bin/run_spec.sh
91
91
  ❯ RAILS_VERSION=6.0 ./spec/bin/run_spec.sh
92
92
  ❯ RAILS_VERSION=6.1 ./spec/bin/run_spec.sh
93
+ ❯ RAILS_VERSION=7.0 ./spec/bin/run_spec.sh
93
94
  ```
94
95
 
95
96
  #### Debugging
data/Gemfile CHANGED
@@ -25,6 +25,10 @@ when "6.1"
25
25
  gem "rails", "~> 6.1.0"
26
26
  gem "bundler", ">= 2.0"
27
27
  gem "sqlite3", "~> 1.4.1"
28
+ when "7.0"
29
+ gem "rails", "~> 7.0.0"
30
+ gem "bundler", ">= 2.0"
31
+ gem "sqlite3", "~> 1.4.1"
28
32
  else
29
33
  gem "rails", "~> 6.0.0"
30
34
  gem "bundler", ">= 2.0"
data/README.md CHANGED
@@ -9,8 +9,6 @@ This gem adds a few Rake tasks to generate Ruby Interface (RBI) files for dynami
9
9
 
10
10
  `sorbet-rails` supports Rails 5+ or later.
11
11
 
12
- **Notice**: we automatically creates a new release on Rubygems with every merges to the master branch
13
-
14
12
  **Notice**: we no longer support Rails 4.2. [Version 0.5.6](https://github.com/chanzuckerberg/sorbet-rails/releases/tag/v0.5.6) is the last version supporting Rails 4.2.
15
13
 
16
14
  ## Initial Setup
@@ -72,7 +70,7 @@ The generation task currently creates the following signatures:
72
70
 
73
71
  It is possible to add custom RBI generation logic for your custom module or gems via the plugin system. Check out the [plugins section](#extending-model-generation-task-with-custom-plugins) below if you are interested.
74
72
 
75
- We also add following methods to make type-checking more easily:
73
+ We also add following methods to make type-checking easier:
76
74
  - [`find_n`, `first_n`, `last_n`](https://github.com/chanzuckerberg/sorbet-rails#find-first-and-last)
77
75
  - [`pluck_to_tstruct`](#pluck_to_tstruct-instead-of-pluck)
78
76
  - [`typed_enum`](#typed_enum-instead-of-enum)
@@ -287,6 +285,7 @@ specific environment group (eg. `development` only).
287
285
 
288
286
  - Model: The gem provides some helper method to a model to make type-checking easier:
289
287
  - `find_n`, `first_n`, `last_n`
288
+ - `where_missing`
290
289
  - `pluck_to_tstruct`
291
290
  - `typed_enum`
292
291
 
@@ -455,6 +454,18 @@ If you run into the following issue when running rspec, it's likely because you'
455
454
  if you're really stuck.
456
455
  ```
457
456
 
457
+ ### `where.missing` does not exist on `ActiveRecord::Relation` ###
458
+
459
+ The [`where` method](https://apidock.com/rails/ActiveRecord/QueryMethods/where) in Rails has two modes: it can be passed no arguments where it will return an `ActiveRecord::QueryMethods::WhereChain` object, or when given arguments, returns an `ActiveRecord::Relation` object. By default we've opted to support `where` with arguments and have provided a `where_missing` method to avoid conflicts during static typing.
460
+
461
+ ```
462
+ Wizard.where.missing(:wand) # sorbet error, use `where_missing` instead
463
+
464
+ Wizard.where_missing(:wand) # valid, returns a relation
465
+ ```
466
+
467
+ **Note:** `where.missing` / `where_missing` are only available in Rails 6.1 or above
468
+
458
469
  ## Extending RBI Generation logic
459
470
 
460
471
  ### Extending Model Generation Task with Custom Plugins
data/Rakefile CHANGED
@@ -10,11 +10,37 @@ namespace :update_spec do
10
10
 
11
11
  desc "Generate Rails apps for all versions."
12
12
  task :all do |t, args|
13
+ Rake::Task['update_spec:v7_0'].invoke
13
14
  Rake::Task['update_spec:v6_1'].invoke
14
15
  Rake::Task['update_spec:v6_0'].invoke
15
16
  Rake::Task['update_spec:v5_2'].invoke
16
17
  end
17
18
 
19
+ desc "Delete the Rails 7.0 spec directory and regenerate it."
20
+ task :v7_0 do |t, args|
21
+ Bundler.with_clean_env do
22
+ FileUtils.rm_rf 'spec/support/v7.0' if File.directory?('spec/support/v7.0')
23
+ system("gem install rails -v 7.0.3")
24
+ system("rails _7.0.3_ -v")
25
+ command = [
26
+ "RAILS_VERSION='7.0'",
27
+ "rails _7.0.3_ new",
28
+ "--template spec/generators/rails-template.rb",
29
+ "spec/support/v7.0",
30
+ "--skip-action-cable",
31
+ "--skip-action-text",
32
+ "--skip-asset-pipeline",
33
+ "--skip-bootsnap",
34
+ "--skip-hotwire",
35
+ "--skip-javascript",
36
+ "--skip-listen",
37
+ "--skip-spring",
38
+ "--skip-test"
39
+ ].join(" ")
40
+ system(command)
41
+ end
42
+ end
43
+
18
44
  desc "Delete the Rails 6.1 spec directory and regenerate it."
19
45
  task :v6_1 do |t, args|
20
46
  Bundler.with_clean_env do
@@ -47,7 +73,7 @@ namespace :update_spec do
47
73
 
48
74
  desc "Update sorbet_test_cases.rb in all the Rails apps in spec/support."
49
75
  task :sorbet_test_cases do |t, args|
50
- ['v6.1', 'v6.0', 'v5.2'].each do |version|
76
+ ['v7.0', 'v6.1', 'v6.0', 'v5.2'].each do |version|
51
77
  FileUtils.cp("spec/generators/sorbet_test_cases.rb", "spec/support/#{version}/sorbet_test_cases.rb")
52
78
  end
53
79
  end
@@ -40,7 +40,7 @@ class SorbetRails::ActiveRecordRbiFormatter
40
40
  class_rbi.create_include("Enumerable")
41
41
  # class_rbi.create_constant(
42
42
  # "Elem",
43
- # value: "type_member(fixed: T.untyped)",
43
+ # value: "type_member {{fixed: T.untyped}}",
44
44
  # )
45
45
 
46
46
  create_elem_specific_query_methods(class_rbi, type: 'Elem', class_method: false)
@@ -75,7 +75,7 @@ class SorbetRails::ActiveRecordRbiFormatter
75
75
  parlour.root.create_class("ActiveRecord::AssociationRelation", superclass: "ActiveRecord::Relation") do |class_rbi|
76
76
  class_rbi.create_constant(
77
77
  "Elem",
78
- value: "type_member(fixed: T.untyped)",
78
+ value: "type_member {{fixed: T.untyped}}",
79
79
  )
80
80
 
81
81
  # Ideally we shouldn't need to define these since this class inherits from
@@ -110,7 +110,7 @@ class SorbetRails::ActiveRecordRbiFormatter
110
110
  parlour.root.create_class("ActiveRecord::Associations::CollectionProxy", superclass: "ActiveRecord::Relation") do |class_rbi|
111
111
  class_rbi.create_constant(
112
112
  "Elem",
113
- value: "type_member(fixed: T.untyped)",
113
+ value: "type_member {{fixed: T.untyped}}",
114
114
  )
115
115
 
116
116
  # This _should_ work which would let us remove it from the enumerable_collections
@@ -220,7 +220,7 @@ class SorbetRails::ActiveRecordRbiFormatter
220
220
  )
221
221
  end
222
222
 
223
- item_methods = %w(first first! second second! third third! third_to_last third_to_last! second_to_last second_to_last! last last!)
223
+ item_methods = %w(first first! second second! third third! third_to_last third_to_last! second_to_last second_to_last! last last! take take!)
224
224
  item_methods.each do |item_method|
225
225
  class_rbi.create_method(
226
226
  item_method,
@@ -30,6 +30,7 @@ class SorbetRails::ModelPlugins::ActiveRecordQuerying < SorbetRails::ModelPlugin
30
30
  :where, :rewhere, :preload, :extract_associated, :eager_load, :includes, :from, :lock, :readonly, :or,
31
31
  :having, :create_with, :distinct, :references, :none, :unscope, :optimizer_hints, :merge, :except, :only,
32
32
  ]
33
+
33
34
  model_query_relation_methods.each do |method_name|
34
35
  add_relation_query_method(
35
36
  root,
@@ -64,6 +65,32 @@ class SorbetRails::ModelPlugins::ActiveRecordQuerying < SorbetRails::ModelPlugin
64
65
  )
65
66
  end
66
67
 
68
+ # https://api.rubyonrails.org/v6.1.4/classes/ActiveRecord/QueryMethods/WhereChain.html#method-i-missing
69
+ # where.missing is only available in Rails 6.1 and above
70
+ if Rails.version >= "6.1"
71
+ add_relation_query_method(
72
+ root,
73
+ "where_missing", # where_missing is injected by sorbet-rails
74
+ parameters: [
75
+ Parameter.new("*args", type: "Symbol"),
76
+ ],
77
+ builtin_query_method: true,
78
+ )
79
+ end
80
+
81
+ # https://api.rubyonrails.org/v7.0.0/classes/ActiveRecord/QueryMethods.html#method-i-in_order_of
82
+ if Rails.version >= "7.0"
83
+ add_relation_query_method(
84
+ root,
85
+ "in_order_of",
86
+ parameters: [
87
+ Parameter.new("column", type: "Symbol"),
88
+ Parameter.new("values", type: "T::Array[T.untyped]")
89
+ ],
90
+ builtin_query_method: true,
91
+ )
92
+ end
93
+
67
94
  add_relation_query_method(
68
95
  root,
69
96
  "extending",
@@ -80,7 +80,7 @@ class SorbetRails::ModelRbiFormatter
80
80
  model_relation_rbi.create_include(self.model_query_methods_returning_relation_module_name)
81
81
  model_relation_rbi.create_constant(
82
82
  "Elem",
83
- value: "type_member(fixed: #{model_class_name})",
83
+ value: "type_member {{fixed: #{model_class_name}}}",
84
84
  )
85
85
 
86
86
  model_assoc_relation_rbi = root.create_class(
@@ -90,7 +90,7 @@ class SorbetRails::ModelRbiFormatter
90
90
  model_assoc_relation_rbi.create_include(self.model_query_methods_returning_assoc_relation_module_name)
91
91
  model_assoc_relation_rbi.create_constant(
92
92
  "Elem",
93
- value: "type_member(fixed: #{model_class_name})",
93
+ value: "type_member {{fixed: #{model_class_name}}}",
94
94
  )
95
95
 
96
96
  collection_proxy_rbi = root.create_class(
@@ -100,7 +100,7 @@ class SorbetRails::ModelRbiFormatter
100
100
  collection_proxy_rbi.create_include(self.model_query_methods_returning_assoc_relation_module_name)
101
101
  collection_proxy_rbi.create_constant(
102
102
  "Elem",
103
- value: "type_member(fixed: #{self.model_class_name})",
103
+ value: "type_member {{fixed: #{self.model_class_name}}}",
104
104
  )
105
105
 
106
106
  model_rbi = root.create_class(
@@ -55,7 +55,7 @@ module ::ActiveRecord::Enum
55
55
  sig { params(definitions: T::Hash[Symbol, T.untyped]).void }
56
56
  def _define_enum(definitions)
57
57
  ActiveRecordOverrides.instance.store_enum_call(self, definitions)
58
- old_enum(definitions)
58
+ old_enum(**definitions)
59
59
  end
60
60
 
61
61
  sig { params(definitions: T::Hash[Symbol, T.untyped]).void }
@@ -26,5 +26,13 @@ module SorbetRails
26
26
  def find_by_id!(id)
27
27
  find_by!(id: id)
28
28
  end
29
+
30
+ # where.missing is only available in Rails 6.1 and above
31
+ if Rails.version >= "6.1"
32
+ # https://api.rubyonrails.org/v6.1.4/classes/ActiveRecord/QueryMethods/WhereChain.html#method-i-missing
33
+ def where_missing(*args)
34
+ where.missing(*args)
35
+ end
36
+ end
29
37
  end
30
38
  end
@@ -26,6 +26,9 @@ namespace :rails_rbi do
26
26
 
27
27
  desc "Generate rbis for rails routes"
28
28
  task :routes, [:root_dir] => :environment do |t, args|
29
+ # Skip ActionDispatch if not included
30
+ next unless defined?(ActionDispatch)
31
+
29
32
  all_routes = Rails.application.routes.routes
30
33
  require "action_dispatch/routing/inspector"
31
34
  inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
@@ -61,6 +64,9 @@ namespace :rails_rbi do
61
64
 
62
65
  desc "Generate rbis for rails models. Pass models name to regenerate rbi for only the given models."
63
66
  task models: :environment do |t, args|
67
+ # Skip ActiveRecord if not included
68
+ next unless defined?(ActiveRecord)
69
+
64
70
  SorbetRails::Utils.rails_eager_load_all!
65
71
 
66
72
  all_models = Set.new(ActiveRecord::Base.descendants + whitelisted_models - blacklisted_models)
@@ -95,6 +101,9 @@ namespace :rails_rbi do
95
101
 
96
102
  desc "Generate rbis for rails helpers."
97
103
  task helpers: :environment do |t, args|
104
+ # Skip ActionController if not included
105
+ next unless defined?(ActionController)
106
+
98
107
  SorbetRails::Utils.rails_eager_load_all!
99
108
 
100
109
  # API controller does not include ActionController::Helpers
@@ -120,6 +129,9 @@ namespace :rails_rbi do
120
129
 
121
130
  desc "Generate rbis for rails mailers"
122
131
  task :mailers, [:root_dir] => :environment do |t, args|
132
+ # Skip ActiveRecord if not included
133
+ next unless defined?(ActionMailer)
134
+
123
135
  SorbetRails::Utils.rails_eager_load_all!
124
136
  all_mailers = ActionMailer::Base.descendants
125
137
 
@@ -138,6 +150,9 @@ namespace :rails_rbi do
138
150
 
139
151
  desc "Generate rbis for rails mailers"
140
152
  task :jobs, [:root_dir] => :environment do |t, args|
153
+ # Skip ActiveJob if not included
154
+ next unless defined?(ActiveJob)
155
+
141
156
  SorbetRails::Utils.rails_eager_load_all!
142
157
  all_jobs = ActiveJob::Base.descendants
143
158
 
data/sorbet-rails.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{sorbet-rails}
3
- s.version = "0.7.#{ENV['GITHUB_RUN_NUMBER'] || 100}".strip
3
+ s.version = "0.7.34"
4
4
  s.date = %q{2019-04-18}
5
5
  s.summary = %q{Set of tools to make Sorbet work with Rails seamlessly.}
6
6
  s.authors = ["Chan Zuckerberg Initiative"]
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  end
17
17
 
18
18
  s.add_dependency 'parlour', '>= 4.0.1'
19
- s.add_dependency 'sorbet-runtime', '>= 0.5'
19
+ s.add_dependency 'sorbet-runtime', '>= 0.5.9892'
20
20
  s.add_dependency 'sorbet-coerce', '>= 0.2.6'
21
21
  s.add_dependency 'method_source', '>= 0.9.2'
22
22
  s.add_dependency 'parser', '>= 2.7'
@@ -5,6 +5,7 @@ wd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5
5
 
6
6
  RAILS_VERSION=5.2 bash $wd/run_spec.sh
7
7
  RAILS_VERSION=6.1 bash $wd/run_spec.sh
8
+ RAILS_VERSION=7.0 bash $wd/run_spec.sh
8
9
 
9
10
  # Always end with the default version, which is Rails 6.0
10
11
  bash $wd/run_spec.sh
@@ -77,4 +77,27 @@ RSpec.describe SorbetRails::CustomFinderMethods do
77
77
  expect(wizards_3).to eq([harry, ron, hermione])
78
78
  end
79
79
  end
80
+
81
+ context 'test where_missing' do
82
+ # where.missing is only available in Rails 6.1 and above
83
+ if Rails.version < "6.1"
84
+ it 'raises an error' do
85
+ expect { Wizard.where_missing(:wand) }.to raise_error(NoMethodError)
86
+ end
87
+ else
88
+ it 'works with no arguments' do
89
+ missing_with_no_args = Wizard.where_missing
90
+ all_wizards = Wizard.all
91
+
92
+ expect(missing_with_no_args).to eq(all_wizards)
93
+ end
94
+
95
+ it 'retrieves wizards with missing wands' do
96
+ elder_wand = Wand.create!(wizard: harry, wood_type: :holly, core_type: :phoenix_feather)
97
+ wizards_without_wands = Wizard.where_missing(:wand).to_a
98
+
99
+ expect(wizards_without_wands).to eq(Wizard.all.to_a - [harry])
100
+ end
101
+ end
102
+ end
80
103
  end
@@ -125,12 +125,6 @@ def create_models
125
125
  end
126
126
  RUBY
127
127
 
128
- # A nasty hack to add has_one_attached and has_many_attached to the models/wizard.rb file.
129
- attachments = nil
130
- if ['5.2', '6.0', '6.1'].include?(ENV["RAILS_VERSION"])
131
- attachments = "has_one_attached :school_photo\n has_many_attached :hats"
132
- end
133
-
134
128
  file "app/models/wizard.rb", <<~RUBY
135
129
  class Wizard < ApplicationRecord
136
130
  validates :name, length: { minimum: 5 }, presence: true
@@ -194,7 +188,8 @@ def create_models
194
188
  belongs_to :school, optional: true
195
189
 
196
190
  scope :recent, -> { where('created_at > ?', 1.month.ago) }
197
- #{attachments}
191
+ has_one_attached :school_photo
192
+ has_many_attached :hats
198
193
  end
199
194
  RUBY
200
195
 
data/spec/rails_helper.rb CHANGED
@@ -19,6 +19,8 @@ rails_folder =
19
19
  "v6.0"
20
20
  when "6.1"
21
21
  "v6.1"
22
+ when "7.0"
23
+ "v7.0"
22
24
  else
23
25
  "v6.0"
24
26
  end
@@ -33,7 +33,7 @@ RSpec.describe 'rake rails_rbi:models', type: :task do
33
33
  'attachment.rbi',
34
34
  'blob.rbi',
35
35
  ]
36
- if ENV["RAILS_VERSION"] == '6.1'
36
+ if Rails.gem_version >= Gem::Version.new('6.1.0')
37
37
  files += [
38
38
  'record.rbi',
39
39
  'variant_record.rbi',