sorbet-rails 0.6.5 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +1 -2
  3. data/.gitignore +2 -1
  4. data/.travis.yml +1 -1
  5. data/README.md +60 -11
  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 +2 -2
  12. data/lib/sorbet-rails/config.rb +12 -0
  13. data/lib/sorbet-rails/dependent_gem_rbis/activerecord.rbi +3 -0
  14. data/lib/sorbet-rails/deprecation.rb +1 -0
  15. data/lib/sorbet-rails/gem_plugins/kaminari_plugin.rb +8 -0
  16. data/lib/sorbet-rails/helper_rbi_formatter.rb +1 -1
  17. data/lib/sorbet-rails/job_rbi_formatter.rb +75 -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 +40 -1
  21. data/lib/sorbet-rails/model_plugins/active_record_attribute.rb +12 -112
  22. data/lib/sorbet-rails/model_plugins/active_record_querying.rb +2 -2
  23. data/lib/sorbet-rails/model_plugins/active_record_serialized_attribute.rb +68 -0
  24. data/lib/sorbet-rails/model_plugins/base.rb +6 -8
  25. data/lib/sorbet-rails/model_plugins/plugins.rb +3 -0
  26. data/lib/sorbet-rails/model_rbi_formatter.rb +3 -3
  27. data/lib/sorbet-rails/model_utils.rb +5 -2
  28. data/lib/sorbet-rails/rails_mixins/generated_url_helpers.rb +2 -3
  29. data/lib/sorbet-rails/rails_mixins/pluck_to_tstruct.rb +54 -7
  30. data/lib/sorbet-rails/railtie.rb +0 -2
  31. data/lib/sorbet-rails/routes_rbi_formatter.rb +6 -2
  32. data/lib/sorbet-rails/sorbet_utils.rb +152 -150
  33. data/lib/sorbet-rails/tasks/rails_rbi.rake +9 -8
  34. data/sorbet-rails.gemspec +2 -2
  35. data/spec/bin/run_spec.sh +1 -1
  36. data/spec/generators/rails-template.rb +16 -0
  37. data/spec/generators/sorbet_test_cases.rb +29 -57
  38. data/spec/job_rbi_formatter_spec.rb +1 -1
  39. data/spec/pluck_to_tstruct_spec.rb +115 -16
  40. data/spec/rails_helper.rb +2 -2
  41. data/spec/rake_rails_rbi_jobs_spec.rb +20 -0
  42. data/spec/rake_rails_rbi_mailers_spec.rb +21 -0
  43. data/spec/sorbet_spec.rb +5 -5
  44. data/spec/support/v5.0/Gemfile +1 -1
  45. data/spec/support/v5.0/Gemfile.lock +15 -14
  46. data/spec/support/v5.0/app/controllers/application_controller.rb +1 -1
  47. data/spec/support/v5.0/app/models/headmaster.rb +1 -1
  48. data/spec/support/v5.0/app/models/potion.rb +1 -1
  49. data/spec/support/v5.0/app/models/robe.rb +1 -1
  50. data/spec/support/v5.0/app/models/school.rb +1 -1
  51. data/spec/support/v5.0/app/models/spell.rb +1 -1
  52. data/spec/support/v5.0/app/models/subject.rb +1 -1
  53. data/spec/support/v5.0/app/models/wizard.rb +5 -0
  54. data/spec/support/v5.0/config/environments/development.rb +1 -1
  55. data/spec/support/v5.0/config/environments/production.rb +1 -1
  56. data/spec/support/v5.0/config/environments/test.rb +1 -1
  57. data/spec/support/v5.0/config/initializers/wrap_parameters.rb +1 -1
  58. data/spec/support/v5.0/config/routes.rb +1 -1
  59. data/spec/support/v5.0/db/migrate/20190620000015_add_serialized_to_wizards.rb +9 -0
  60. data/spec/support/v5.0/db/schema.rb +8 -4
  61. data/spec/support/v5.0/sorbet_test_cases.rb +29 -57
  62. data/spec/support/v5.1/Gemfile.lock +13 -12
  63. data/spec/support/v5.1/app/controllers/application_controller.rb +1 -1
  64. data/spec/support/v5.1/app/models/headmaster.rb +1 -1
  65. data/spec/support/v5.1/app/models/school.rb +1 -1
  66. data/spec/support/v5.1/app/models/wizard.rb +5 -0
  67. data/spec/support/v5.1/config/environments/production.rb +1 -1
  68. data/spec/support/v5.1/config/initializers/wrap_parameters.rb +1 -1
  69. data/spec/support/v5.1/config/routes.rb +1 -1
  70. data/spec/support/v5.1/db/migrate/20190620000015_add_serialized_to_wizards.rb +9 -0
  71. data/spec/support/v5.1/db/schema.rb +5 -1
  72. data/spec/support/v5.1/sorbet_test_cases.rb +29 -57
  73. data/spec/support/v5.2/Gemfile +1 -1
  74. data/spec/support/v5.2/Gemfile.lock +15 -14
  75. data/spec/support/v5.2/app/models/headmaster.rb +1 -1
  76. data/spec/support/v5.2/app/models/school.rb +1 -1
  77. data/spec/support/v5.2/app/models/wizard.rb +5 -0
  78. data/spec/support/v5.2/config/environments/development.rb +1 -1
  79. data/spec/support/v5.2/config/environments/production.rb +1 -1
  80. data/spec/support/v5.2/config/environments/test.rb +1 -1
  81. data/spec/support/v5.2/config/initializers/wrap_parameters.rb +1 -1
  82. data/spec/support/v5.2/config/routes.rb +1 -1
  83. data/spec/support/v5.2/db/migrate/20190620000015_add_serialized_to_wizards.rb +9 -0
  84. data/spec/support/v5.2/db/schema.rb +5 -1
  85. data/spec/support/v5.2/sorbet_test_cases.rb +29 -57
  86. data/spec/support/v6.0/.gitignore +6 -0
  87. data/spec/support/v6.0/Gemfile +3 -3
  88. data/spec/support/v6.0/Gemfile.lock +82 -80
  89. data/spec/support/v6.0/app/models/wizard.rb +5 -0
  90. data/spec/support/v6.0/bin/bundle +22 -13
  91. data/spec/support/v6.0/config/environments/development.rb +1 -1
  92. data/spec/support/v6.0/config/environments/production.rb +1 -1
  93. data/spec/support/v6.0/config/environments/test.rb +2 -2
  94. data/spec/support/v6.0/config/routes.rb +1 -1
  95. data/spec/support/v6.0/db/migrate/20190620000015_add_serialized_to_wizards.rb +9 -0
  96. data/spec/support/v6.0/db/schema.rb +5 -1
  97. data/spec/support/v6.0/sorbet_test_cases.rb +29 -57
  98. data/spec/support/v6.0/tmp/pids/.keep +0 -0
  99. data/spec/test_data/v5.0/expected_application_job.rbi +2 -2
  100. data/spec/test_data/v5.0/expected_award_house_point_hourglasses.rbi +2 -2
  101. data/spec/test_data/v5.0/expected_custom_application_job.rbi +21 -0
  102. data/spec/test_data/v5.0/expected_custom_application_mailer.rbi +6 -0
  103. data/spec/test_data/v5.0/expected_custom_award_house_point_hourglasses.rbi +21 -0
  104. data/spec/test_data/v5.0/expected_custom_daily_prophet_mailer.rbi +8 -0
  105. data/spec/test_data/v5.0/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  106. data/spec/test_data/v5.0/expected_headmaster.rbi +26 -2
  107. data/spec/test_data/v5.0/expected_internal_metadata.rbi +2 -2
  108. data/spec/test_data/v5.0/expected_potion.rbi +14 -2
  109. data/spec/test_data/v5.0/expected_robe.rbi +14 -2
  110. data/spec/test_data/v5.0/expected_routes.rbi +4 -0
  111. data/spec/test_data/v5.0/expected_schema_migration.rbi +2 -2
  112. data/spec/test_data/v5.0/expected_school.rbi +14 -2
  113. data/spec/test_data/v5.0/expected_spell.rbi +2 -2
  114. data/spec/test_data/v5.0/expected_spell/habtm_spell_books.rbi +26 -2
  115. data/spec/test_data/v5.0/expected_spell_book.rbi +23 -11
  116. data/spec/test_data/v5.0/expected_spell_book/habtm_spells.rbi +26 -2
  117. data/spec/test_data/v5.0/expected_squib.rbi +65 -2
  118. data/spec/test_data/v5.0/expected_subject.rbi +2 -2
  119. data/spec/test_data/v5.0/expected_subject/habtm_wizards.rbi +26 -2
  120. data/spec/test_data/v5.0/expected_wand.rbi +24 -12
  121. data/spec/test_data/v5.0/expected_wizard.rbi +123 -60
  122. data/spec/test_data/v5.0/expected_wizard/habtm_subjects.rbi +26 -2
  123. data/spec/test_data/v5.0/expected_wizard_wo_spellbook.rbi +123 -60
  124. data/spec/test_data/v5.1/expected_application_job.rbi +2 -2
  125. data/spec/test_data/v5.1/expected_award_house_point_hourglasses.rbi +2 -2
  126. data/spec/test_data/v5.1/expected_custom_application_job.rbi +21 -0
  127. data/spec/test_data/v5.1/expected_custom_application_mailer.rbi +6 -0
  128. data/spec/test_data/v5.1/expected_custom_award_house_point_hourglasses.rbi +21 -0
  129. data/spec/test_data/v5.1/expected_custom_daily_prophet_mailer.rbi +8 -0
  130. data/spec/test_data/v5.1/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  131. data/spec/test_data/v5.1/expected_headmaster.rbi +26 -2
  132. data/spec/test_data/v5.1/expected_internal_metadata.rbi +2 -2
  133. data/spec/test_data/v5.1/expected_potion.rbi +14 -2
  134. data/spec/test_data/v5.1/expected_robe.rbi +14 -2
  135. data/spec/test_data/v5.1/expected_routes.rbi +4 -0
  136. data/spec/test_data/v5.1/expected_schema_migration.rbi +2 -2
  137. data/spec/test_data/v5.1/expected_school.rbi +14 -2
  138. data/spec/test_data/v5.1/expected_spell.rbi +2 -2
  139. data/spec/test_data/v5.1/expected_spell/habtm_spell_books.rbi +26 -2
  140. data/spec/test_data/v5.1/expected_spell_book.rbi +23 -11
  141. data/spec/test_data/v5.1/expected_spell_book/habtm_spells.rbi +26 -2
  142. data/spec/test_data/v5.1/expected_squib.rbi +65 -2
  143. data/spec/test_data/v5.1/expected_subject.rbi +2 -2
  144. data/spec/test_data/v5.1/expected_subject/habtm_wizards.rbi +26 -2
  145. data/spec/test_data/v5.1/expected_wand.rbi +24 -12
  146. data/spec/test_data/v5.1/expected_wizard.rbi +123 -60
  147. data/spec/test_data/v5.1/expected_wizard/habtm_subjects.rbi +26 -2
  148. data/spec/test_data/v5.1/expected_wizard_wo_spellbook.rbi +123 -60
  149. data/spec/test_data/v5.2/expected_application_job.rbi +2 -2
  150. data/spec/test_data/v5.2/expected_attachment.rbi +26 -2
  151. data/spec/test_data/v5.2/expected_award_house_point_hourglasses.rbi +2 -2
  152. data/spec/test_data/v5.2/expected_blob.rbi +27 -3
  153. data/spec/test_data/v5.2/expected_custom_application_job.rbi +21 -0
  154. data/spec/test_data/v5.2/expected_custom_application_mailer.rbi +6 -0
  155. data/spec/test_data/v5.2/expected_custom_award_house_point_hourglasses.rbi +21 -0
  156. data/spec/test_data/v5.2/expected_custom_daily_prophet_mailer.rbi +8 -0
  157. data/spec/test_data/v5.2/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  158. data/spec/test_data/v5.2/expected_headmaster.rbi +26 -2
  159. data/spec/test_data/v5.2/expected_internal_metadata.rbi +2 -2
  160. data/spec/test_data/v5.2/expected_potion.rbi +14 -2
  161. data/spec/test_data/v5.2/expected_robe.rbi +14 -2
  162. data/spec/test_data/v5.2/expected_routes.rbi +4 -0
  163. data/spec/test_data/v5.2/expected_schema_migration.rbi +2 -2
  164. data/spec/test_data/v5.2/expected_school.rbi +14 -2
  165. data/spec/test_data/v5.2/expected_spell.rbi +2 -2
  166. data/spec/test_data/v5.2/expected_spell/habtm_spell_books.rbi +26 -2
  167. data/spec/test_data/v5.2/expected_spell_book.rbi +23 -11
  168. data/spec/test_data/v5.2/expected_spell_book/habtm_spells.rbi +26 -2
  169. data/spec/test_data/v5.2/expected_squib.rbi +91 -4
  170. data/spec/test_data/v5.2/expected_subject.rbi +2 -2
  171. data/spec/test_data/v5.2/expected_subject/habtm_wizards.rbi +26 -2
  172. data/spec/test_data/v5.2/expected_wand.rbi +24 -12
  173. data/spec/test_data/v5.2/expected_wizard.rbi +149 -62
  174. data/spec/test_data/v5.2/expected_wizard/habtm_subjects.rbi +26 -2
  175. data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +149 -62
  176. data/spec/test_data/v6.0/expected_application_job.rbi +2 -2
  177. data/spec/test_data/v6.0/expected_attachment.rbi +26 -2
  178. data/spec/test_data/v6.0/expected_award_house_point_hourglasses.rbi +2 -2
  179. data/spec/test_data/v6.0/expected_blob.rbi +27 -3
  180. data/spec/test_data/v6.0/expected_custom_application_job.rbi +21 -0
  181. data/spec/test_data/v6.0/expected_custom_application_mailer.rbi +6 -0
  182. data/spec/test_data/v6.0/expected_custom_award_house_point_hourglasses.rbi +21 -0
  183. data/spec/test_data/v6.0/expected_custom_daily_prophet_mailer.rbi +8 -0
  184. data/spec/test_data/v6.0/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  185. data/spec/test_data/v6.0/expected_headmaster.rbi +26 -2
  186. data/spec/test_data/v6.0/expected_internal_metadata.rbi +2 -2
  187. data/spec/test_data/v6.0/expected_potion.rbi +14 -2
  188. data/spec/test_data/v6.0/expected_robe.rbi +14 -2
  189. data/spec/test_data/v6.0/expected_routes.rbi +4 -0
  190. data/spec/test_data/v6.0/expected_schema_migration.rbi +2 -2
  191. data/spec/test_data/v6.0/expected_school.rbi +14 -2
  192. data/spec/test_data/v6.0/expected_spell.rbi +2 -2
  193. data/spec/test_data/v6.0/expected_spell/habtm_spell_books.rbi +26 -2
  194. data/spec/test_data/v6.0/expected_spell_book.rbi +23 -11
  195. data/spec/test_data/v6.0/expected_spell_book/habtm_spells.rbi +26 -2
  196. data/spec/test_data/v6.0/expected_squib.rbi +91 -4
  197. data/spec/test_data/v6.0/expected_subject.rbi +2 -2
  198. data/spec/test_data/v6.0/expected_subject/habtm_wizards.rbi +26 -2
  199. data/spec/test_data/v6.0/expected_wand.rbi +24 -12
  200. data/spec/test_data/v6.0/expected_wizard.rbi +149 -62
  201. data/spec/test_data/v6.0/expected_wizard/habtm_subjects.rbi +26 -2
  202. data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +149 -62
  203. data/spec/tstruct_comparable.rb +13 -0
  204. metadata +61 -15
  205. data/lib/bundled_rbi/parameters.rbi +0 -28
  206. data/lib/sorbet-rails/custom_types/boolean_string.rb +0 -42
  207. data/lib/sorbet-rails/custom_types/integer_string.rb +0 -45
  208. data/lib/sorbet-rails/rails_mixins/custom_params_methods.rb +0 -57
  209. data/spec/boolean_string_spec.rb +0 -59
  210. data/spec/custom_params_methods_spec.rb +0 -138
  211. data/spec/integer_string_spec.rb +0 -46
@@ -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
@@ -42,11 +42,6 @@ RSpec.describe 'sorbet' do
42
42
  chdir: Rails.root.to_path,
43
43
  )
44
44
 
45
- stdout, stderr, status = Open3.capture3(
46
- 'bundle', 'exec', 'srb', 'tc',
47
- chdir: Rails.root.to_path,
48
- )
49
-
50
45
  if status != 0
51
46
  puts "================================="
52
47
  puts "stdout #{stdout}"
@@ -55,6 +50,11 @@ RSpec.describe 'sorbet' do
55
50
  puts "================================="
56
51
  end
57
52
 
53
+ stdout, stderr, status = Open3.capture3(
54
+ 'bundle', 'exec', 'srb', 'tc',
55
+ chdir: Rails.root.to_path,
56
+ )
57
+
58
58
  # Ensure sorbet_test_cases.rb is set to `typed: true` since srb init may
59
59
  # set it to false.
60
60
  sorbet_test_cases_path = Rails.root.join('sorbet_test_cases.rb')
@@ -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,9 +1,9 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- sorbet-rails (0.6.5)
4
+ sorbet-rails (0.7.3)
5
5
  method_source (>= 0.9.2)
6
- parlour (~> 2.0)
6
+ parlour (>= 4.0.1)
7
7
  parser (>= 2.7)
8
8
  sorbet-coerce (>= 0.2.6)
9
9
  sorbet-runtime (>= 0.5)
@@ -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)
@@ -76,16 +76,16 @@ GEM
76
76
  nio4r (2.5.2)
77
77
  nokogiri (1.10.9)
78
78
  mini_portile2 (~> 2.4.0)
79
- parlour (2.1.0)
79
+ parlour (5.0.0)
80
80
  commander (~> 4.5)
81
81
  parser
82
82
  rainbow (~> 3.0)
83
83
  sorbet-runtime (>= 0.5)
84
- parser (2.7.1.2)
85
- ast (~> 2.4.0)
86
- polyfill (1.8.0)
87
- puma (3.12.4)
88
- rack (2.2.2)
84
+ parser (3.0.0.0)
85
+ ast (~> 2.4.1)
86
+ polyfill (1.9.0)
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,13 +116,13 @@ 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.7)
119
+ sorbet-coerce (0.3.0)
120
120
  polyfill (~> 1.8)
121
121
  safe_type (~> 1.1, >= 1.1.1)
122
122
  sorbet (>= 0.4.4704)
123
123
  sorbet-runtime (>= 0.4.4704)
124
124
  sorbet-runtime (0.5.5480)
125
- sorbet-static (0.5.5480-universal-darwin-14)
125
+ sorbet-static (0.5.5480-universal-darwin-19)
126
126
  sprockets (4.0.0)
127
127
  concurrent-ruby (~> 1.0)
128
128
  rack (> 1, < 3)
@@ -137,15 +137,16 @@ 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
144
+ x86_64-darwin-19
144
145
 
145
146
  DEPENDENCIES
146
147
  byebug
147
148
  jbuilder (~> 2.5)
148
- puma (~> 3.0)
149
+ puma (~> 3.12)
149
150
  rails (~> 5.0.7)
150
151
  sorbet
151
152
  sorbet-rails!
@@ -154,4 +155,4 @@ DEPENDENCIES
154
155
  tzinfo-data
155
156
 
156
157
  BUNDLED WITH
157
- 2.0.2
158
+ 2.2.0
@@ -1,4 +1,4 @@
1
- # typed: strong
1
+ # typed: strict
2
2
  class ApplicationController < ActionController::Base
3
3
  protect_from_forgery with: :exception
4
4
  end
@@ -1,4 +1,4 @@
1
- # typed: strong
1
+ # typed: strict
2
2
  class Headmaster < ApplicationRecord
3
3
  belongs_to :school, required: false
4
4
  belongs_to :wizard, optional: true
@@ -1,4 +1,4 @@
1
- # typed: strong
1
+ # typed: strict
2
2
  # an abstract class that has no table
3
3
  class Potion < ApplicationRecord
4
4
  self.abstract_class = true
@@ -1,4 +1,4 @@
1
- # typed: strong
1
+ # typed: strict
2
2
  class Robe < ApplicationRecord
3
3
  belongs_to :wizard, required: false
4
4
  end
@@ -1,4 +1,4 @@
1
- # typed: strong
1
+ # typed: strict
2
2
  class School < ApplicationRecord
3
3
  has_one :headmaster
4
4
  validates :headmaster, presence: true
@@ -1,4 +1,4 @@
1
- # typed: strong
1
+ # typed: strict
2
2
  class Spell < ApplicationRecord
3
3
  # habtm enforced at the DB level
4
4
  has_and_belongs_to_many :spell_books
@@ -1,4 +1,4 @@
1
- # typed: strong
1
+ # typed: strict
2
2
  class Subject < ApplicationRecord
3
3
  # habtm which is optional at the db level
4
4
  has_and_belongs_to_many :wizards
@@ -47,6 +47,11 @@ class Wizard < ApplicationRecord
47
47
  blue: 2,
48
48
  }, _prefix: :color, _suffix: :eyes
49
49
 
50
+ serialize :owl_results, Hash
51
+ serialize :newt_subjects # no specific data type, uses the default YAML Object coder
52
+ serialize :pets, Array
53
+ serialize :patronus_characteristics, JSON
54
+
50
55
  has_one :wand
51
56
  has_many :spell_books
52
57
  # habtm which is optional at the db level
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: false
2
2
  Rails.application.configure do
3
3
  # Settings specified here will take precedence over those in config/application.rb.
4
4
 
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: false
2
2
  Rails.application.configure do
3
3
  # Settings specified here will take precedence over those in config/application.rb.
4
4
 
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: false
2
2
  Rails.application.configure do
3
3
  # Settings specified here will take precedence over those in config/application.rb.
4
4
 
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: false
2
2
  # Be sure to restart your server when you modify this file.
3
3
 
4
4
  # This file contains settings for ActionController::ParamsWrapper which
@@ -1,4 +1,4 @@
1
- # typed: strict
1
+ # typed: false
2
2
  Rails.application.routes.draw do
3
3
  get 'test/index' => 'test#index'
4
4
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
@@ -0,0 +1,9 @@
1
+ # typed: false
2
+ class AddSerializedToWizards < ActiveRecord::Migration[5.0]
3
+ def change
4
+ add_column :wizards, :owl_results, :text # Hash
5
+ add_column :wizards, :newt_subjects, :text # generic
6
+ add_column :wizards, :pets, :text # Array
7
+ add_column :wizards, :patronus_characteristics, :text # serialized as JSON, but not a JSON column type
8
+ end
9
+ end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20190620000014) do
14
+ ActiveRecord::Schema.define(version: 20190620000015) do
15
15
 
16
16
  create_table "headmasters", force: :cascade do |t|
17
17
  t.integer "school_id"
@@ -78,15 +78,19 @@ ActiveRecord::Schema.define(version: 20190620000014) do
78
78
  t.integer "professor"
79
79
  t.string "parent_email"
80
80
  t.text "notes"
81
- t.datetime "created_at", null: false
82
- t.datetime "updated_at", null: false
81
+ t.datetime "created_at", null: false
82
+ t.datetime "updated_at", null: false
83
83
  t.string "broom"
84
84
  t.integer "quidditch_position"
85
85
  t.integer "hair_color"
86
86
  t.integer "eye_color"
87
87
  t.integer "hair_length"
88
- t.string "type", default: "Wizard", null: false
88
+ t.string "type", default: "Wizard", null: false
89
89
  t.integer "school_id"
90
+ t.text "owl_results"
91
+ t.text "newt_subjects"
92
+ t.text "pets"
93
+ t.text "patronus_characteristics"
90
94
  end
91
95
 
92
96
  end
@@ -64,7 +64,7 @@ T.assert_type!(Wizard.find_each, T::Enumerator[Wizard])
64
64
  Wizard.find_in_batches { |w| T.assert_type!(w, T::Array[Wizard]) }
65
65
  T.assert_type!(Wizard.find_in_batches, T::Enumerator[T::Array[Wizard]])
66
66
  Wizard.in_batches { |w| T.assert_type!(w, Wizard::ActiveRecord_Relation) }
67
- T.assert_type!(Wizard.in_batches, T::Enumerable[Wizard::ActiveRecord_Relation])
67
+ T.assert_type!(Wizard.in_batches, ActiveRecord::Batches::BatchEnumerator)
68
68
  # T.assert_type!(Wizard.destroy_all, T::Array[Wizard]) # Ignored until we add support
69
69
  T.assert_type!(Wizard.any?, T::Boolean)
70
70
  T.assert_type!(Wizard.many?, T::Boolean)
@@ -305,6 +305,21 @@ T.assert_type!(Wizard::House::Hufflepuff, Wizard::House)
305
305
  T.assert_type!(Wizard::House::Ravenclaw, Wizard::House)
306
306
  T.assert_type!(Wizard::House::Slytherin, Wizard::House)
307
307
 
308
+ # Serialization
309
+ T.assert_type!(
310
+ wizard.owl_results,
311
+ T.nilable(T::Hash[T.untyped, T.untyped])
312
+ )
313
+ T.assert_type!(
314
+ wizard.newt_subjects,
315
+ T.nilable(T.any(T::Array[T.untyped], T::Boolean, Float, T::Hash[T.untyped, T.untyped], Integer, String))
316
+ )
317
+ T.assert_type!(
318
+ wizard.patronus_characteristics,
319
+ T.nilable(T.any(T::Array[T.untyped], T::Boolean, Float, T::Hash[String, T.untyped], Integer, String))
320
+ )
321
+ T.assert_type!(wizard.pets, T.nilable(T::Array[T.untyped]))
322
+
308
323
  # Mythical plugin
309
324
  T.assert_type!(Wand.mythicals, T::Array[Wand])
310
325
 
@@ -312,7 +327,10 @@ T.assert_type!(Wand.mythicals, T::Array[Wand])
312
327
  T.assert_type!(HogwartsAcceptanceMailer.notify(wizard), ActionMailer::MessageDelivery)
313
328
 
314
329
  # Jobs
315
- AwardHousePointHourglasses.perform_later(student: wizard, point: 10)
330
+ T.assert_type!(
331
+ AwardHousePointHourglasses.perform_later(student: wizard, point: 10),
332
+ AwardHousePointHourglasses
333
+ )
316
334
  AwardHousePointHourglasses.perform_now(student: wizard, point: 10)
317
335
  AwardHousePointHourglasses.
318
336
  set(queue: :daily, wait: 5.minutes).
@@ -321,7 +339,6 @@ AwardHousePointHourglasses.
321
339
  set(priority: 10, wait_until: Time.now.tomorrow).
322
340
  perform_later(student: wizard, point: 10)
323
341
 
324
-
325
342
  T.assert_type!(wizard.broom_nimbus?, T::Boolean)
326
343
  T.assert_type!(wizard.color_brown_eyes?, T::Boolean)
327
344
  T.assert_type!(wizard.quidditch_keeper?, T::Boolean)
@@ -361,44 +378,6 @@ params = ActionController::Parameters.new({
361
378
  typed_params = TypedParams[MyActionParams].new.extract!(params)
362
379
  T.assert_type!(typed_params, MyActionParams)
363
380
 
364
- # -- require_typed
365
- T.assert_type!(
366
- params.require_typed(:age, TA[Integer].new),
367
- Integer,
368
- )
369
- T.assert_type!(
370
- params.require_typed(:name, TA[String].new),
371
- String,
372
- )
373
- info = params.require_typed(:info, TA[ActionController::Parameters].new)
374
- T.assert_type!(info, ActionController::Parameters)
375
- T.assert_type!(
376
- info.require_typed(:friends, TA[T::Array[String]].new),
377
- T::Array[String],
378
- )
379
- # -- fetch_typed
380
- T.assert_type!(
381
- params.fetch_typed(:age, TA[Integer].new),
382
- Integer,
383
- )
384
- T.assert_type!(
385
- params.fetch_typed(:name, TA[String].new),
386
- String,
387
- )
388
- T.assert_type!(
389
- params.fetch_typed(:nonexistence, TA[String].new, ''),
390
- String,
391
- )
392
- T.assert_type!(
393
- params.fetch_typed(:nonexistence, TA[T.nilable(String)].new, nil),
394
- T.nilable(String),
395
- )
396
- T.assert_type!(
397
- params.fetch_typed(:nonexistence, TA[T::Array[Integer]].new, []),
398
- T::Array[Integer],
399
- )
400
-
401
-
402
381
  # -- pluck to tstruct
403
382
  class WizardStruct < T::Struct
404
383
  const :name, String
@@ -415,23 +394,16 @@ Wizard.all.pluck_to_tstruct(TA[WizardStruct].new).each do |row|
415
394
  T.assert_type!(row, WizardStruct)
416
395
  end
417
396
 
418
-
419
397
  # -- GeneratedUrlHelpers
420
398
  class TestHelper
421
399
  include GeneratedUrlHelpers
422
-
423
- # need to implement this for the url
424
- def default_url_options
425
- {
426
- protocol: 'http',
427
- host: 'localhost',
428
- port: 3000,
429
- }
430
- end
431
-
432
- def test_url_helper
433
- T.assert_type!(test_index_path, String)
434
- T.assert_type!(test_index_url, String)
435
- end
436
400
  end
437
- TestHelper.new.test_url_helper
401
+
402
+ T.assert_type!(TestHelper.new.test_index_path, String)
403
+ # need to set this config for _url methods
404
+ Rails.application.routes.default_url_options = {
405
+ protocol: 'http',
406
+ host: 'localhost',
407
+ port: 3000,
408
+ }
409
+ T.assert_type!(TestHelper.new.test_index_url, String)
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: ../../..
3
3
  specs:
4
- sorbet-rails (0.6.5)
4
+ sorbet-rails (0.7.3)
5
5
  method_source (>= 0.9.2)
6
- parlour (~> 2.0)
6
+ parlour (>= 4.0.1)
7
7
  parser (>= 2.7)
8
8
  sorbet-coerce (>= 0.2.6)
9
9
  sorbet-runtime (>= 0.5)
@@ -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)
@@ -77,16 +77,16 @@ GEM
77
77
  nio4r (2.5.2)
78
78
  nokogiri (1.10.9)
79
79
  mini_portile2 (~> 2.4.0)
80
- parlour (2.1.0)
80
+ parlour (5.0.0)
81
81
  commander (~> 4.5)
82
82
  parser
83
83
  rainbow (~> 3.0)
84
84
  sorbet-runtime (>= 0.5)
85
- parser (2.7.1.2)
86
- ast (~> 2.4.0)
87
- polyfill (1.8.0)
85
+ parser (3.0.0.0)
86
+ ast (~> 2.4.1)
87
+ polyfill (1.9.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,13 +117,13 @@ 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.7)
120
+ sorbet-coerce (0.3.0)
121
121
  polyfill (~> 1.8)
122
122
  safe_type (~> 1.1, >= 1.1.1)
123
123
  sorbet (>= 0.4.4704)
124
124
  sorbet-runtime (>= 0.4.4704)
125
125
  sorbet-runtime (0.5.5480)
126
- sorbet-static (0.5.5480-universal-darwin-14)
126
+ sorbet-static (0.5.5480-universal-darwin-19)
127
127
  sprockets (4.0.0)
128
128
  concurrent-ruby (~> 1.0)
129
129
  rack (> 1, < 3)
@@ -143,10 +143,11 @@ 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
150
+ x86_64-darwin-19
150
151
 
151
152
  DEPENDENCIES
152
153
  byebug
@@ -161,4 +162,4 @@ DEPENDENCIES
161
162
  web-console (>= 3.3.0)
162
163
 
163
164
  BUNDLED WITH
164
- 2.0.2
165
+ 2.2.0