sorbet-rails 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/sorbet-rails/gem_plugins/active_flag_plugin.rb +0 -1
  4. data/lib/sorbet-rails/gem_plugins/paperclip_plugin.rb +0 -1
  5. data/lib/sorbet-rails/model_plugins/active_record_assoc.rb +9 -2
  6. data/lib/sorbet-rails/model_plugins/active_record_attribute.rb +0 -1
  7. data/lib/sorbet-rails/model_plugins/active_record_enum.rb +0 -1
  8. data/lib/sorbet-rails/model_plugins/active_record_named_scope.rb +15 -6
  9. data/lib/sorbet-rails/model_plugins/active_record_querying.rb +5 -1
  10. data/lib/sorbet-rails/model_plugins/base.rb +2 -1
  11. data/lib/sorbet-rails/model_rbi_formatter.rb +4 -8
  12. data/lib/sorbet-rails/model_utils.rb +68 -30
  13. data/lib/sorbet-rails/tasks/rails_rbi.rake +13 -21
  14. data/sorbet-rails.gemspec +1 -1
  15. data/spec/generators/rails-template.rb +3 -6
  16. data/spec/generators/sorbet_test_cases.rb +41 -26
  17. data/spec/support/v5.0/Gemfile.lock +2 -2
  18. data/spec/support/v5.0/app/models/spell_book.rb +2 -0
  19. data/spec/support/v5.0/app/models/wizard.rb +1 -1
  20. data/spec/support/v5.0/sorbet_test_cases.rb +41 -26
  21. data/spec/support/v5.1/Gemfile.lock +2 -2
  22. data/spec/support/v5.1/app/models/spell_book.rb +2 -0
  23. data/spec/support/v5.1/app/models/wizard.rb +1 -1
  24. data/spec/support/v5.1/sorbet_test_cases.rb +41 -26
  25. data/spec/support/v5.2/Gemfile.lock +2 -2
  26. data/spec/support/v5.2/app/models/spell_book.rb +2 -0
  27. data/spec/support/v5.2/app/models/wizard.rb +1 -1
  28. data/spec/support/v5.2/sorbet_test_cases.rb +41 -26
  29. data/spec/support/v6.0/Gemfile.lock +2 -2
  30. data/spec/support/v6.0/app/models/spell_book.rb +2 -0
  31. data/spec/support/v6.0/app/models/wizard.rb +1 -1
  32. data/spec/support/v6.0/sorbet_test_cases.rb +41 -26
  33. data/spec/test_data/v5.0/expected_headmaster.rbi +18 -190
  34. data/spec/test_data/v5.0/expected_internal_metadata.rbi +18 -188
  35. data/spec/test_data/v5.0/expected_potion.rbi +18 -188
  36. data/spec/test_data/v5.0/expected_robe.rbi +18 -190
  37. data/spec/test_data/v5.0/expected_schema_migration.rbi +18 -188
  38. data/spec/test_data/v5.0/expected_school.rbi +18 -190
  39. data/spec/test_data/v5.0/expected_spell.rbi +18 -190
  40. data/spec/test_data/v5.0/expected_spell/habtm_spell_books.rbi +18 -190
  41. data/spec/test_data/v5.0/expected_spell_book.rbi +55 -217
  42. data/spec/test_data/v5.0/expected_spell_book/habtm_spells.rbi +18 -190
  43. data/spec/test_data/v5.0/expected_squib.rbi +90 -264
  44. data/spec/test_data/v5.0/expected_subject.rbi +18 -190
  45. data/spec/test_data/v5.0/expected_subject/habtm_wizards.rbi +18 -190
  46. data/spec/test_data/v5.0/expected_wand.rbi +53 -227
  47. data/spec/test_data/v5.0/expected_wizard.rbi +90 -264
  48. data/spec/test_data/v5.0/expected_wizard/habtm_subjects.rbi +18 -190
  49. data/spec/test_data/v5.0/expected_wizard_wo_spellbook.rbi +90 -264
  50. data/spec/test_data/v5.1/expected_headmaster.rbi +18 -196
  51. data/spec/test_data/v5.1/expected_internal_metadata.rbi +18 -194
  52. data/spec/test_data/v5.1/expected_potion.rbi +18 -194
  53. data/spec/test_data/v5.1/expected_robe.rbi +18 -196
  54. data/spec/test_data/v5.1/expected_schema_migration.rbi +18 -194
  55. data/spec/test_data/v5.1/expected_school.rbi +18 -196
  56. data/spec/test_data/v5.1/expected_spell.rbi +18 -196
  57. data/spec/test_data/v5.1/expected_spell/habtm_spell_books.rbi +18 -196
  58. data/spec/test_data/v5.1/expected_spell_book.rbi +55 -223
  59. data/spec/test_data/v5.1/expected_spell_book/habtm_spells.rbi +18 -196
  60. data/spec/test_data/v5.1/expected_squib.rbi +91 -271
  61. data/spec/test_data/v5.1/expected_subject.rbi +18 -196
  62. data/spec/test_data/v5.1/expected_subject/habtm_wizards.rbi +18 -196
  63. data/spec/test_data/v5.1/expected_wand.rbi +53 -233
  64. data/spec/test_data/v5.1/expected_wizard.rbi +91 -271
  65. data/spec/test_data/v5.1/expected_wizard/habtm_subjects.rbi +18 -196
  66. data/spec/test_data/v5.1/expected_wizard_wo_spellbook.rbi +91 -271
  67. data/spec/test_data/v5.2/expected_attachment.rbi +18 -194
  68. data/spec/test_data/v5.2/expected_blob.rbi +39 -215
  69. data/spec/test_data/v5.2/expected_headmaster.rbi +18 -196
  70. data/spec/test_data/v5.2/expected_internal_metadata.rbi +18 -194
  71. data/spec/test_data/v5.2/expected_potion.rbi +18 -194
  72. data/spec/test_data/v5.2/expected_robe.rbi +18 -196
  73. data/spec/test_data/v5.2/expected_schema_migration.rbi +18 -194
  74. data/spec/test_data/v5.2/expected_school.rbi +18 -196
  75. data/spec/test_data/v5.2/expected_spell.rbi +18 -196
  76. data/spec/test_data/v5.2/expected_spell/habtm_spell_books.rbi +18 -196
  77. data/spec/test_data/v5.2/expected_spell_book.rbi +55 -223
  78. data/spec/test_data/v5.2/expected_spell_book/habtm_spells.rbi +18 -196
  79. data/spec/test_data/v5.2/expected_squib.rbi +95 -275
  80. data/spec/test_data/v5.2/expected_subject.rbi +18 -196
  81. data/spec/test_data/v5.2/expected_subject/habtm_wizards.rbi +18 -196
  82. data/spec/test_data/v5.2/expected_wand.rbi +53 -233
  83. data/spec/test_data/v5.2/expected_wizard.rbi +95 -275
  84. data/spec/test_data/v5.2/expected_wizard/habtm_subjects.rbi +18 -196
  85. data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +95 -275
  86. data/spec/test_data/v6.0/expected_attachment.rbi +18 -218
  87. data/spec/test_data/v6.0/expected_blob.rbi +31 -243
  88. data/spec/test_data/v6.0/expected_headmaster.rbi +18 -220
  89. data/spec/test_data/v6.0/expected_internal_metadata.rbi +18 -218
  90. data/spec/test_data/v6.0/expected_potion.rbi +18 -218
  91. data/spec/test_data/v6.0/expected_robe.rbi +18 -220
  92. data/spec/test_data/v6.0/expected_schema_migration.rbi +18 -218
  93. data/spec/test_data/v6.0/expected_school.rbi +18 -220
  94. data/spec/test_data/v6.0/expected_spell.rbi +18 -220
  95. data/spec/test_data/v6.0/expected_spell/habtm_spell_books.rbi +18 -220
  96. data/spec/test_data/v6.0/expected_spell_book.rbi +24 -258
  97. data/spec/test_data/v6.0/expected_spell_book/habtm_spells.rbi +18 -220
  98. data/spec/test_data/v6.0/expected_squib.rbi +31 -457
  99. data/spec/test_data/v6.0/expected_subject.rbi +18 -220
  100. data/spec/test_data/v6.0/expected_subject/habtm_wizards.rbi +18 -220
  101. data/spec/test_data/v6.0/expected_wand.rbi +18 -270
  102. data/spec/test_data/v6.0/expected_wizard.rbi +31 -457
  103. data/spec/test_data/v6.0/expected_wizard/habtm_subjects.rbi +18 -220
  104. data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +31 -457
  105. metadata +1 -1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- sorbet-rails (0.6.3)
4
+ sorbet-rails (0.6.4)
5
5
  method_source (>= 0.9.2)
6
6
  parlour (~> 2.0)
7
7
  parser (>= 2.7)
@@ -81,7 +81,7 @@ GEM
81
81
  parser
82
82
  rainbow (~> 3.0)
83
83
  sorbet-runtime (>= 0.5)
84
- parser (2.7.1.1)
84
+ parser (2.7.1.2)
85
85
  ast (~> 2.4.0)
86
86
  polyfill (1.8.0)
87
87
  puma (3.12.4)
@@ -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)
@@ -90,6 +70,18 @@ T.assert_type!(Wizard.none?, T::Boolean)
90
70
  T.assert_type!(Wizard.one?, T::Boolean)
91
71
  # T.assert_type!(Wizard.update_all(name: 'Harry Potter'), Integer) # Ignored until we add support
92
72
  # T.assert_type!(Wizard.delete_all, Integer) # Ignored until we add support
73
+ # Query methods
74
+ T.assert_type!(Wizard.all, Wizard::ActiveRecord_Relation)
75
+ T.assert_type!(Wizard.recent, Wizard::ActiveRecord_Relation) # Named scope
76
+ T.assert_type!(Wizard.Gryffindor, Wizard::ActiveRecord_Relation) # Enum scope
77
+ T.assert_type!(Wizard.Gryffindor.recent, Wizard::ActiveRecord_Relation)
78
+ T.assert_type!(Wizard.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
79
+ T.assert_type!(Wizard.where(id: 1), Wizard::ActiveRecord_Relation)
80
+ T.assert_type!(Wizard.where(id: 1).recent, Wizard::ActiveRecord_Relation)
81
+ T.assert_type!(Wizard.where.not(id: 1), Wizard::ActiveRecord_Relation)
82
+ T.assert_type!(Wizard.preload(:spell_books), Wizard::ActiveRecord_Relation)
83
+ T.assert_type!(Wizard.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
84
+ T.assert_type!(Wizard.order(:id), Wizard::ActiveRecord_Relation)
93
85
 
94
86
  # Finder methods -- ActiveRecord::Relation
95
87
  T.assert_type!(Wizard.all.exists?(name: 'Harry Potter'), T::Boolean)
@@ -133,6 +125,18 @@ T.assert_type!(Wizard.all.none?, T::Boolean)
133
125
  T.assert_type!(Wizard.all.one?, T::Boolean)
134
126
  # T.assert_type!(Wizard.all.update_all(name: 'Harry Potter'), Integer) # Ignored until we add support
135
127
  # T.assert_type!(Wizard.all.delete_all, Integer) # Ignored until we add support
128
+ # Query methods
129
+ T.assert_type!(Wizard.all.all, Wizard::ActiveRecord_Relation)
130
+ T.assert_type!(Wizard.all.recent, Wizard::ActiveRecord_Relation) # Named scope
131
+ T.assert_type!(Wizard.all.Gryffindor, Wizard::ActiveRecord_Relation) # Enum scope
132
+ T.assert_type!(Wizard.all.Gryffindor.recent, Wizard::ActiveRecord_Relation)
133
+ T.assert_type!(Wizard.all.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
134
+ T.assert_type!(Wizard.all.where(id: 1), Wizard::ActiveRecord_Relation)
135
+ T.assert_type!(Wizard.all.where(id: 1).recent, Wizard::ActiveRecord_Relation)
136
+ T.assert_type!(Wizard.all.where.not(id: 1), Wizard::ActiveRecord_Relation)
137
+ T.assert_type!(Wizard.all.preload(:spell_books), Wizard::ActiveRecord_Relation)
138
+ T.assert_type!(Wizard.all.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
139
+ T.assert_type!(Wizard.all.order(:id), Wizard::ActiveRecord_Relation)
136
140
  # Enumerable methods
137
141
  Wizard.all.each { |w| T.assert_type!(w, Wizard) }
138
142
  Wizard.all.map { |w| T.assert_type!(w, Wizard) }
@@ -183,13 +187,18 @@ T.assert_type!(spell_books.none?, T::Boolean)
183
187
  T.assert_type!(spell_books.one?, T::Boolean)
184
188
  # T.assert_type!(spell_books.update_all(name: 'Fantastic Beasts'), Integer) # Ignored until we add support
185
189
  # T.assert_type!(spell_books.delete_all, Integer) # Ignored until we add support
186
- # CollectionProxy query also typed correctly!
190
+ # Query methods
191
+ T.assert_type!(spell_books.all, SpellBook::ActiveRecord_AssociationRelation)
192
+ T.assert_type!(spell_books.recent, SpellBook::ActiveRecord_AssociationRelation) # Named scope
193
+ T.assert_type!(spell_books.unclassified, SpellBook::ActiveRecord_AssociationRelation) # Enum scope
194
+ T.assert_type!(spell_books.unclassified.recent, SpellBook::ActiveRecord_AssociationRelation)
195
+ T.assert_type!(spell_books.unclassified.recent.unscoped, SpellBook::ActiveRecord_Relation) # Turns back into relation
187
196
  T.assert_type!(spell_books.where(id: 1), SpellBook::ActiveRecord_AssociationRelation)
197
+ T.assert_type!(spell_books.where(id: 1).recent, SpellBook::ActiveRecord_AssociationRelation)
198
+ T.assert_type!(spell_books.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
188
199
  T.assert_type!(spell_books.preload(:wizard), SpellBook::ActiveRecord_AssociationRelation)
189
200
  T.assert_type!(spell_books.eager_load(:wizard), SpellBook::ActiveRecord_AssociationRelation)
190
201
  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
202
  # Enumerable methods
194
203
  spell_books.each { |s| T.assert_type!(s, SpellBook) }
195
204
  spell_books.map { |s| T.assert_type!(s, SpellBook) }
@@ -248,12 +257,18 @@ T.assert_type!(spell_books_query.none?, T::Boolean)
248
257
  T.assert_type!(spell_books_query.one?, T::Boolean)
249
258
  # T.assert_type!(spell_books_query.update_all(name: 'Fantastic Beasts'), Integer) # Ignored until we add support
250
259
  # T.assert_type!(spell_books_query.delete_all, Integer) # Ignored until we add support
251
- # Query chaining
260
+ # Query methods
261
+ T.assert_type!(spell_books_query.all, SpellBook::ActiveRecord_AssociationRelation)
262
+ T.assert_type!(spell_books_query.recent, SpellBook::ActiveRecord_AssociationRelation) # Named scope
263
+ T.assert_type!(spell_books_query.unclassified, SpellBook::ActiveRecord_AssociationRelation) # Enum scope
264
+ T.assert_type!(spell_books_query.unclassified.recent, SpellBook::ActiveRecord_AssociationRelation)
265
+ T.assert_type!(spell_books_query.unclassified.recent.unscoped, SpellBook::ActiveRecord_Relation) # Turns back into relation
266
+ T.assert_type!(spell_books_query.where(id: 1), SpellBook::ActiveRecord_AssociationRelation)
267
+ T.assert_type!(spell_books_query.where(id: 1).recent, SpellBook::ActiveRecord_AssociationRelation)
268
+ T.assert_type!(spell_books_query.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
252
269
  T.assert_type!(spell_books_query.preload(:wizard), SpellBook::ActiveRecord_AssociationRelation)
253
270
  T.assert_type!(spell_books_query.eager_load(:wizard), SpellBook::ActiveRecord_AssociationRelation)
254
271
  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
272
  # Enumerable methods
258
273
  spell_books_query.each { |s| T.assert_type!(s, SpellBook) }
259
274
  spell_books_query.map { |s| T.assert_type!(s, SpellBook) }
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- sorbet-rails (0.6.3)
4
+ sorbet-rails (0.6.4)
5
5
  method_source (>= 0.9.2)
6
6
  parlour (~> 2.0)
7
7
  parser (>= 2.7)
@@ -82,7 +82,7 @@ GEM
82
82
  parser
83
83
  rainbow (~> 3.0)
84
84
  sorbet-runtime (>= 0.5)
85
- parser (2.7.1.1)
85
+ parser (2.7.1.2)
86
86
  ast (~> 2.4.0)
87
87
  polyfill (1.8.0)
88
88
  puma (3.12.4)
@@ -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)
@@ -90,6 +70,18 @@ T.assert_type!(Wizard.none?, T::Boolean)
90
70
  T.assert_type!(Wizard.one?, T::Boolean)
91
71
  # T.assert_type!(Wizard.update_all(name: 'Harry Potter'), Integer) # Ignored until we add support
92
72
  # T.assert_type!(Wizard.delete_all, Integer) # Ignored until we add support
73
+ # Query methods
74
+ T.assert_type!(Wizard.all, Wizard::ActiveRecord_Relation)
75
+ T.assert_type!(Wizard.recent, Wizard::ActiveRecord_Relation) # Named scope
76
+ T.assert_type!(Wizard.Gryffindor, Wizard::ActiveRecord_Relation) # Enum scope
77
+ T.assert_type!(Wizard.Gryffindor.recent, Wizard::ActiveRecord_Relation)
78
+ T.assert_type!(Wizard.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
79
+ T.assert_type!(Wizard.where(id: 1), Wizard::ActiveRecord_Relation)
80
+ T.assert_type!(Wizard.where(id: 1).recent, Wizard::ActiveRecord_Relation)
81
+ T.assert_type!(Wizard.where.not(id: 1), Wizard::ActiveRecord_Relation)
82
+ T.assert_type!(Wizard.preload(:spell_books), Wizard::ActiveRecord_Relation)
83
+ T.assert_type!(Wizard.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
84
+ T.assert_type!(Wizard.order(:id), Wizard::ActiveRecord_Relation)
93
85
 
94
86
  # Finder methods -- ActiveRecord::Relation
95
87
  T.assert_type!(Wizard.all.exists?(name: 'Harry Potter'), T::Boolean)
@@ -133,6 +125,18 @@ T.assert_type!(Wizard.all.none?, T::Boolean)
133
125
  T.assert_type!(Wizard.all.one?, T::Boolean)
134
126
  # T.assert_type!(Wizard.all.update_all(name: 'Harry Potter'), Integer) # Ignored until we add support
135
127
  # T.assert_type!(Wizard.all.delete_all, Integer) # Ignored until we add support
128
+ # Query methods
129
+ T.assert_type!(Wizard.all.all, Wizard::ActiveRecord_Relation)
130
+ T.assert_type!(Wizard.all.recent, Wizard::ActiveRecord_Relation) # Named scope
131
+ T.assert_type!(Wizard.all.Gryffindor, Wizard::ActiveRecord_Relation) # Enum scope
132
+ T.assert_type!(Wizard.all.Gryffindor.recent, Wizard::ActiveRecord_Relation)
133
+ T.assert_type!(Wizard.all.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
134
+ T.assert_type!(Wizard.all.where(id: 1), Wizard::ActiveRecord_Relation)
135
+ T.assert_type!(Wizard.all.where(id: 1).recent, Wizard::ActiveRecord_Relation)
136
+ T.assert_type!(Wizard.all.where.not(id: 1), Wizard::ActiveRecord_Relation)
137
+ T.assert_type!(Wizard.all.preload(:spell_books), Wizard::ActiveRecord_Relation)
138
+ T.assert_type!(Wizard.all.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
139
+ T.assert_type!(Wizard.all.order(:id), Wizard::ActiveRecord_Relation)
136
140
  # Enumerable methods
137
141
  Wizard.all.each { |w| T.assert_type!(w, Wizard) }
138
142
  Wizard.all.map { |w| T.assert_type!(w, Wizard) }
@@ -183,13 +187,18 @@ T.assert_type!(spell_books.none?, T::Boolean)
183
187
  T.assert_type!(spell_books.one?, T::Boolean)
184
188
  # T.assert_type!(spell_books.update_all(name: 'Fantastic Beasts'), Integer) # Ignored until we add support
185
189
  # T.assert_type!(spell_books.delete_all, Integer) # Ignored until we add support
186
- # CollectionProxy query also typed correctly!
190
+ # Query methods
191
+ T.assert_type!(spell_books.all, SpellBook::ActiveRecord_AssociationRelation)
192
+ T.assert_type!(spell_books.recent, SpellBook::ActiveRecord_AssociationRelation) # Named scope
193
+ T.assert_type!(spell_books.unclassified, SpellBook::ActiveRecord_AssociationRelation) # Enum scope
194
+ T.assert_type!(spell_books.unclassified.recent, SpellBook::ActiveRecord_AssociationRelation)
195
+ T.assert_type!(spell_books.unclassified.recent.unscoped, SpellBook::ActiveRecord_Relation) # Turns back into relation
187
196
  T.assert_type!(spell_books.where(id: 1), SpellBook::ActiveRecord_AssociationRelation)
197
+ T.assert_type!(spell_books.where(id: 1).recent, SpellBook::ActiveRecord_AssociationRelation)
198
+ T.assert_type!(spell_books.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
188
199
  T.assert_type!(spell_books.preload(:wizard), SpellBook::ActiveRecord_AssociationRelation)
189
200
  T.assert_type!(spell_books.eager_load(:wizard), SpellBook::ActiveRecord_AssociationRelation)
190
201
  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
202
  # Enumerable methods
194
203
  spell_books.each { |s| T.assert_type!(s, SpellBook) }
195
204
  spell_books.map { |s| T.assert_type!(s, SpellBook) }
@@ -248,12 +257,18 @@ T.assert_type!(spell_books_query.none?, T::Boolean)
248
257
  T.assert_type!(spell_books_query.one?, T::Boolean)
249
258
  # T.assert_type!(spell_books_query.update_all(name: 'Fantastic Beasts'), Integer) # Ignored until we add support
250
259
  # T.assert_type!(spell_books_query.delete_all, Integer) # Ignored until we add support
251
- # Query chaining
260
+ # Query methods
261
+ T.assert_type!(spell_books_query.all, SpellBook::ActiveRecord_AssociationRelation)
262
+ T.assert_type!(spell_books_query.recent, SpellBook::ActiveRecord_AssociationRelation) # Named scope
263
+ T.assert_type!(spell_books_query.unclassified, SpellBook::ActiveRecord_AssociationRelation) # Enum scope
264
+ T.assert_type!(spell_books_query.unclassified.recent, SpellBook::ActiveRecord_AssociationRelation)
265
+ T.assert_type!(spell_books_query.unclassified.recent.unscoped, SpellBook::ActiveRecord_Relation) # Turns back into relation
266
+ T.assert_type!(spell_books_query.where(id: 1), SpellBook::ActiveRecord_AssociationRelation)
267
+ T.assert_type!(spell_books_query.where(id: 1).recent, SpellBook::ActiveRecord_AssociationRelation)
268
+ T.assert_type!(spell_books_query.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
252
269
  T.assert_type!(spell_books_query.preload(:wizard), SpellBook::ActiveRecord_AssociationRelation)
253
270
  T.assert_type!(spell_books_query.eager_load(:wizard), SpellBook::ActiveRecord_AssociationRelation)
254
271
  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
272
  # Enumerable methods
258
273
  spell_books_query.each { |s| T.assert_type!(s, SpellBook) }
259
274
  spell_books_query.map { |s| T.assert_type!(s, SpellBook) }
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- sorbet-rails (0.6.3)
4
+ sorbet-rails (0.6.4)
5
5
  method_source (>= 0.9.2)
6
6
  parlour (~> 2.0)
7
7
  parser (>= 2.7)
@@ -89,7 +89,7 @@ GEM
89
89
  parser
90
90
  rainbow (~> 3.0)
91
91
  sorbet-runtime (>= 0.5)
92
- parser (2.7.1.1)
92
+ parser (2.7.1.2)
93
93
  ast (~> 2.4.0)
94
94
  polyfill (1.8.0)
95
95
  puma (3.12.4)
@@ -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)
@@ -90,6 +70,18 @@ T.assert_type!(Wizard.none?, T::Boolean)
90
70
  T.assert_type!(Wizard.one?, T::Boolean)
91
71
  # T.assert_type!(Wizard.update_all(name: 'Harry Potter'), Integer) # Ignored until we add support
92
72
  # T.assert_type!(Wizard.delete_all, Integer) # Ignored until we add support
73
+ # Query methods
74
+ T.assert_type!(Wizard.all, Wizard::ActiveRecord_Relation)
75
+ T.assert_type!(Wizard.recent, Wizard::ActiveRecord_Relation) # Named scope
76
+ T.assert_type!(Wizard.Gryffindor, Wizard::ActiveRecord_Relation) # Enum scope
77
+ T.assert_type!(Wizard.Gryffindor.recent, Wizard::ActiveRecord_Relation)
78
+ T.assert_type!(Wizard.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
79
+ T.assert_type!(Wizard.where(id: 1), Wizard::ActiveRecord_Relation)
80
+ T.assert_type!(Wizard.where(id: 1).recent, Wizard::ActiveRecord_Relation)
81
+ T.assert_type!(Wizard.where.not(id: 1), Wizard::ActiveRecord_Relation)
82
+ T.assert_type!(Wizard.preload(:spell_books), Wizard::ActiveRecord_Relation)
83
+ T.assert_type!(Wizard.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
84
+ T.assert_type!(Wizard.order(:id), Wizard::ActiveRecord_Relation)
93
85
 
94
86
  # Finder methods -- ActiveRecord::Relation
95
87
  T.assert_type!(Wizard.all.exists?(name: 'Harry Potter'), T::Boolean)
@@ -133,6 +125,18 @@ T.assert_type!(Wizard.all.none?, T::Boolean)
133
125
  T.assert_type!(Wizard.all.one?, T::Boolean)
134
126
  # T.assert_type!(Wizard.all.update_all(name: 'Harry Potter'), Integer) # Ignored until we add support
135
127
  # T.assert_type!(Wizard.all.delete_all, Integer) # Ignored until we add support
128
+ # Query methods
129
+ T.assert_type!(Wizard.all.all, Wizard::ActiveRecord_Relation)
130
+ T.assert_type!(Wizard.all.recent, Wizard::ActiveRecord_Relation) # Named scope
131
+ T.assert_type!(Wizard.all.Gryffindor, Wizard::ActiveRecord_Relation) # Enum scope
132
+ T.assert_type!(Wizard.all.Gryffindor.recent, Wizard::ActiveRecord_Relation)
133
+ T.assert_type!(Wizard.all.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
134
+ T.assert_type!(Wizard.all.where(id: 1), Wizard::ActiveRecord_Relation)
135
+ T.assert_type!(Wizard.all.where(id: 1).recent, Wizard::ActiveRecord_Relation)
136
+ T.assert_type!(Wizard.all.where.not(id: 1), Wizard::ActiveRecord_Relation)
137
+ T.assert_type!(Wizard.all.preload(:spell_books), Wizard::ActiveRecord_Relation)
138
+ T.assert_type!(Wizard.all.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
139
+ T.assert_type!(Wizard.all.order(:id), Wizard::ActiveRecord_Relation)
136
140
  # Enumerable methods
137
141
  Wizard.all.each { |w| T.assert_type!(w, Wizard) }
138
142
  Wizard.all.map { |w| T.assert_type!(w, Wizard) }
@@ -183,13 +187,18 @@ T.assert_type!(spell_books.none?, T::Boolean)
183
187
  T.assert_type!(spell_books.one?, T::Boolean)
184
188
  # T.assert_type!(spell_books.update_all(name: 'Fantastic Beasts'), Integer) # Ignored until we add support
185
189
  # T.assert_type!(spell_books.delete_all, Integer) # Ignored until we add support
186
- # CollectionProxy query also typed correctly!
190
+ # Query methods
191
+ T.assert_type!(spell_books.all, SpellBook::ActiveRecord_AssociationRelation)
192
+ T.assert_type!(spell_books.recent, SpellBook::ActiveRecord_AssociationRelation) # Named scope
193
+ T.assert_type!(spell_books.unclassified, SpellBook::ActiveRecord_AssociationRelation) # Enum scope
194
+ T.assert_type!(spell_books.unclassified.recent, SpellBook::ActiveRecord_AssociationRelation)
195
+ T.assert_type!(spell_books.unclassified.recent.unscoped, SpellBook::ActiveRecord_Relation) # Turns back into relation
187
196
  T.assert_type!(spell_books.where(id: 1), SpellBook::ActiveRecord_AssociationRelation)
197
+ T.assert_type!(spell_books.where(id: 1).recent, SpellBook::ActiveRecord_AssociationRelation)
198
+ T.assert_type!(spell_books.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
188
199
  T.assert_type!(spell_books.preload(:wizard), SpellBook::ActiveRecord_AssociationRelation)
189
200
  T.assert_type!(spell_books.eager_load(:wizard), SpellBook::ActiveRecord_AssociationRelation)
190
201
  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
202
  # Enumerable methods
194
203
  spell_books.each { |s| T.assert_type!(s, SpellBook) }
195
204
  spell_books.map { |s| T.assert_type!(s, SpellBook) }
@@ -248,12 +257,18 @@ T.assert_type!(spell_books_query.none?, T::Boolean)
248
257
  T.assert_type!(spell_books_query.one?, T::Boolean)
249
258
  # T.assert_type!(spell_books_query.update_all(name: 'Fantastic Beasts'), Integer) # Ignored until we add support
250
259
  # T.assert_type!(spell_books_query.delete_all, Integer) # Ignored until we add support
251
- # Query chaining
260
+ # Query methods
261
+ T.assert_type!(spell_books_query.all, SpellBook::ActiveRecord_AssociationRelation)
262
+ T.assert_type!(spell_books_query.recent, SpellBook::ActiveRecord_AssociationRelation) # Named scope
263
+ T.assert_type!(spell_books_query.unclassified, SpellBook::ActiveRecord_AssociationRelation) # Enum scope
264
+ T.assert_type!(spell_books_query.unclassified.recent, SpellBook::ActiveRecord_AssociationRelation)
265
+ T.assert_type!(spell_books_query.unclassified.recent.unscoped, SpellBook::ActiveRecord_Relation) # Turns back into relation
266
+ T.assert_type!(spell_books_query.where(id: 1), SpellBook::ActiveRecord_AssociationRelation)
267
+ T.assert_type!(spell_books_query.where(id: 1).recent, SpellBook::ActiveRecord_AssociationRelation)
268
+ T.assert_type!(spell_books_query.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
252
269
  T.assert_type!(spell_books_query.preload(:wizard), SpellBook::ActiveRecord_AssociationRelation)
253
270
  T.assert_type!(spell_books_query.eager_load(:wizard), SpellBook::ActiveRecord_AssociationRelation)
254
271
  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
272
  # Enumerable methods
258
273
  spell_books_query.each { |s| T.assert_type!(s, SpellBook) }
259
274
  spell_books_query.map { |s| T.assert_type!(s, SpellBook) }
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- sorbet-rails (0.6.3)
4
+ sorbet-rails (0.6.4)
5
5
  method_source (>= 0.9.2)
6
6
  parlour (~> 2.0)
7
7
  parser (>= 2.7)
@@ -102,7 +102,7 @@ GEM
102
102
  parser
103
103
  rainbow (~> 3.0)
104
104
  sorbet-runtime (>= 0.5)
105
- parser (2.7.1.1)
105
+ parser (2.7.1.2)
106
106
  ast (~> 2.4.0)
107
107
  polyfill (1.8.0)
108
108
  puma (3.12.4)
@@ -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