sorbet-rails 0.7.33 → 0.7.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) 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/CONTRIBUTING.md +1 -0
  5. data/Gemfile +4 -0
  6. data/README.md +1 -1
  7. data/Rakefile +27 -1
  8. data/lib/sorbet-rails/active_record_rbi_formatter.rb +1 -1
  9. data/lib/sorbet-rails/model_plugins/active_record_querying.rb +14 -0
  10. data/lib/sorbet-rails/rails_mixins/active_record_overrides.rb +1 -1
  11. data/lib/sorbet-rails/tasks/rails_rbi.rake +15 -0
  12. data/sorbet-rails.gemspec +1 -1
  13. data/spec/bin/run_all_specs.sh +1 -0
  14. data/spec/generators/rails-template.rb +2 -7
  15. data/spec/rails_helper.rb +2 -0
  16. data/spec/rake_rails_rbi_models_spec.rb +1 -1
  17. data/spec/support/v5.2/sorbet_test_cases.rb +8 -0
  18. data/spec/support/v6.0/sorbet_test_cases.rb +8 -0
  19. data/spec/support/v6.1/sorbet_test_cases.rb +8 -0
  20. data/spec/support/v7.0/.gitattributes +7 -0
  21. data/spec/support/v7.0/.gitignore +35 -0
  22. data/spec/support/v7.0/Gemfile +48 -0
  23. data/spec/support/v7.0/Gemfile.lock +218 -0
  24. data/spec/support/v7.0/README.md +24 -0
  25. data/spec/support/v7.0/Rakefile +6 -0
  26. data/spec/support/v7.0/app/assets/images/.keep +0 -0
  27. data/spec/support/v7.0/app/assets/stylesheets/application.css +1 -0
  28. data/spec/support/v7.0/app/controllers/application_controller.rb +3 -0
  29. data/spec/support/v7.0/app/controllers/concerns/.keep +0 -0
  30. data/spec/support/v7.0/app/helpers/application_helper.rb +3 -0
  31. data/spec/support/v7.0/app/helpers/bar_helper.rb +3 -0
  32. data/spec/support/v7.0/app/helpers/baz_helper.rb +3 -0
  33. data/spec/support/v7.0/app/helpers/foo_helper.rb +3 -0
  34. data/spec/support/v7.0/app/jobs/application_job.rb +8 -0
  35. data/spec/support/v7.0/app/jobs/award_house_point_hourglasses.rb +12 -0
  36. data/spec/support/v7.0/app/mailers/application_mailer.rb +5 -0
  37. data/spec/support/v7.0/app/mailers/daily_prophet_mailer.rb +9 -0
  38. data/spec/support/v7.0/app/mailers/hogwarts_acceptance_mailer.rb +29 -0
  39. data/spec/support/v7.0/app/models/application_record.rb +4 -0
  40. data/spec/support/v7.0/app/models/concerns/.keep +0 -0
  41. data/spec/support/v7.0/app/models/concerns/mythical.rb +11 -0
  42. data/spec/support/v7.0/app/models/headmaster.rb +8 -0
  43. data/spec/support/v7.0/app/models/potion.rb +6 -0
  44. data/spec/support/v7.0/app/models/robe.rb +4 -0
  45. data/spec/support/v7.0/app/models/school.rb +5 -0
  46. data/spec/support/v7.0/app/models/spell.rb +5 -0
  47. data/spec/support/v7.0/app/models/spell_book.rb +18 -0
  48. data/spec/support/v7.0/app/models/squib.rb +6 -0
  49. data/spec/support/v7.0/app/models/subject.rb +5 -0
  50. data/spec/support/v7.0/app/models/wand.rb +19 -0
  51. data/spec/support/v7.0/app/models/wizard.rb +65 -0
  52. data/spec/support/v7.0/app/views/layouts/application.html.erb +15 -0
  53. data/spec/support/v7.0/app/views/layouts/mailer.html.erb +13 -0
  54. data/spec/support/v7.0/app/views/layouts/mailer.text.erb +1 -0
  55. data/spec/support/v7.0/bin/bundle +114 -0
  56. data/spec/support/v7.0/bin/rails +4 -0
  57. data/spec/support/v7.0/bin/rake +4 -0
  58. data/spec/support/v7.0/bin/setup +33 -0
  59. data/spec/support/v7.0/config/application.rb +38 -0
  60. data/spec/support/v7.0/config/boot.rb +4 -0
  61. data/spec/support/v7.0/config/database.yml +25 -0
  62. data/spec/support/v7.0/config/environment.rb +6 -0
  63. data/spec/support/v7.0/config/environments/development.rb +69 -0
  64. data/spec/support/v7.0/config/environments/production.rb +83 -0
  65. data/spec/support/v7.0/config/environments/test.rb +61 -0
  66. data/spec/support/v7.0/config/initializers/content_security_policy.rb +26 -0
  67. data/spec/support/v7.0/config/initializers/filter_parameter_logging.rb +9 -0
  68. data/spec/support/v7.0/config/initializers/inflections.rb +17 -0
  69. data/spec/support/v7.0/config/initializers/permissions_policy.rb +12 -0
  70. data/spec/support/v7.0/config/initializers/sorbet_rails.rb +3 -0
  71. data/spec/support/v7.0/config/locales/en.yml +33 -0
  72. data/spec/support/v7.0/config/puma.rb +44 -0
  73. data/spec/support/v7.0/config/routes.rb +8 -0
  74. data/spec/support/v7.0/config/storage.yml +34 -0
  75. data/spec/support/v7.0/config.ru +6 -0
  76. data/spec/support/v7.0/db/migrate/20190620000001_create_wizards.rb +14 -0
  77. data/spec/support/v7.0/db/migrate/20190620000002_create_wands.rb +12 -0
  78. data/spec/support/v7.0/db/migrate/20190620000003_create_spell_books.rb +10 -0
  79. data/spec/support/v7.0/db/migrate/20190620000004_add_more_column_types_to_wands.rb +14 -0
  80. data/spec/support/v7.0/db/migrate/20190620000005_add_broom_to_wizard.rb +6 -0
  81. data/spec/support/v7.0/db/migrate/20190620000006_add_more_enums_to_wizard.rb +9 -0
  82. data/spec/support/v7.0/db/migrate/20190620000007_add_type_to_wizard.rb +6 -0
  83. data/spec/support/v7.0/db/migrate/20190620000008_add_robe_to_wizard.rb +8 -0
  84. data/spec/support/v7.0/db/migrate/20190620000009_add_school.rb +10 -0
  85. data/spec/support/v7.0/db/migrate/20190620000010_add_subject.rb +8 -0
  86. data/spec/support/v7.0/db/migrate/20190620000011_add_subjects_wizards.rb +8 -0
  87. data/spec/support/v7.0/db/migrate/20190620000012_add_spell.rb +8 -0
  88. data/spec/support/v7.0/db/migrate/20190620000013_add_spells_spell_books.rb +8 -0
  89. data/spec/support/v7.0/db/migrate/20190620000014_create_headmasters.rb +9 -0
  90. data/spec/support/v7.0/db/migrate/20190620000015_add_serialized_to_wizards.rb +9 -0
  91. data/spec/support/v7.0/db/schema.rb +98 -0
  92. data/spec/support/v7.0/db/seeds.rb +8 -0
  93. data/spec/support/v7.0/lib/assets/.keep +0 -0
  94. data/spec/support/v7.0/lib/mythical_rbi_plugin.rb +16 -0
  95. data/spec/support/v7.0/lib/tasks/.keep +0 -0
  96. data/spec/support/v7.0/log/.keep +0 -0
  97. data/spec/support/v7.0/sorbet_test_cases.rb +439 -0
  98. data/spec/support/v7.0/storage/.keep +0 -0
  99. data/spec/support/v7.0/tmp/.keep +0 -0
  100. data/spec/support/v7.0/tmp/pids/.keep +0 -0
  101. data/spec/support/v7.0/tmp/storage/.keep +0 -0
  102. data/spec/support/v7.0/vendor/.keep +0 -0
  103. data/spec/test_data/v5.2/expected_active_record_base.rbi +6 -0
  104. data/spec/test_data/v5.2/expected_active_record_relation.rbi +6 -0
  105. data/spec/test_data/v6.0/expected_active_record_base.rbi +6 -0
  106. data/spec/test_data/v6.0/expected_active_record_relation.rbi +6 -0
  107. data/spec/test_data/v6.1/expected_active_record_base.rbi +6 -0
  108. data/spec/test_data/v6.1/expected_active_record_relation.rbi +6 -0
  109. data/spec/test_data/v7.0/expected_active_record_base.rbi +119 -0
  110. data/spec/test_data/v7.0/expected_active_record_relation.rbi +180 -0
  111. data/spec/test_data/v7.0/expected_application_job.rbi +20 -0
  112. data/spec/test_data/v7.0/expected_application_mailer.rbi +5 -0
  113. data/spec/test_data/v7.0/expected_attachment.rbi +358 -0
  114. data/spec/test_data/v7.0/expected_award_house_point_hourglasses.rbi +20 -0
  115. data/spec/test_data/v7.0/expected_blob.rbi +394 -0
  116. data/spec/test_data/v7.0/expected_custom_application_job.rbi +21 -0
  117. data/spec/test_data/v7.0/expected_custom_application_mailer.rbi +6 -0
  118. data/spec/test_data/v7.0/expected_custom_award_house_point_hourglasses.rbi +21 -0
  119. data/spec/test_data/v7.0/expected_custom_daily_prophet_mailer.rbi +8 -0
  120. data/spec/test_data/v7.0/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  121. data/spec/test_data/v7.0/expected_daily_prophet_mailer.rbi +7 -0
  122. data/spec/test_data/v7.0/expected_headmaster.rbi +376 -0
  123. data/spec/test_data/v7.0/expected_helpers.rbi +27 -0
  124. data/spec/test_data/v7.0/expected_helpers_with_application_and_devise_helpers.rbi +34 -0
  125. data/spec/test_data/v7.0/expected_hogwarts_acceptance_mailer.rbi +20 -0
  126. data/spec/test_data/v7.0/expected_internal_metadata.rbi +346 -0
  127. data/spec/test_data/v7.0/expected_no_routes.rbi +4 -0
  128. data/spec/test_data/v7.0/expected_potion.rbi +328 -0
  129. data/spec/test_data/v7.0/expected_record.rbi +307 -0
  130. data/spec/test_data/v7.0/expected_robe.rbi +349 -0
  131. data/spec/test_data/v7.0/expected_routes.rbi +182 -0
  132. data/spec/test_data/v7.0/expected_schema_migration.rbi +319 -0
  133. data/spec/test_data/v7.0/expected_school.rbi +349 -0
  134. data/spec/test_data/v7.0/expected_spell/habtm_spell_books.rbi +367 -0
  135. data/spec/test_data/v7.0/expected_spell.rbi +340 -0
  136. data/spec/test_data/v7.0/expected_spell_book/habtm_spells.rbi +367 -0
  137. data/spec/test_data/v7.0/expected_spell_book.rbi +499 -0
  138. data/spec/test_data/v7.0/expected_squib.rbi +1204 -0
  139. data/spec/test_data/v7.0/expected_srb_tc_output.txt +1 -0
  140. data/spec/test_data/v7.0/expected_subject/habtm_wizards.rbi +367 -0
  141. data/spec/test_data/v7.0/expected_subject.rbi +340 -0
  142. data/spec/test_data/v7.0/expected_variant_record.rbi +382 -0
  143. data/spec/test_data/v7.0/expected_wand.rbi +611 -0
  144. data/spec/test_data/v7.0/expected_wizard/habtm_subjects.rbi +367 -0
  145. data/spec/test_data/v7.0/expected_wizard.rbi +1280 -0
  146. data/spec/test_data/v7.0/expected_wizard_wo_spellbook.rbi +1274 -0
  147. metadata +243 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c85a4b2dec82b9ff5e78fd20ca40964639474ae84d03641f4d7a2f2ee7afe1ae
4
- data.tar.gz: 62fd90904255f58f2c494a51c170077e347b0746b426717829514aa38df79b48
3
+ metadata.gz: d6ae993b835bd73f18fd64cacdf0fb9f3ba8e44d8ad42cb59fa103d1f2d8a481
4
+ data.tar.gz: d47b11ca70a73985bd8e811f56fee3394960c063b8e1850470f5ff1c1202bc63
5
5
  SHA512:
6
- metadata.gz: 1d57f6492a27063b71f6f02d5731a6b4b05f97395f6ec61cfccf0af782544bd1bd0c9c8205338535dc4563c2be15f51745d03a52d51cd02e53d937c99fbba0b3
7
- data.tar.gz: 8141acaf0b835f523b75f255a647e615017015aab6e40e2d50bd3ff5a523b74589583964553e1fbe6d959f3234722434757cb7aa9a68cc68381a1a5761b5a493
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 }}
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
@@ -70,7 +70,7 @@ The generation task currently creates the following signatures:
70
70
 
71
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.
72
72
 
73
- We also add following methods to make type-checking more easily:
73
+ We also add following methods to make type-checking easier:
74
74
  - [`find_n`, `first_n`, `last_n`](https://github.com/chanzuckerberg/sorbet-rails#find-first-and-last)
75
75
  - [`pluck_to_tstruct`](#pluck_to_tstruct-instead-of-pluck)
76
76
  - [`typed_enum`](#typed_enum-instead-of-enum)
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
@@ -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,
@@ -77,6 +78,19 @@ class SorbetRails::ModelPlugins::ActiveRecordQuerying < SorbetRails::ModelPlugin
77
78
  )
78
79
  end
79
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
+
80
94
  add_relation_query_method(
81
95
  root,
82
96
  "extending",
@@ -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,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.33"
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"]
@@ -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
@@ -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',
@@ -32,6 +32,8 @@ T.assert_type!(wizard.spell_book_ids, T::Array[Integer])
32
32
  # Finder methods -- Model
33
33
  T.assert_type!(Wizard.exists?(name: 'Test'), T::Boolean)
34
34
  T.assert_type!(Wizard.find(wizard.id), Wizard)
35
+ T.assert_type!(Wizard.take, T.nilable(Wizard))
36
+ T.assert_type!(Wizard.take!, Wizard)
35
37
  T.assert_type!(Wizard.first!, Wizard)
36
38
  T.assert_type!(Wizard.first, T.nilable(Wizard))
37
39
  T.assert_type!(Wizard.second!, Wizard)
@@ -90,6 +92,8 @@ T.assert_type!(Wizard.select_columns(:id, :name), Wizard::ActiveRecord_Relation)
90
92
  # Finder methods -- ActiveRecord::Relation
91
93
  T.assert_type!(Wizard.all.exists?(name: 'Harry Potter'), T::Boolean)
92
94
  T.assert_type!(Wizard.all.find(wizard.id), Wizard)
95
+ T.assert_type!(Wizard.all.take, T.nilable(Wizard))
96
+ T.assert_type!(Wizard.all.take!, Wizard)
93
97
  T.assert_type!(Wizard.all.first!, Wizard)
94
98
  T.assert_type!(Wizard.all.first, T.nilable(Wizard))
95
99
  T.assert_type!(Wizard.all.second!, Wizard)
@@ -161,6 +165,8 @@ spell_book = wizard.spell_books.first!
161
165
  spell_books = wizard.spell_books
162
166
  T.assert_type!(spell_books.exists?(name: 'Fantastic Beasts'), T::Boolean)
163
167
  T.assert_type!(spell_books.find(spell_book.id), SpellBook)
168
+ T.assert_type!(spell_books.take, T.nilable(SpellBook))
169
+ T.assert_type!(spell_books.take!, SpellBook)
164
170
  T.assert_type!(spell_books.first!, SpellBook)
165
171
  T.assert_type!(spell_books.first, T.nilable(SpellBook))
166
172
  T.assert_type!(spell_books.second!, SpellBook)
@@ -240,6 +246,8 @@ T.assert_type!(spell_books.push([spell_book]), SpellBook::ActiveRecord_Associati
240
246
  spell_books_query = spell_books.where(wizard_id: wizard.id)
241
247
  T.assert_type!(spell_books_query.exists?(name: 'Fantastic Beasts'), T::Boolean)
242
248
  T.assert_type!(spell_books_query.find(spell_book.id), SpellBook)
249
+ T.assert_type!(spell_books_query.take, T.nilable(SpellBook))
250
+ T.assert_type!(spell_books_query.take!, SpellBook)
243
251
  T.assert_type!(spell_books_query.first!, SpellBook)
244
252
  T.assert_type!(spell_books_query.first, T.nilable(SpellBook))
245
253
  T.assert_type!(spell_books_query.second!, SpellBook)
@@ -32,6 +32,8 @@ T.assert_type!(wizard.spell_book_ids, T::Array[Integer])
32
32
  # Finder methods -- Model
33
33
  T.assert_type!(Wizard.exists?(name: 'Test'), T::Boolean)
34
34
  T.assert_type!(Wizard.find(wizard.id), Wizard)
35
+ T.assert_type!(Wizard.take, T.nilable(Wizard))
36
+ T.assert_type!(Wizard.take!, Wizard)
35
37
  T.assert_type!(Wizard.first!, Wizard)
36
38
  T.assert_type!(Wizard.first, T.nilable(Wizard))
37
39
  T.assert_type!(Wizard.second!, Wizard)
@@ -90,6 +92,8 @@ T.assert_type!(Wizard.select_columns(:id, :name), Wizard::ActiveRecord_Relation)
90
92
  # Finder methods -- ActiveRecord::Relation
91
93
  T.assert_type!(Wizard.all.exists?(name: 'Harry Potter'), T::Boolean)
92
94
  T.assert_type!(Wizard.all.find(wizard.id), Wizard)
95
+ T.assert_type!(Wizard.all.take, T.nilable(Wizard))
96
+ T.assert_type!(Wizard.all.take!, Wizard)
93
97
  T.assert_type!(Wizard.all.first!, Wizard)
94
98
  T.assert_type!(Wizard.all.first, T.nilable(Wizard))
95
99
  T.assert_type!(Wizard.all.second!, Wizard)
@@ -161,6 +165,8 @@ spell_book = wizard.spell_books.first!
161
165
  spell_books = wizard.spell_books
162
166
  T.assert_type!(spell_books.exists?(name: 'Fantastic Beasts'), T::Boolean)
163
167
  T.assert_type!(spell_books.find(spell_book.id), SpellBook)
168
+ T.assert_type!(spell_books.take, T.nilable(SpellBook))
169
+ T.assert_type!(spell_books.take!, SpellBook)
164
170
  T.assert_type!(spell_books.first!, SpellBook)
165
171
  T.assert_type!(spell_books.first, T.nilable(SpellBook))
166
172
  T.assert_type!(spell_books.second!, SpellBook)
@@ -240,6 +246,8 @@ T.assert_type!(spell_books.push([spell_book]), SpellBook::ActiveRecord_Associati
240
246
  spell_books_query = spell_books.where(wizard_id: wizard.id)
241
247
  T.assert_type!(spell_books_query.exists?(name: 'Fantastic Beasts'), T::Boolean)
242
248
  T.assert_type!(spell_books_query.find(spell_book.id), SpellBook)
249
+ T.assert_type!(spell_books_query.take, T.nilable(SpellBook))
250
+ T.assert_type!(spell_books_query.take!, SpellBook)
243
251
  T.assert_type!(spell_books_query.first!, SpellBook)
244
252
  T.assert_type!(spell_books_query.first, T.nilable(SpellBook))
245
253
  T.assert_type!(spell_books_query.second!, SpellBook)
@@ -32,6 +32,8 @@ T.assert_type!(wizard.spell_book_ids, T::Array[Integer])
32
32
  # Finder methods -- Model
33
33
  T.assert_type!(Wizard.exists?(name: 'Test'), T::Boolean)
34
34
  T.assert_type!(Wizard.find(wizard.id), Wizard)
35
+ T.assert_type!(Wizard.take, T.nilable(Wizard))
36
+ T.assert_type!(Wizard.take!, Wizard)
35
37
  T.assert_type!(Wizard.first!, Wizard)
36
38
  T.assert_type!(Wizard.first, T.nilable(Wizard))
37
39
  T.assert_type!(Wizard.second!, Wizard)
@@ -91,6 +93,8 @@ T.assert_type!(Wizard.where_missing(:wand), Wizard::ActiveRecord_Relation)
91
93
  # Finder methods -- ActiveRecord::Relation
92
94
  T.assert_type!(Wizard.all.exists?(name: 'Harry Potter'), T::Boolean)
93
95
  T.assert_type!(Wizard.all.find(wizard.id), Wizard)
96
+ T.assert_type!(Wizard.all.take, T.nilable(Wizard))
97
+ T.assert_type!(Wizard.all.take!, Wizard)
94
98
  T.assert_type!(Wizard.all.first!, Wizard)
95
99
  T.assert_type!(Wizard.all.first, T.nilable(Wizard))
96
100
  T.assert_type!(Wizard.all.second!, Wizard)
@@ -163,6 +167,8 @@ spell_book = wizard.spell_books.first!
163
167
  spell_books = wizard.spell_books
164
168
  T.assert_type!(spell_books.exists?(name: 'Fantastic Beasts'), T::Boolean)
165
169
  T.assert_type!(spell_books.find(spell_book.id), SpellBook)
170
+ T.assert_type!(spell_books.take, T.nilable(SpellBook))
171
+ T.assert_type!(spell_books.take!, SpellBook)
166
172
  T.assert_type!(spell_books.first!, SpellBook)
167
173
  T.assert_type!(spell_books.first, T.nilable(SpellBook))
168
174
  T.assert_type!(spell_books.second!, SpellBook)
@@ -243,6 +249,8 @@ T.assert_type!(spell_books.push([spell_book]), SpellBook::ActiveRecord_Associati
243
249
  spell_books_query = spell_books.where(wizard_id: wizard.id)
244
250
  T.assert_type!(spell_books_query.exists?(name: 'Fantastic Beasts'), T::Boolean)
245
251
  T.assert_type!(spell_books_query.find(spell_book.id), SpellBook)
252
+ T.assert_type!(spell_books_query.take, T.nilable(SpellBook))
253
+ T.assert_type!(spell_books_query.take!, SpellBook)
246
254
  T.assert_type!(spell_books_query.first!, SpellBook)
247
255
  T.assert_type!(spell_books_query.first, T.nilable(SpellBook))
248
256
  T.assert_type!(spell_books_query.second!, SpellBook)
@@ -0,0 +1,7 @@
1
+ # See https://git-scm.com/docs/gitattributes for more about git attribute files.
2
+
3
+ # Mark the database schema as having been generated.
4
+ db/schema.rb linguist-generated
5
+
6
+ # Mark any vendored files as having been vendored.
7
+ vendor/* linguist-vendored
@@ -0,0 +1,35 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-*
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*
16
+ /tmp/*
17
+ !/log/.keep
18
+ !/tmp/.keep
19
+
20
+ # Ignore pidfiles, but keep the directory.
21
+ /tmp/pids/*
22
+ !/tmp/pids/
23
+ !/tmp/pids/.keep
24
+
25
+ # Ignore uploaded files in development.
26
+ /storage/*
27
+ !/storage/.keep
28
+ /tmp/storage/*
29
+ !/tmp/storage/
30
+ !/tmp/storage/.keep
31
+
32
+ /public/assets
33
+
34
+ # Ignore master key for decrypting credentials and more.
35
+ /config/master.key
@@ -0,0 +1,48 @@
1
+ source "https://rubygems.org"
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ ruby "3.0.1"
5
+
6
+ # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
7
+ gem "rails", "~> 7.0.3"
8
+
9
+ # Use sqlite3 as the database for Active Record
10
+ gem "sqlite3", "~> 1.4"
11
+
12
+ # Use the Puma web server [https://github.com/puma/puma]
13
+ gem "puma", "~> 5.0"
14
+
15
+ # Build JSON APIs with ease [https://github.com/rails/jbuilder]
16
+ gem "jbuilder"
17
+
18
+ # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
19
+ # gem "kredis"
20
+
21
+ # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
22
+ # gem "bcrypt", "~> 3.1.7"
23
+
24
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
25
+ gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
26
+
27
+ # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
28
+ # gem "image_processing", "~> 1.2"
29
+
30
+ group :development, :test do
31
+ # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
32
+ gem "debug", platforms: %i[ mri mingw x64_mingw ]
33
+ end
34
+
35
+ group :development do
36
+ # Use console on exceptions pages [https://github.com/rails/web-console]
37
+ gem "web-console"
38
+
39
+ # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
40
+ # gem "rack-mini-profiler"
41
+
42
+ # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
43
+ # gem "spring"
44
+ end
45
+
46
+ gem "sorbet-rails", path: "../../../."
47
+ gem "sorbet"
48
+ gem "sorbet-runtime"