sorbet-rails 0.6.3 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +1 -2
  3. data/.gitignore +2 -1
  4. data/.travis.yml +3 -1
  5. data/README.md +54 -7
  6. data/Rakefile +3 -3
  7. data/lib/bundled_rbi/customizabel_rbi_formatter.rbi +29 -0
  8. data/lib/bundled_rbi/pluck_to_tstruct.rbi +2 -1
  9. data/lib/bundled_rbi/typed_enum.rbi +7 -0
  10. data/lib/sorbet-rails.rb +1 -3
  11. data/lib/sorbet-rails/active_record_rbi_formatter.rb +8 -2
  12. data/lib/sorbet-rails/config.rb +11 -0
  13. data/lib/sorbet-rails/deprecation.rb +1 -0
  14. data/lib/sorbet-rails/gem_plugins/active_flag_plugin.rb +0 -1
  15. data/lib/sorbet-rails/gem_plugins/kaminari_plugin.rb +8 -0
  16. data/lib/sorbet-rails/gem_plugins/paperclip_plugin.rb +0 -1
  17. data/lib/sorbet-rails/job_rbi_formatter.rb +73 -62
  18. data/lib/sorbet-rails/mailer_rbi_formatter.rb +40 -27
  19. data/lib/sorbet-rails/model_column_utils.rb +129 -0
  20. data/lib/sorbet-rails/model_plugins/active_record_assoc.rb +37 -3
  21. data/lib/sorbet-rails/model_plugins/active_record_attribute.rb +0 -103
  22. data/lib/sorbet-rails/model_plugins/active_record_enum.rb +0 -1
  23. data/lib/sorbet-rails/model_plugins/active_record_named_scope.rb +15 -6
  24. data/lib/sorbet-rails/model_plugins/active_record_querying.rb +34 -3
  25. data/lib/sorbet-rails/model_plugins/active_storage_methods.rb +1 -1
  26. data/lib/sorbet-rails/model_plugins/base.rb +0 -9
  27. data/lib/sorbet-rails/model_rbi_formatter.rb +4 -8
  28. data/lib/sorbet-rails/model_utils.rb +73 -32
  29. data/lib/sorbet-rails/rails_mixins/generated_url_helpers.rb +2 -3
  30. data/lib/sorbet-rails/rails_mixins/pluck_to_tstruct.rb +17 -7
  31. data/lib/sorbet-rails/railtie.rb +0 -2
  32. data/lib/sorbet-rails/sorbet_utils.rb +152 -150
  33. data/lib/sorbet-rails/tasks/rails_rbi.rake +18 -26
  34. data/sorbet-rails.gemspec +1 -1
  35. data/spec/generators/rails-template.rb +3 -6
  36. data/spec/generators/sorbet_test_cases.rb +66 -88
  37. data/spec/job_rbi_formatter_spec.rb +1 -1
  38. data/spec/pluck_to_tstruct_spec.rb +74 -1
  39. data/spec/rails_helper.rb +2 -2
  40. data/spec/rake_rails_rbi_jobs_spec.rb +20 -0
  41. data/spec/rake_rails_rbi_mailers_spec.rb +21 -0
  42. data/spec/support/v5.0/Gemfile +1 -1
  43. data/spec/support/v5.0/Gemfile.lock +9 -9
  44. data/spec/support/v5.0/app/models/spell_book.rb +2 -0
  45. data/spec/support/v5.0/app/models/wizard.rb +1 -1
  46. data/spec/support/v5.0/sorbet_test_cases.rb +66 -88
  47. data/spec/support/v5.1/Gemfile.lock +7 -7
  48. data/spec/support/v5.1/app/models/spell_book.rb +2 -0
  49. data/spec/support/v5.1/app/models/wizard.rb +1 -1
  50. data/spec/support/v5.1/sorbet_test_cases.rb +66 -88
  51. data/spec/support/v5.2/Gemfile +1 -1
  52. data/spec/support/v5.2/Gemfile.lock +9 -9
  53. data/spec/support/v5.2/app/models/spell_book.rb +2 -0
  54. data/spec/support/v5.2/app/models/wizard.rb +1 -1
  55. data/spec/support/v5.2/sorbet_test_cases.rb +66 -88
  56. data/spec/support/v6.0/.gitignore +6 -0
  57. data/spec/support/v6.0/Gemfile +3 -3
  58. data/spec/support/v6.0/Gemfile.lock +77 -76
  59. data/spec/support/v6.0/app/models/spell_book.rb +2 -0
  60. data/spec/support/v6.0/app/models/wizard.rb +1 -1
  61. data/spec/support/v6.0/bin/bundle +22 -13
  62. data/spec/support/v6.0/config/environments/test.rb +1 -1
  63. data/spec/support/v6.0/sorbet_test_cases.rb +66 -88
  64. data/spec/support/v6.0/tmp/pids/.keep +0 -0
  65. data/spec/test_data/v5.0/expected_active_record_base.rbi +2 -2
  66. data/spec/test_data/v5.0/expected_active_record_relation.rbi +2 -2
  67. data/spec/test_data/v5.0/expected_custom_application_job.rbi +21 -0
  68. data/spec/test_data/v5.0/expected_custom_application_mailer.rbi +6 -0
  69. data/spec/test_data/v5.0/expected_custom_award_house_point_hourglasses.rbi +21 -0
  70. data/spec/test_data/v5.0/expected_custom_daily_prophet_mailer.rbi +8 -0
  71. data/spec/test_data/v5.0/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  72. data/spec/test_data/v5.0/expected_headmaster.rbi +60 -190
  73. data/spec/test_data/v5.0/expected_internal_metadata.rbi +42 -188
  74. data/spec/test_data/v5.0/expected_potion.rbi +51 -188
  75. data/spec/test_data/v5.0/expected_robe.rbi +51 -190
  76. data/spec/test_data/v5.0/expected_schema_migration.rbi +42 -188
  77. data/spec/test_data/v5.0/expected_school.rbi +51 -190
  78. data/spec/test_data/v5.0/expected_spell.rbi +42 -190
  79. data/spec/test_data/v5.0/expected_spell/habtm_spell_books.rbi +60 -190
  80. data/spec/test_data/v5.0/expected_spell_book.rbi +86 -215
  81. data/spec/test_data/v5.0/expected_spell_book/habtm_spells.rbi +60 -190
  82. data/spec/test_data/v5.0/expected_squib.rbi +131 -263
  83. data/spec/test_data/v5.0/expected_subject.rbi +42 -190
  84. data/spec/test_data/v5.0/expected_subject/habtm_wizards.rbi +60 -190
  85. data/spec/test_data/v5.0/expected_wand.rbi +84 -225
  86. data/spec/test_data/v5.0/expected_wizard.rbi +131 -263
  87. data/spec/test_data/v5.0/expected_wizard/habtm_subjects.rbi +60 -190
  88. data/spec/test_data/v5.0/expected_wizard_wo_spellbook.rbi +131 -263
  89. data/spec/test_data/v5.1/expected_active_record_base.rbi +2 -2
  90. data/spec/test_data/v5.1/expected_active_record_relation.rbi +2 -2
  91. data/spec/test_data/v5.1/expected_custom_application_job.rbi +21 -0
  92. data/spec/test_data/v5.1/expected_custom_application_mailer.rbi +6 -0
  93. data/spec/test_data/v5.1/expected_custom_award_house_point_hourglasses.rbi +21 -0
  94. data/spec/test_data/v5.1/expected_custom_daily_prophet_mailer.rbi +8 -0
  95. data/spec/test_data/v5.1/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  96. data/spec/test_data/v5.1/expected_headmaster.rbi +60 -196
  97. data/spec/test_data/v5.1/expected_internal_metadata.rbi +42 -194
  98. data/spec/test_data/v5.1/expected_potion.rbi +51 -194
  99. data/spec/test_data/v5.1/expected_robe.rbi +51 -196
  100. data/spec/test_data/v5.1/expected_schema_migration.rbi +42 -194
  101. data/spec/test_data/v5.1/expected_school.rbi +51 -196
  102. data/spec/test_data/v5.1/expected_spell.rbi +42 -196
  103. data/spec/test_data/v5.1/expected_spell/habtm_spell_books.rbi +60 -196
  104. data/spec/test_data/v5.1/expected_spell_book.rbi +86 -221
  105. data/spec/test_data/v5.1/expected_spell_book/habtm_spells.rbi +60 -196
  106. data/spec/test_data/v5.1/expected_squib.rbi +132 -270
  107. data/spec/test_data/v5.1/expected_subject.rbi +42 -196
  108. data/spec/test_data/v5.1/expected_subject/habtm_wizards.rbi +60 -196
  109. data/spec/test_data/v5.1/expected_wand.rbi +84 -231
  110. data/spec/test_data/v5.1/expected_wizard.rbi +132 -270
  111. data/spec/test_data/v5.1/expected_wizard/habtm_subjects.rbi +60 -196
  112. data/spec/test_data/v5.1/expected_wizard_wo_spellbook.rbi +132 -270
  113. data/spec/test_data/v5.2/expected_active_record_base.rbi +2 -2
  114. data/spec/test_data/v5.2/expected_active_record_relation.rbi +2 -2
  115. data/spec/test_data/v5.2/expected_attachment.rbi +60 -194
  116. data/spec/test_data/v5.2/expected_blob.rbi +80 -214
  117. data/spec/test_data/v5.2/expected_custom_application_job.rbi +21 -0
  118. data/spec/test_data/v5.2/expected_custom_application_mailer.rbi +6 -0
  119. data/spec/test_data/v5.2/expected_custom_award_house_point_hourglasses.rbi +21 -0
  120. data/spec/test_data/v5.2/expected_custom_daily_prophet_mailer.rbi +8 -0
  121. data/spec/test_data/v5.2/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  122. data/spec/test_data/v5.2/expected_headmaster.rbi +60 -196
  123. data/spec/test_data/v5.2/expected_internal_metadata.rbi +42 -194
  124. data/spec/test_data/v5.2/expected_potion.rbi +51 -194
  125. data/spec/test_data/v5.2/expected_robe.rbi +51 -196
  126. data/spec/test_data/v5.2/expected_schema_migration.rbi +42 -194
  127. data/spec/test_data/v5.2/expected_school.rbi +51 -196
  128. data/spec/test_data/v5.2/expected_spell.rbi +42 -196
  129. data/spec/test_data/v5.2/expected_spell/habtm_spell_books.rbi +60 -196
  130. data/spec/test_data/v5.2/expected_spell_book.rbi +86 -221
  131. data/spec/test_data/v5.2/expected_spell_book/habtm_spells.rbi +60 -196
  132. data/spec/test_data/v5.2/expected_squib.rbi +156 -276
  133. data/spec/test_data/v5.2/expected_subject.rbi +42 -196
  134. data/spec/test_data/v5.2/expected_subject/habtm_wizards.rbi +60 -196
  135. data/spec/test_data/v5.2/expected_wand.rbi +84 -231
  136. data/spec/test_data/v5.2/expected_wizard.rbi +156 -276
  137. data/spec/test_data/v5.2/expected_wizard/habtm_subjects.rbi +60 -196
  138. data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +156 -276
  139. data/spec/test_data/v6.0/expected_active_record_base.rbi +2 -2
  140. data/spec/test_data/v6.0/expected_active_record_relation.rbi +10 -10
  141. data/spec/test_data/v6.0/expected_attachment.rbi +60 -218
  142. data/spec/test_data/v6.0/expected_blob.rbi +80 -238
  143. data/spec/test_data/v6.0/expected_custom_application_job.rbi +21 -0
  144. data/spec/test_data/v6.0/expected_custom_application_mailer.rbi +6 -0
  145. data/spec/test_data/v6.0/expected_custom_award_house_point_hourglasses.rbi +21 -0
  146. data/spec/test_data/v6.0/expected_custom_daily_prophet_mailer.rbi +8 -0
  147. data/spec/test_data/v6.0/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  148. data/spec/test_data/v6.0/expected_headmaster.rbi +60 -220
  149. data/spec/test_data/v6.0/expected_internal_metadata.rbi +42 -218
  150. data/spec/test_data/v6.0/expected_potion.rbi +51 -218
  151. data/spec/test_data/v6.0/expected_robe.rbi +51 -220
  152. data/spec/test_data/v6.0/expected_routes.rbi +14 -7
  153. data/spec/test_data/v6.0/expected_schema_migration.rbi +42 -218
  154. data/spec/test_data/v6.0/expected_school.rbi +51 -220
  155. data/spec/test_data/v6.0/expected_spell.rbi +42 -220
  156. data/spec/test_data/v6.0/expected_spell/habtm_spell_books.rbi +60 -220
  157. data/spec/test_data/v6.0/expected_spell_book.rbi +98 -257
  158. data/spec/test_data/v6.0/expected_spell_book/habtm_spells.rbi +60 -220
  159. data/spec/test_data/v6.0/expected_squib.rbi +182 -326
  160. data/spec/test_data/v6.0/expected_subject.rbi +42 -220
  161. data/spec/test_data/v6.0/expected_subject/habtm_wizards.rbi +60 -220
  162. data/spec/test_data/v6.0/expected_wand.rbi +100 -271
  163. data/spec/test_data/v6.0/expected_wizard.rbi +182 -326
  164. data/spec/test_data/v6.0/expected_wizard/habtm_subjects.rbi +60 -220
  165. data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +182 -326
  166. metadata +46 -11
  167. data/lib/bundled_rbi/parameters.rbi +0 -28
  168. data/lib/sorbet-rails/custom_types/boolean_string.rb +0 -42
  169. data/lib/sorbet-rails/custom_types/integer_string.rb +0 -45
  170. data/lib/sorbet-rails/rails_mixins/custom_params_methods.rb +0 -57
  171. data/spec/boolean_string_spec.rb +0 -59
  172. data/spec/custom_params_methods_spec.rb +0 -138
  173. data/spec/integer_string_spec.rb +0 -46
@@ -70,7 +70,7 @@ end
70
70
  # File uses File::SEPARATOR by default but will also use File::ALT_SEPARATOR if it's not nil
71
71
  FILE_SEPARATOR_RE = Regexp.union(*[File::SEPARATOR, File::ALT_SEPARATOR].compact).freeze
72
72
 
73
- def expect_files(base_dir:, files:)
73
+ def expect_files(base_dir:, files:, expected_file_prefix: "expected")
74
74
  dirs = Set.new([base_dir])
75
75
  # if any files contain file separators then include those paths in our globbing as well
76
76
  files.each do |f|
@@ -92,7 +92,7 @@ def expect_files(base_dir:, files:)
92
92
  generated = File.read(file_path)
93
93
  # expect there is the same file in test_data folder
94
94
  path_from_dir = pathname.relative_path_from(base_dir).to_path
95
- expect_match_file(generated, "expected_#{path_from_dir}")
95
+ expect_match_file(generated, "#{expected_file_prefix}_#{path_from_dir}")
96
96
  path_from_dir
97
97
  end
98
98
 
@@ -3,6 +3,13 @@ require 'rails_helper'
3
3
  RSpec.describe 'rake rails_rbi:jobs', type: :task do
4
4
  let!(:generated_dir_path) { Rails.root.join("sorbet", "rails-rbi", "jobs") }
5
5
 
6
+ class CustomJobRbiGenerator < SorbetRails::JobRbiFormatter
7
+ def populate_rbi
8
+ rbi_generator.root.add_comment("== Custom Generator ==")
9
+ super
10
+ end
11
+ end
12
+
6
13
  it "preloads the Rails environment" do
7
14
  expect(task.prerequisites).to include("environment")
8
15
  end
@@ -17,4 +24,17 @@ RSpec.describe 'rake rails_rbi:jobs', type: :task do
17
24
  ],
18
25
  )
19
26
  end
27
+
28
+ it "generates custom jobs rbi correctly" do
29
+ ::SorbetRails.config.job_generator_class = CustomJobRbiGenerator
30
+ task.invoke
31
+ expect_files(
32
+ base_dir: generated_dir_path,
33
+ files: [
34
+ "application_job.rbi",
35
+ "award_house_point_hourglasses.rbi",
36
+ ],
37
+ expected_file_prefix: "expected_custom",
38
+ )
39
+ end
20
40
  end
@@ -3,6 +3,13 @@ require 'rails_helper'
3
3
  RSpec.describe 'rake rails_rbi:mailers', type: :task do
4
4
  let!(:generated_dir_path) { Rails.root.join("sorbet", "rails-rbi", "mailers") }
5
5
 
6
+ class CustomMailerRbiGenerator < SorbetRails::MailerRbiFormatter
7
+ def populate_rbi
8
+ rbi_generator.root.add_comment("== Custom Generator ==")
9
+ super
10
+ end
11
+ end
12
+
6
13
  it "preloads the Rails environment" do
7
14
  expect(task.prerequisites).to include("environment")
8
15
  end
@@ -18,4 +25,18 @@ RSpec.describe 'rake rails_rbi:mailers', type: :task do
18
25
  ],
19
26
  )
20
27
  end
28
+
29
+ it "generates custom mailers rbi correctly" do
30
+ ::SorbetRails.config.mailer_generator_class = CustomMailerRbiGenerator
31
+ task.invoke
32
+ expect_files(
33
+ base_dir: generated_dir_path,
34
+ files: [
35
+ "application_mailer.rbi",
36
+ "daily_prophet_mailer.rbi",
37
+ "hogwarts_acceptance_mailer.rbi",
38
+ ],
39
+ expected_file_prefix: "expected_custom",
40
+ )
41
+ end
21
42
  end
@@ -11,7 +11,7 @@ gem 'rails', '~> 5.0.7'
11
11
  # Use sqlite3 as the database for Active Record
12
12
  gem 'sqlite3', '~> 1.3.6'
13
13
  # Use Puma as the app server
14
- gem 'puma', '~> 3.0'
14
+ gem 'puma', '~> 3.12'
15
15
  # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
16
16
  gem 'jbuilder', '~> 2.5'
17
17
  # Use ActiveModel has_secure_password
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- sorbet-rails (0.6.3)
4
+ sorbet-rails (0.7.1)
5
5
  method_source (>= 0.9.2)
6
6
  parlour (~> 2.0)
7
7
  parser (>= 2.7)
@@ -49,7 +49,7 @@ GEM
49
49
  minitest (~> 5.1)
50
50
  tzinfo (~> 1.1)
51
51
  arel (7.1.4)
52
- ast (2.4.0)
52
+ ast (2.4.1)
53
53
  builder (3.2.4)
54
54
  byebug (11.1.1)
55
55
  commander (4.5.2)
@@ -81,11 +81,11 @@ GEM
81
81
  parser
82
82
  rainbow (~> 3.0)
83
83
  sorbet-runtime (>= 0.5)
84
- parser (2.7.1.1)
85
- ast (~> 2.4.0)
84
+ parser (2.7.1.4)
85
+ ast (~> 2.4.1)
86
86
  polyfill (1.8.0)
87
- puma (3.12.4)
88
- rack (2.2.2)
87
+ puma (3.12.6)
88
+ rack (2.2.3)
89
89
  rack-test (0.6.3)
90
90
  rack (>= 1.0)
91
91
  rails (5.0.7.2)
@@ -116,7 +116,7 @@ GEM
116
116
  safe_type (1.1.1)
117
117
  sorbet (0.5.5480)
118
118
  sorbet-static (= 0.5.5480)
119
- sorbet-coerce (0.2.6)
119
+ sorbet-coerce (0.2.7)
120
120
  polyfill (~> 1.8)
121
121
  safe_type (~> 1.1, >= 1.1.1)
122
122
  sorbet (>= 0.4.4704)
@@ -137,7 +137,7 @@ GEM
137
137
  thread_safe (~> 0.1)
138
138
  websocket-driver (0.6.5)
139
139
  websocket-extensions (>= 0.1.0)
140
- websocket-extensions (0.1.4)
140
+ websocket-extensions (0.1.5)
141
141
 
142
142
  PLATFORMS
143
143
  ruby
@@ -145,7 +145,7 @@ PLATFORMS
145
145
  DEPENDENCIES
146
146
  byebug
147
147
  jbuilder (~> 2.5)
148
- puma (~> 3.0)
148
+ puma (~> 3.12)
149
149
  rails (~> 5.0.7)
150
150
  sorbet
151
151
  sorbet-rails!
@@ -13,4 +13,6 @@ class SpellBook < ApplicationRecord
13
13
  biology: 1,
14
14
  dark_art: 999,
15
15
  }
16
+
17
+ scope :recent, -> { where('created_at > ?', 1.month.ago) }
16
18
  end
@@ -2,7 +2,7 @@
2
2
  class Wizard < ApplicationRecord
3
3
  validates :name, length: { minimum: 5 }, presence: true
4
4
  # simulate conditional validation
5
- validates :parent_email, presence: true, if: -> { false }
5
+ validates :parent_email, presence: true, if: :Slytherin?
6
6
 
7
7
  typed_enum house: {
8
8
  Gryffindor: 0,
@@ -29,26 +29,6 @@ T.assert_type!(T.must(wizard.wand).wizard, Wizard)
29
29
  T.assert_type!(wizard.spell_books, SpellBook::ActiveRecord_Associations_CollectionProxy)
30
30
  T.assert_type!(wizard.spell_book_ids, T::Array[Integer])
31
31
 
32
- # -- model relation
33
- # default
34
- T.assert_type!(Wizard.all, Wizard::ActiveRecord_Relation)
35
-
36
- # custom scope
37
- T.assert_type!(Wizard.recent, Wizard::ActiveRecord_Relation)
38
-
39
- # enum scope
40
- T.assert_type!(Wizard.Gryffindor, Wizard::ActiveRecord_Relation)
41
-
42
- # ActiveRecord Querying
43
- T.assert_type!(Wizard.Gryffindor.recent, Wizard::ActiveRecord_Relation)
44
- T.assert_type!(Wizard.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
45
- T.assert_type!(Wizard.where(id: 1), Wizard::ActiveRecord_Relation)
46
- T.assert_type!(Wizard.where(id: 1).recent, Wizard::ActiveRecord_Relation)
47
- T.assert_type!(Wizard.where.not(id: 1), Wizard::ActiveRecord_Relation)
48
- T.assert_type!(Wizard.preload(:spell_books), Wizard::ActiveRecord_Relation)
49
- T.assert_type!(Wizard.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
50
- T.assert_type!(Wizard.order(:id), Wizard::ActiveRecord_Relation)
51
-
52
32
  # Finder methods -- Model
53
33
  T.assert_type!(Wizard.exists?(name: 'Test'), T::Boolean)
54
34
  T.assert_type!(Wizard.find(wizard.id), Wizard)
@@ -83,6 +63,8 @@ Wizard.find_each { |w| T.assert_type!(w, Wizard) }
83
63
  T.assert_type!(Wizard.find_each, T::Enumerator[Wizard])
84
64
  Wizard.find_in_batches { |w| T.assert_type!(w, T::Array[Wizard]) }
85
65
  T.assert_type!(Wizard.find_in_batches, T::Enumerator[T::Array[Wizard]])
66
+ Wizard.in_batches { |w| T.assert_type!(w, Wizard::ActiveRecord_Relation) }
67
+ T.assert_type!(Wizard.in_batches, ActiveRecord::Batches::BatchEnumerator)
86
68
  # T.assert_type!(Wizard.destroy_all, T::Array[Wizard]) # Ignored until we add support
87
69
  T.assert_type!(Wizard.any?, T::Boolean)
88
70
  T.assert_type!(Wizard.many?, T::Boolean)
@@ -90,6 +72,18 @@ T.assert_type!(Wizard.none?, T::Boolean)
90
72
  T.assert_type!(Wizard.one?, T::Boolean)
91
73
  # T.assert_type!(Wizard.update_all(name: 'Harry Potter'), Integer) # Ignored until we add support
92
74
  # T.assert_type!(Wizard.delete_all, Integer) # Ignored until we add support
75
+ # Query methods
76
+ T.assert_type!(Wizard.all, Wizard::ActiveRecord_Relation)
77
+ T.assert_type!(Wizard.recent, Wizard::ActiveRecord_Relation) # Named scope
78
+ T.assert_type!(Wizard.Gryffindor, Wizard::ActiveRecord_Relation) # Enum scope
79
+ T.assert_type!(Wizard.Gryffindor.recent, Wizard::ActiveRecord_Relation)
80
+ T.assert_type!(Wizard.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
81
+ T.assert_type!(Wizard.where(id: 1), Wizard::ActiveRecord_Relation)
82
+ T.assert_type!(Wizard.where(id: 1).recent, Wizard::ActiveRecord_Relation)
83
+ T.assert_type!(Wizard.where.not(id: 1), Wizard::ActiveRecord_Relation)
84
+ T.assert_type!(Wizard.preload(:spell_books), Wizard::ActiveRecord_Relation)
85
+ T.assert_type!(Wizard.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
86
+ T.assert_type!(Wizard.order(:id), Wizard::ActiveRecord_Relation)
93
87
 
94
88
  # Finder methods -- ActiveRecord::Relation
95
89
  T.assert_type!(Wizard.all.exists?(name: 'Harry Potter'), T::Boolean)
@@ -126,6 +120,8 @@ Wizard.all.find_each { |w| T.assert_type!(w, Wizard) }
126
120
  T.assert_type!(Wizard.all.find_each, T::Enumerator[Wizard])
127
121
  Wizard.all.find_in_batches { |w| T.assert_type!(w, T::Array[Wizard]) }
128
122
  T.assert_type!(Wizard.all.find_in_batches, T::Enumerator[T::Array[Wizard]])
123
+ Wizard.all.in_batches { |w| T.assert_type!(w, Wizard::ActiveRecord_Relation) }
124
+ T.assert_type!(Wizard.all.in_batches, T::Enumerable[Wizard::ActiveRecord_Relation])
129
125
  # T.assert_type!(Wizard.all.destroy_all, T::Array[Wizard]) # Ignored until we add support
130
126
  T.assert_type!(Wizard.all.any?, T::Boolean)
131
127
  T.assert_type!(Wizard.all.many?, T::Boolean)
@@ -133,6 +129,18 @@ T.assert_type!(Wizard.all.none?, T::Boolean)
133
129
  T.assert_type!(Wizard.all.one?, T::Boolean)
134
130
  # T.assert_type!(Wizard.all.update_all(name: 'Harry Potter'), Integer) # Ignored until we add support
135
131
  # T.assert_type!(Wizard.all.delete_all, Integer) # Ignored until we add support
132
+ # Query methods
133
+ T.assert_type!(Wizard.all.all, Wizard::ActiveRecord_Relation)
134
+ T.assert_type!(Wizard.all.recent, Wizard::ActiveRecord_Relation) # Named scope
135
+ T.assert_type!(Wizard.all.Gryffindor, Wizard::ActiveRecord_Relation) # Enum scope
136
+ T.assert_type!(Wizard.all.Gryffindor.recent, Wizard::ActiveRecord_Relation)
137
+ T.assert_type!(Wizard.all.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
138
+ T.assert_type!(Wizard.all.where(id: 1), Wizard::ActiveRecord_Relation)
139
+ T.assert_type!(Wizard.all.where(id: 1).recent, Wizard::ActiveRecord_Relation)
140
+ T.assert_type!(Wizard.all.where.not(id: 1), Wizard::ActiveRecord_Relation)
141
+ T.assert_type!(Wizard.all.preload(:spell_books), Wizard::ActiveRecord_Relation)
142
+ T.assert_type!(Wizard.all.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
143
+ T.assert_type!(Wizard.all.order(:id), Wizard::ActiveRecord_Relation)
136
144
  # Enumerable methods
137
145
  Wizard.all.each { |w| T.assert_type!(w, Wizard) }
138
146
  Wizard.all.map { |w| T.assert_type!(w, Wizard) }
@@ -172,10 +180,12 @@ T.assert_type!(spell_books.create!(name: 'Fantastic Beasts') { |s| T.assert_type
172
180
  T.assert_type!(spell_books.first_or_create(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
173
181
  T.assert_type!(spell_books.first_or_create!(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
174
182
  T.assert_type!(spell_books.first_or_initialize { |s| T.assert_type!(s, SpellBook) }, SpellBook)
175
- # spell_books.find_each { |s| T.assert_type!(s, SpellBook) } # TODO: Handle for Rails 6
176
- # T.assert_type!(spell_books.find_each, T::Enumerator[SpellBook]) # TODO: Handle for Rails 6
177
- # spell_books.find_in_batches { |s| T.assert_type!(s, T::Array[SpellBook]) } # TODO: Handle for Rails 6
178
- # T.assert_type!(spell_books.find_in_batches, T::Enumerator[T::Array[SpellBook]]) # TODO: Handle for Rails 6
183
+ spell_books.find_each { |s| T.assert_type!(s, SpellBook) }
184
+ T.assert_type!(spell_books.find_each, T::Enumerator[SpellBook])
185
+ spell_books.find_in_batches { |s| T.assert_type!(s, T::Array[SpellBook]) }
186
+ T.assert_type!(spell_books.find_in_batches, T::Enumerator[T::Array[SpellBook]])
187
+ spell_books.in_batches { |s| T.assert_type!(s, SpellBook::ActiveRecord_AssociationRelation) }
188
+ T.assert_type!(spell_books.in_batches, T::Enumerable[SpellBook::ActiveRecord_AssociationRelation])
179
189
  # T.assert_type!(spell_books.destroy_all, T::Array[SpellBook]) # Ignored until we add support
180
190
  T.assert_type!(spell_books.any?, T::Boolean)
181
191
  T.assert_type!(spell_books.many?, T::Boolean)
@@ -183,13 +193,18 @@ T.assert_type!(spell_books.none?, T::Boolean)
183
193
  T.assert_type!(spell_books.one?, T::Boolean)
184
194
  # T.assert_type!(spell_books.update_all(name: 'Fantastic Beasts'), Integer) # Ignored until we add support
185
195
  # T.assert_type!(spell_books.delete_all, Integer) # Ignored until we add support
186
- # CollectionProxy query also typed correctly!
196
+ # Query methods
197
+ T.assert_type!(spell_books.all, SpellBook::ActiveRecord_AssociationRelation)
198
+ T.assert_type!(spell_books.recent, SpellBook::ActiveRecord_AssociationRelation) # Named scope
199
+ T.assert_type!(spell_books.unclassified, SpellBook::ActiveRecord_AssociationRelation) # Enum scope
200
+ T.assert_type!(spell_books.unclassified.recent, SpellBook::ActiveRecord_AssociationRelation)
201
+ T.assert_type!(spell_books.unclassified.recent.unscoped, SpellBook::ActiveRecord_Relation) # Turns back into relation
187
202
  T.assert_type!(spell_books.where(id: 1), SpellBook::ActiveRecord_AssociationRelation)
203
+ T.assert_type!(spell_books.where(id: 1).recent, SpellBook::ActiveRecord_AssociationRelation)
204
+ T.assert_type!(spell_books.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
188
205
  T.assert_type!(spell_books.preload(:wizard), SpellBook::ActiveRecord_AssociationRelation)
189
206
  T.assert_type!(spell_books.eager_load(:wizard), SpellBook::ActiveRecord_AssociationRelation)
190
207
  T.assert_type!(spell_books.order(:id), SpellBook::ActiveRecord_AssociationRelation)
191
- T.assert_type!(spell_books.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
192
- T.assert_type!(spell_books.biology, SpellBook::ActiveRecord_AssociationRelation)
193
208
  # Enumerable methods
194
209
  spell_books.each { |s| T.assert_type!(s, SpellBook) }
195
210
  spell_books.map { |s| T.assert_type!(s, SpellBook) }
@@ -237,10 +252,12 @@ T.assert_type!(spell_books_query.create!(name: 'Fantastic Beasts') { |s| T.asser
237
252
  T.assert_type!(spell_books_query.first_or_create(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook) # Ignored until we add support
238
253
  T.assert_type!(spell_books_query.first_or_create!(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook) # Ignored until we add support
239
254
  T.assert_type!(spell_books_query.first_or_initialize { |s| T.assert_type!(s, SpellBook) }, SpellBook) # Ignored until we add support
240
- # spell_books_query.find_each { |s| T.assert_type!(s, SpellBook) } # TODO: Handle for Rails 6
241
- # T.assert_type!(spell_books_query.find_each, T::Enumerator[SpellBook]) # TODO: Handle for Rails 6
242
- # spell_books_query.find_in_batches { |s| T.assert_type!(s, T::Array[SpellBook]) } # TODO: Handle for Rails 6
243
- # T.assert_type!(spell_books_query.find_in_batches, T::Enumerator[T::Array[SpellBook]]) # TODO: Handle for Rails 6
255
+ spell_books_query.find_each { |s| T.assert_type!(s, SpellBook) }
256
+ T.assert_type!(spell_books_query.find_each, T::Enumerator[SpellBook])
257
+ spell_books_query.find_in_batches { |s| T.assert_type!(s, T::Array[SpellBook]) }
258
+ T.assert_type!(spell_books_query.find_in_batches, T::Enumerator[T::Array[SpellBook]])
259
+ spell_books_query.in_batches { |s| T.assert_type!(s, SpellBook::ActiveRecord_AssociationRelation) }
260
+ T.assert_type!(spell_books_query.in_batches, T::Enumerable[SpellBook::ActiveRecord_AssociationRelation])
244
261
  # T.assert_type!(spell_books_query.destroy_all, T::Array[SpellBook]) # Ignored until we add support
245
262
  T.assert_type!(spell_books_query.any?, T::Boolean)
246
263
  T.assert_type!(spell_books_query.many?, T::Boolean)
@@ -248,12 +265,18 @@ T.assert_type!(spell_books_query.none?, T::Boolean)
248
265
  T.assert_type!(spell_books_query.one?, T::Boolean)
249
266
  # T.assert_type!(spell_books_query.update_all(name: 'Fantastic Beasts'), Integer) # Ignored until we add support
250
267
  # T.assert_type!(spell_books_query.delete_all, Integer) # Ignored until we add support
251
- # Query chaining
268
+ # Query methods
269
+ T.assert_type!(spell_books_query.all, SpellBook::ActiveRecord_AssociationRelation)
270
+ T.assert_type!(spell_books_query.recent, SpellBook::ActiveRecord_AssociationRelation) # Named scope
271
+ T.assert_type!(spell_books_query.unclassified, SpellBook::ActiveRecord_AssociationRelation) # Enum scope
272
+ T.assert_type!(spell_books_query.unclassified.recent, SpellBook::ActiveRecord_AssociationRelation)
273
+ T.assert_type!(spell_books_query.unclassified.recent.unscoped, SpellBook::ActiveRecord_Relation) # Turns back into relation
274
+ T.assert_type!(spell_books_query.where(id: 1), SpellBook::ActiveRecord_AssociationRelation)
275
+ T.assert_type!(spell_books_query.where(id: 1).recent, SpellBook::ActiveRecord_AssociationRelation)
276
+ T.assert_type!(spell_books_query.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
252
277
  T.assert_type!(spell_books_query.preload(:wizard), SpellBook::ActiveRecord_AssociationRelation)
253
278
  T.assert_type!(spell_books_query.eager_load(:wizard), SpellBook::ActiveRecord_AssociationRelation)
254
279
  T.assert_type!(spell_books_query.order(:id), SpellBook::ActiveRecord_AssociationRelation)
255
- T.assert_type!(spell_books_query.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
256
- T.assert_type!(spell_books_query.biology, SpellBook::ActiveRecord_AssociationRelation)
257
280
  # Enumerable methods
258
281
  spell_books_query.each { |s| T.assert_type!(s, SpellBook) }
259
282
  spell_books_query.map { |s| T.assert_type!(s, SpellBook) }
@@ -338,44 +361,6 @@ params = ActionController::Parameters.new({
338
361
  typed_params = TypedParams[MyActionParams].new.extract!(params)
339
362
  T.assert_type!(typed_params, MyActionParams)
340
363
 
341
- # -- require_typed
342
- T.assert_type!(
343
- params.require_typed(:age, TA[Integer].new),
344
- Integer,
345
- )
346
- T.assert_type!(
347
- params.require_typed(:name, TA[String].new),
348
- String,
349
- )
350
- info = params.require_typed(:info, TA[ActionController::Parameters].new)
351
- T.assert_type!(info, ActionController::Parameters)
352
- T.assert_type!(
353
- info.require_typed(:friends, TA[T::Array[String]].new),
354
- T::Array[String],
355
- )
356
- # -- fetch_typed
357
- T.assert_type!(
358
- params.fetch_typed(:age, TA[Integer].new),
359
- Integer,
360
- )
361
- T.assert_type!(
362
- params.fetch_typed(:name, TA[String].new),
363
- String,
364
- )
365
- T.assert_type!(
366
- params.fetch_typed(:nonexistence, TA[String].new, ''),
367
- String,
368
- )
369
- T.assert_type!(
370
- params.fetch_typed(:nonexistence, TA[T.nilable(String)].new, nil),
371
- T.nilable(String),
372
- )
373
- T.assert_type!(
374
- params.fetch_typed(:nonexistence, TA[T::Array[Integer]].new, []),
375
- T::Array[Integer],
376
- )
377
-
378
-
379
364
  # -- pluck to tstruct
380
365
  class WizardStruct < T::Struct
381
366
  const :name, String
@@ -392,23 +377,16 @@ Wizard.all.pluck_to_tstruct(TA[WizardStruct].new).each do |row|
392
377
  T.assert_type!(row, WizardStruct)
393
378
  end
394
379
 
395
-
396
380
  # -- GeneratedUrlHelpers
397
381
  class TestHelper
398
382
  include GeneratedUrlHelpers
399
-
400
- # need to implement this for the url
401
- def default_url_options
402
- {
403
- protocol: 'http',
404
- host: 'localhost',
405
- port: 3000,
406
- }
407
- end
408
-
409
- def test_url_helper
410
- T.assert_type!(test_index_path, String)
411
- T.assert_type!(test_index_url, String)
412
- end
413
383
  end
414
- TestHelper.new.test_url_helper
384
+
385
+ T.assert_type!(TestHelper.new.test_index_path, String)
386
+ # need to set this config for _url methods
387
+ Rails.application.routes.default_url_options = {
388
+ protocol: 'http',
389
+ host: 'localhost',
390
+ port: 3000,
391
+ }
392
+ T.assert_type!(TestHelper.new.test_index_url, String)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- sorbet-rails (0.6.3)
4
+ sorbet-rails (0.7.1)
5
5
  method_source (>= 0.9.2)
6
6
  parlour (~> 2.0)
7
7
  parser (>= 2.7)
@@ -49,7 +49,7 @@ GEM
49
49
  minitest (~> 5.1)
50
50
  tzinfo (~> 1.1)
51
51
  arel (8.0.0)
52
- ast (2.4.0)
52
+ ast (2.4.1)
53
53
  bindex (0.8.1)
54
54
  builder (3.2.4)
55
55
  byebug (11.1.1)
@@ -82,11 +82,11 @@ GEM
82
82
  parser
83
83
  rainbow (~> 3.0)
84
84
  sorbet-runtime (>= 0.5)
85
- parser (2.7.1.1)
86
- ast (~> 2.4.0)
85
+ parser (2.7.1.4)
86
+ ast (~> 2.4.1)
87
87
  polyfill (1.8.0)
88
88
  puma (3.12.4)
89
- rack (2.2.2)
89
+ rack (2.2.3)
90
90
  rack-test (1.1.0)
91
91
  rack (>= 1.0, < 3)
92
92
  rails (5.1.7)
@@ -117,7 +117,7 @@ GEM
117
117
  safe_type (1.1.1)
118
118
  sorbet (0.5.5480)
119
119
  sorbet-static (= 0.5.5480)
120
- sorbet-coerce (0.2.6)
120
+ sorbet-coerce (0.2.7)
121
121
  polyfill (~> 1.8)
122
122
  safe_type (~> 1.1, >= 1.1.1)
123
123
  sorbet (>= 0.4.4704)
@@ -143,7 +143,7 @@ GEM
143
143
  railties (>= 5.0)
144
144
  websocket-driver (0.6.5)
145
145
  websocket-extensions (>= 0.1.0)
146
- websocket-extensions (0.1.4)
146
+ websocket-extensions (0.1.5)
147
147
 
148
148
  PLATFORMS
149
149
  ruby