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.
- checksums.yaml +4 -4
- data/.github/workflows/ci-master.yml +1 -1
- data/.github/workflows/ci.yml +1 -1
- data/.github/workflows/publish-gem.yml +9 -19
- data/CONTRIBUTING.md +1 -0
- data/Gemfile +4 -0
- data/README.md +14 -3
- data/Rakefile +27 -1
- data/lib/sorbet-rails/active_record_rbi_formatter.rb +4 -4
- data/lib/sorbet-rails/model_plugins/active_record_querying.rb +27 -0
- data/lib/sorbet-rails/model_rbi_formatter.rb +3 -3
- data/lib/sorbet-rails/rails_mixins/active_record_overrides.rb +1 -1
- data/lib/sorbet-rails/rails_mixins/custom_finder_methods.rb +8 -0
- data/lib/sorbet-rails/tasks/rails_rbi.rake +15 -0
- data/sorbet-rails.gemspec +2 -2
- data/spec/bin/run_all_specs.sh +1 -0
- data/spec/custom_finder_methods_spec.rb +23 -0
- data/spec/generators/rails-template.rb +2 -7
- data/spec/rails_helper.rb +2 -0
- data/spec/rake_rails_rbi_models_spec.rb +1 -1
- data/spec/support/v5.2/Gemfile.lock +76 -67
- data/spec/support/v5.2/sorbet_test_cases.rb +8 -0
- data/spec/support/v6.0/Gemfile.lock +93 -85
- data/spec/support/v6.0/sorbet_test_cases.rb +8 -0
- data/spec/support/v6.1/Gemfile +1 -1
- data/spec/support/v6.1/Gemfile.lock +115 -108
- data/spec/support/v6.1/sorbet_test_cases.rb +11 -0
- data/spec/support/v7.0/.gitattributes +7 -0
- data/spec/support/v7.0/.gitignore +35 -0
- data/spec/support/v7.0/Gemfile +48 -0
- data/spec/support/v7.0/Gemfile.lock +218 -0
- data/spec/support/v7.0/README.md +24 -0
- data/spec/support/v7.0/Rakefile +6 -0
- data/spec/support/v7.0/app/assets/images/.keep +0 -0
- data/spec/support/v7.0/app/assets/stylesheets/application.css +1 -0
- data/spec/support/v7.0/app/controllers/application_controller.rb +3 -0
- data/spec/support/v7.0/app/controllers/concerns/.keep +0 -0
- data/spec/support/v7.0/app/helpers/application_helper.rb +3 -0
- data/spec/support/v7.0/app/helpers/bar_helper.rb +3 -0
- data/spec/support/v7.0/app/helpers/baz_helper.rb +3 -0
- data/spec/support/v7.0/app/helpers/foo_helper.rb +3 -0
- data/spec/support/v7.0/app/jobs/application_job.rb +8 -0
- data/spec/support/v7.0/app/jobs/award_house_point_hourglasses.rb +12 -0
- data/spec/support/v7.0/app/mailers/application_mailer.rb +5 -0
- data/spec/support/v7.0/app/mailers/daily_prophet_mailer.rb +9 -0
- data/spec/support/v7.0/app/mailers/hogwarts_acceptance_mailer.rb +29 -0
- data/spec/support/v7.0/app/models/application_record.rb +4 -0
- data/spec/support/v7.0/app/models/concerns/.keep +0 -0
- data/spec/support/v7.0/app/models/concerns/mythical.rb +11 -0
- data/spec/support/v7.0/app/models/headmaster.rb +8 -0
- data/spec/support/v7.0/app/models/potion.rb +6 -0
- data/spec/support/v7.0/app/models/robe.rb +4 -0
- data/spec/support/v7.0/app/models/school.rb +5 -0
- data/spec/support/v7.0/app/models/spell.rb +5 -0
- data/spec/support/v7.0/app/models/spell_book.rb +18 -0
- data/spec/support/v7.0/app/models/squib.rb +6 -0
- data/spec/support/v7.0/app/models/subject.rb +5 -0
- data/spec/support/v7.0/app/models/wand.rb +19 -0
- data/spec/support/v7.0/app/models/wizard.rb +65 -0
- data/spec/support/v7.0/app/views/layouts/application.html.erb +15 -0
- data/spec/support/v7.0/app/views/layouts/mailer.html.erb +13 -0
- data/spec/support/v7.0/app/views/layouts/mailer.text.erb +1 -0
- data/spec/support/v7.0/bin/bundle +114 -0
- data/spec/support/v7.0/bin/rails +4 -0
- data/spec/support/v7.0/bin/rake +4 -0
- data/spec/support/v7.0/bin/setup +33 -0
- data/spec/support/v7.0/config/application.rb +38 -0
- data/spec/support/v7.0/config/boot.rb +4 -0
- data/spec/support/v7.0/config/database.yml +25 -0
- data/spec/support/v7.0/config/environment.rb +6 -0
- data/spec/support/v7.0/config/environments/development.rb +69 -0
- data/spec/support/v7.0/config/environments/production.rb +83 -0
- data/spec/support/v7.0/config/environments/test.rb +61 -0
- data/spec/support/v7.0/config/initializers/content_security_policy.rb +26 -0
- data/spec/support/v7.0/config/initializers/filter_parameter_logging.rb +9 -0
- data/spec/support/v7.0/config/initializers/inflections.rb +17 -0
- data/spec/support/v7.0/config/initializers/permissions_policy.rb +12 -0
- data/spec/support/v7.0/config/initializers/sorbet_rails.rb +3 -0
- data/spec/support/v7.0/config/locales/en.yml +33 -0
- data/spec/support/v7.0/config/puma.rb +44 -0
- data/spec/support/v7.0/config/routes.rb +8 -0
- data/spec/support/v7.0/config/storage.yml +34 -0
- data/spec/support/v7.0/config.ru +6 -0
- data/spec/support/v7.0/db/migrate/20190620000001_create_wizards.rb +14 -0
- data/spec/support/v7.0/db/migrate/20190620000002_create_wands.rb +12 -0
- data/spec/support/v7.0/db/migrate/20190620000003_create_spell_books.rb +10 -0
- data/spec/support/v7.0/db/migrate/20190620000004_add_more_column_types_to_wands.rb +14 -0
- data/spec/support/v7.0/db/migrate/20190620000005_add_broom_to_wizard.rb +6 -0
- data/spec/support/v7.0/db/migrate/20190620000006_add_more_enums_to_wizard.rb +9 -0
- data/spec/support/v7.0/db/migrate/20190620000007_add_type_to_wizard.rb +6 -0
- data/spec/support/v7.0/db/migrate/20190620000008_add_robe_to_wizard.rb +8 -0
- data/spec/support/v7.0/db/migrate/20190620000009_add_school.rb +10 -0
- data/spec/support/v7.0/db/migrate/20190620000010_add_subject.rb +8 -0
- data/spec/support/v7.0/db/migrate/20190620000011_add_subjects_wizards.rb +8 -0
- data/spec/support/v7.0/db/migrate/20190620000012_add_spell.rb +8 -0
- data/spec/support/v7.0/db/migrate/20190620000013_add_spells_spell_books.rb +8 -0
- data/spec/support/v7.0/db/migrate/20190620000014_create_headmasters.rb +9 -0
- data/spec/support/v7.0/db/migrate/20190620000015_add_serialized_to_wizards.rb +9 -0
- data/spec/support/v7.0/db/schema.rb +98 -0
- data/spec/support/v7.0/db/seeds.rb +8 -0
- data/spec/support/v7.0/lib/assets/.keep +0 -0
- data/spec/support/v7.0/lib/mythical_rbi_plugin.rb +16 -0
- data/spec/support/v7.0/lib/tasks/.keep +0 -0
- data/spec/support/v7.0/log/.keep +0 -0
- data/spec/support/v7.0/sorbet_test_cases.rb +439 -0
- data/spec/support/v7.0/storage/.keep +0 -0
- data/spec/support/v7.0/tmp/.keep +0 -0
- data/spec/support/v7.0/tmp/pids/.keep +0 -0
- data/spec/support/v7.0/tmp/storage/.keep +0 -0
- data/spec/support/v7.0/vendor/.keep +0 -0
- data/spec/test_data/v5.2/expected_active_record_base.rbi +6 -0
- data/spec/test_data/v5.2/expected_active_record_relation.rbi +8 -2
- data/spec/test_data/v5.2/expected_attachment.rbi +3 -3
- data/spec/test_data/v5.2/expected_blob.rbi +3 -3
- data/spec/test_data/v5.2/expected_habtm_subjects.rbi +3 -3
- data/spec/test_data/v5.2/expected_habtm_wizards.rbi +3 -3
- data/spec/test_data/v5.2/expected_headmaster.rbi +3 -3
- data/spec/test_data/v5.2/expected_internal_metadata.rbi +3 -3
- data/spec/test_data/v5.2/expected_potion.rbi +3 -3
- data/spec/test_data/v5.2/expected_robe.rbi +3 -3
- data/spec/test_data/v5.2/expected_schema_migration.rbi +3 -3
- data/spec/test_data/v5.2/expected_school.rbi +3 -3
- data/spec/test_data/v5.2/expected_spell/habtm_spell_books.rbi +3 -3
- data/spec/test_data/v5.2/expected_spell.rbi +3 -3
- data/spec/test_data/v5.2/expected_spell_book/habtm_spell_books.rbi +3 -3
- data/spec/test_data/v5.2/expected_spell_book/habtm_spells.rbi +3 -3
- data/spec/test_data/v5.2/expected_spell_book.rbi +3 -3
- data/spec/test_data/v5.2/expected_squib.rbi +3 -3
- data/spec/test_data/v5.2/expected_subject/habtm_wizards.rbi +3 -3
- data/spec/test_data/v5.2/expected_subject.rbi +3 -3
- data/spec/test_data/v5.2/expected_wand.rbi +3 -3
- data/spec/test_data/v5.2/expected_wizard/habtm_subjects.rbi +3 -3
- data/spec/test_data/v5.2/expected_wizard.rbi +3 -3
- data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +3 -3
- data/spec/test_data/v6.0/expected_active_record_base.rbi +6 -0
- data/spec/test_data/v6.0/expected_active_record_relation.rbi +8 -2
- data/spec/test_data/v6.0/expected_attachment.rbi +3 -3
- data/spec/test_data/v6.0/expected_blob.rbi +3 -3
- data/spec/test_data/v6.0/expected_habtm_subjects.rbi +3 -3
- data/spec/test_data/v6.0/expected_habtm_wizards.rbi +3 -3
- data/spec/test_data/v6.0/expected_headmaster.rbi +3 -3
- data/spec/test_data/v6.0/expected_internal_metadata.rbi +3 -3
- data/spec/test_data/v6.0/expected_potion.rbi +3 -3
- data/spec/test_data/v6.0/expected_robe.rbi +3 -3
- data/spec/test_data/v6.0/expected_schema_migration.rbi +3 -3
- data/spec/test_data/v6.0/expected_school.rbi +3 -3
- data/spec/test_data/v6.0/expected_spell/habtm_spell_books.rbi +3 -3
- data/spec/test_data/v6.0/expected_spell.rbi +3 -3
- data/spec/test_data/v6.0/expected_spell_book/habtm_spell_books.rbi +3 -3
- data/spec/test_data/v6.0/expected_spell_book/habtm_spells.rbi +3 -3
- data/spec/test_data/v6.0/expected_spell_book.rbi +3 -3
- data/spec/test_data/v6.0/expected_squib.rbi +3 -3
- data/spec/test_data/v6.0/expected_subject/habtm_wizards.rbi +3 -3
- data/spec/test_data/v6.0/expected_subject.rbi +3 -3
- data/spec/test_data/v6.0/expected_wand.rbi +3 -3
- data/spec/test_data/v6.0/expected_wizard/habtm_subjects.rbi +3 -3
- data/spec/test_data/v6.0/expected_wizard.rbi +3 -3
- data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +3 -3
- data/spec/test_data/v6.1/expected_active_record_base.rbi +6 -0
- data/spec/test_data/v6.1/expected_active_record_relation.rbi +8 -2
- data/spec/test_data/v6.1/expected_attachment.rbi +9 -3
- data/spec/test_data/v6.1/expected_blob.rbi +9 -3
- data/spec/test_data/v6.1/expected_habtm_subjects.rbi +3 -3
- data/spec/test_data/v6.1/expected_habtm_wizards.rbi +3 -3
- data/spec/test_data/v6.1/expected_headmaster.rbi +9 -3
- data/spec/test_data/v6.1/expected_internal_metadata.rbi +9 -3
- data/spec/test_data/v6.1/expected_potion.rbi +9 -3
- data/spec/test_data/v6.1/expected_record.rbi +9 -3
- data/spec/test_data/v6.1/expected_robe.rbi +9 -3
- data/spec/test_data/v6.1/expected_schema_migration.rbi +9 -3
- data/spec/test_data/v6.1/expected_school.rbi +9 -3
- data/spec/test_data/v6.1/expected_spell/habtm_spell_books.rbi +9 -3
- data/spec/test_data/v6.1/expected_spell.rbi +9 -3
- data/spec/test_data/v6.1/expected_spell_book/habtm_spell_books.rbi +3 -3
- data/spec/test_data/v6.1/expected_spell_book/habtm_spells.rbi +9 -3
- data/spec/test_data/v6.1/expected_spell_book.rbi +9 -3
- data/spec/test_data/v6.1/expected_squib.rbi +9 -3
- data/spec/test_data/v6.1/expected_subject/habtm_wizards.rbi +9 -3
- data/spec/test_data/v6.1/expected_subject.rbi +9 -3
- data/spec/test_data/v6.1/expected_variant_record.rbi +9 -3
- data/spec/test_data/v6.1/expected_wand.rbi +9 -3
- data/spec/test_data/v6.1/expected_wizard/habtm_subjects.rbi +9 -3
- data/spec/test_data/v6.1/expected_wizard.rbi +9 -3
- data/spec/test_data/v6.1/expected_wizard_wo_spellbook.rbi +9 -3
- data/spec/test_data/v7.0/expected_active_record_base.rbi +119 -0
- data/spec/test_data/v7.0/expected_active_record_relation.rbi +180 -0
- data/spec/test_data/v7.0/expected_application_job.rbi +20 -0
- data/spec/test_data/v7.0/expected_application_mailer.rbi +5 -0
- data/spec/test_data/v7.0/expected_attachment.rbi +358 -0
- data/spec/test_data/v7.0/expected_award_house_point_hourglasses.rbi +20 -0
- data/spec/test_data/v7.0/expected_blob.rbi +394 -0
- data/spec/test_data/v7.0/expected_custom_application_job.rbi +21 -0
- data/spec/test_data/v7.0/expected_custom_application_mailer.rbi +6 -0
- data/spec/test_data/v7.0/expected_custom_award_house_point_hourglasses.rbi +21 -0
- data/spec/test_data/v7.0/expected_custom_daily_prophet_mailer.rbi +8 -0
- data/spec/test_data/v7.0/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
- data/spec/test_data/v7.0/expected_daily_prophet_mailer.rbi +7 -0
- data/spec/test_data/v7.0/expected_headmaster.rbi +376 -0
- data/spec/test_data/v7.0/expected_helpers.rbi +27 -0
- data/spec/test_data/v7.0/expected_helpers_with_application_and_devise_helpers.rbi +34 -0
- data/spec/test_data/v7.0/expected_hogwarts_acceptance_mailer.rbi +20 -0
- data/spec/test_data/v7.0/expected_internal_metadata.rbi +346 -0
- data/spec/test_data/v7.0/expected_no_routes.rbi +4 -0
- data/spec/test_data/v7.0/expected_potion.rbi +328 -0
- data/spec/test_data/v7.0/expected_record.rbi +307 -0
- data/spec/test_data/v7.0/expected_robe.rbi +349 -0
- data/spec/test_data/v7.0/expected_routes.rbi +182 -0
- data/spec/test_data/v7.0/expected_schema_migration.rbi +319 -0
- data/spec/test_data/v7.0/expected_school.rbi +349 -0
- data/spec/test_data/v7.0/expected_spell/habtm_spell_books.rbi +367 -0
- data/spec/test_data/v7.0/expected_spell.rbi +340 -0
- data/spec/test_data/v7.0/expected_spell_book/habtm_spells.rbi +367 -0
- data/spec/test_data/v7.0/expected_spell_book.rbi +499 -0
- data/spec/test_data/v7.0/expected_squib.rbi +1204 -0
- data/spec/test_data/v7.0/expected_srb_tc_output.txt +1 -0
- data/spec/test_data/v7.0/expected_subject/habtm_wizards.rbi +367 -0
- data/spec/test_data/v7.0/expected_subject.rbi +340 -0
- data/spec/test_data/v7.0/expected_variant_record.rbi +382 -0
- data/spec/test_data/v7.0/expected_wand.rbi +611 -0
- data/spec/test_data/v7.0/expected_wizard/habtm_subjects.rbi +367 -0
- data/spec/test_data/v7.0/expected_wizard.rbi +1280 -0
- data/spec/test_data/v7.0/expected_wizard_wo_spellbook.rbi +1274 -0
- metadata +245 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6ae993b835bd73f18fd64cacdf0fb9f3ba8e44d8ad42cb59fa103d1f2d8a481
|
4
|
+
data.tar.gz: d47b11ca70a73985bd8e811f56fee3394960c063b8e1850470f5ff1c1202bc63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 372bb4773d316e81a5318e3749a215fec0c3c7c72dd1f363bb3c342775a93be4d82b634943d29e31552a912833ed1b3c4a4291f48acc982a9710cc28f59939b5
|
7
|
+
data.tar.gz: feaf6bcf6955f9eb9941f8f52e572c80a90a5bde285d9ccb3ec3741fad54ad51dec140dc591de041f676d26728a5c2da6b26470ed0da30b21d07b0dbe1fb2d03
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,27 +1,17 @@
|
|
1
1
|
name: publish-gem
|
2
2
|
|
3
3
|
on:
|
4
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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'
|
data/spec/bin/run_all_specs.sh
CHANGED
@@ -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
|
-
|
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