sorbet-rails 0.7.4 → 0.7.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (360) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +7 -0
  3. data/.github/workflows/ci-master.yml +28 -0
  4. data/.github/workflows/ci.yml +26 -0
  5. data/.github/workflows/publish-gem.yml +27 -0
  6. data/CONTRIBUTING.md +1 -2
  7. data/Gemfile +5 -9
  8. data/README.md +18 -4
  9. data/Rakefile +13 -24
  10. data/lib/sorbet-rails/active_record_rbi_formatter.rb +12 -9
  11. data/lib/sorbet-rails/dependent_gem_rbis/activerecord.rbi +4 -0
  12. data/lib/sorbet-rails/dependent_gem_rbis/parlour.rbi +1 -1
  13. data/lib/sorbet-rails/gem_plugins/aasm_plugin.rb +50 -0
  14. data/lib/sorbet-rails/gem_plugins/money_rails_plugin.rb +76 -0
  15. data/lib/sorbet-rails/job_rbi_formatter.rb +1 -1
  16. data/lib/sorbet-rails/model_plugins/active_record_querying.rb +25 -1
  17. data/lib/sorbet-rails/model_plugins/active_record_serialized_attribute.rb +3 -2
  18. data/lib/sorbet-rails/model_plugins/base.rb +8 -1
  19. data/lib/sorbet-rails/model_plugins/custom_finder_methods.rb +1 -1
  20. data/lib/sorbet-rails/model_plugins/plugins.rb +6 -0
  21. data/lib/sorbet-rails/model_utils.rb +14 -7
  22. data/lib/sorbet-rails/rails_mixins/custom_finder_methods.rb +4 -0
  23. data/lib/sorbet-rails/railtie.rb +1 -1
  24. data/lib/sorbet-rails/routes_rbi_formatter.rb +8 -0
  25. data/lib/sorbet-rails/tasks/rails_rbi.rake +12 -8
  26. data/sorbet-rails.gemspec +2 -2
  27. data/spec/bin/run_all_specs.sh +3 -4
  28. data/spec/bin/run_spec.sh +4 -1
  29. data/spec/generators/rails-template.rb +3 -20
  30. data/spec/generators/sorbet_test_cases.rb +26 -4
  31. data/spec/rails_helper.rb +5 -5
  32. data/spec/rake_rails_rbi_models_spec.rb +11 -4
  33. data/spec/sorbet_spec.rb +2 -1
  34. data/spec/support/v5.2/Gemfile +1 -3
  35. data/spec/support/v5.2/Gemfile.lock +66 -71
  36. data/spec/support/v5.2/app/controllers/application_controller.rb +1 -1
  37. data/spec/support/v5.2/app/mailers/application_mailer.rb +1 -1
  38. data/spec/support/v5.2/app/mailers/daily_prophet_mailer.rb +1 -1
  39. data/spec/support/v5.2/app/mailers/hogwarts_acceptance_mailer.rb +1 -1
  40. data/spec/support/v5.2/app/models/spell_book.rb +1 -1
  41. data/spec/support/v5.2/app/models/wand.rb +1 -1
  42. data/spec/support/v5.2/app/models/wizard.rb +1 -1
  43. data/spec/support/v5.2/config/environments/development.rb +1 -1
  44. data/spec/support/v5.2/config/environments/production.rb +1 -1
  45. data/spec/support/v5.2/config/environments/test.rb +1 -1
  46. data/spec/support/v5.2/config/routes.rb +1 -1
  47. data/spec/support/v5.2/sorbet_test_cases.rb +26 -4
  48. data/spec/support/v6.0/Gemfile +1 -1
  49. data/spec/support/v6.0/Gemfile.lock +81 -85
  50. data/spec/support/v6.0/app/mailers/application_mailer.rb +1 -1
  51. data/spec/support/v6.0/config/environments/development.rb +1 -1
  52. data/spec/support/v6.0/config/environments/test.rb +1 -1
  53. data/spec/support/v6.0/config/initializers/cookies_serializer.rb +1 -1
  54. data/spec/support/v6.0/config/initializers/sorbet_rails.rb +1 -1
  55. data/spec/support/v6.0/config/routes.rb +1 -1
  56. data/spec/support/v6.0/sorbet_test_cases.rb +26 -4
  57. data/spec/support/{v5.1 → v6.1}/.gitignore +13 -2
  58. data/spec/support/{v5.1 → v6.1}/Gemfile +12 -15
  59. data/spec/support/{v5.1 → v6.1}/Gemfile.lock +87 -59
  60. data/spec/support/{v5.0 → v6.1}/README.md +0 -0
  61. data/spec/support/{v5.0 → v6.1}/Rakefile +0 -0
  62. data/spec/support/{v5.0 → v6.1}/app/assets/config/manifest.js +0 -0
  63. data/spec/support/{v5.0 → v6.1}/app/assets/images/.keep +0 -0
  64. data/spec/support/{v5.1 → v6.1}/app/assets/stylesheets/application.css +0 -0
  65. data/spec/support/{v5.0 → v6.1}/app/controllers/application_controller.rb +1 -2
  66. data/spec/support/{v5.0 → v6.1}/app/controllers/concerns/.keep +0 -0
  67. data/spec/support/{v5.0 → v6.1}/app/helpers/application_helper.rb +0 -0
  68. data/spec/support/{v5.0 → v6.1}/app/helpers/bar_helper.rb +0 -0
  69. data/spec/support/{v5.0 → v6.1}/app/helpers/baz_helper.rb +0 -0
  70. data/spec/support/{v5.0 → v6.1}/app/helpers/foo_helper.rb +0 -0
  71. data/spec/support/v6.1/app/jobs/application_job.rb +8 -0
  72. data/spec/support/{v5.0 → v6.1}/app/jobs/award_house_point_hourglasses.rb +0 -0
  73. data/spec/support/{v5.1 → v6.1}/app/mailers/application_mailer.rb +1 -1
  74. data/spec/support/{v5.0 → v6.1}/app/mailers/daily_prophet_mailer.rb +0 -0
  75. data/spec/support/{v5.0 → v6.1}/app/mailers/hogwarts_acceptance_mailer.rb +0 -0
  76. data/spec/support/{v5.0 → v6.1}/app/models/application_record.rb +0 -0
  77. data/spec/support/{v5.0 → v6.1}/app/models/concerns/.keep +0 -0
  78. data/spec/support/{v5.0 → v6.1}/app/models/concerns/mythical.rb +0 -0
  79. data/spec/support/{v5.1 → v6.1}/app/models/headmaster.rb +1 -1
  80. data/spec/support/{v5.1 → v6.1}/app/models/potion.rb +0 -0
  81. data/spec/support/{v5.1 → v6.1}/app/models/robe.rb +0 -0
  82. data/spec/support/{v5.0 → v6.1}/app/models/school.rb +1 -1
  83. data/spec/support/{v5.1 → v6.1}/app/models/spell.rb +0 -0
  84. data/spec/support/{v5.0 → v6.1}/app/models/spell_book.rb +0 -0
  85. data/spec/support/{v5.0 → v6.1}/app/models/squib.rb +0 -0
  86. data/spec/support/{v5.1 → v6.1}/app/models/subject.rb +0 -0
  87. data/spec/support/{v5.0 → v6.1}/app/models/wand.rb +0 -0
  88. data/spec/support/{v5.0 → v6.1}/app/models/wizard.rb +2 -1
  89. data/spec/support/{v5.1 → v6.1}/app/views/layouts/application.html.erb +2 -1
  90. data/spec/support/{v5.0 → v6.1}/app/views/layouts/mailer.html.erb +0 -0
  91. data/spec/support/{v5.0 → v6.1}/app/views/layouts/mailer.text.erb +0 -0
  92. data/spec/support/v6.1/bin/bundle +114 -0
  93. data/spec/support/{v5.0 → v6.1}/bin/rails +0 -0
  94. data/spec/support/{v5.0 → v6.1}/bin/rake +0 -0
  95. data/spec/support/{v5.1 → v6.1}/bin/setup +6 -11
  96. data/spec/support/{v5.1 → v6.1}/config/application.rb +8 -4
  97. data/spec/support/{v5.0 → v6.1}/config/boot.rb +0 -0
  98. data/spec/support/{v5.1 → v6.1}/config/database.yml +1 -1
  99. data/spec/support/{v5.0 → v6.1}/config/environment.rb +0 -0
  100. data/spec/support/{v5.1 → v6.1}/config/environments/development.rb +12 -4
  101. data/spec/support/{v5.1 → v6.1}/config/environments/production.rb +29 -7
  102. data/spec/support/{v5.1 → v6.1}/config/environments/test.rb +13 -7
  103. data/spec/support/{v5.0 → v6.1}/config/initializers/application_controller_renderer.rb +0 -0
  104. data/spec/support/{v5.0 → v6.1}/config/initializers/backtrace_silencers.rb +0 -0
  105. data/spec/support/v6.1/config/initializers/content_security_policy.rb +29 -0
  106. data/spec/support/{v5.1 → v6.1}/config/initializers/cookies_serializer.rb +1 -1
  107. data/spec/support/{v5.0 → v6.1}/config/initializers/filter_parameter_logging.rb +0 -0
  108. data/spec/support/{v5.0 → v6.1}/config/initializers/inflections.rb +0 -0
  109. data/spec/support/{v5.0 → v6.1}/config/initializers/mime_types.rb +0 -0
  110. data/spec/support/{v5.0 → v6.1}/config/initializers/sorbet_rails.rb +1 -1
  111. data/spec/support/{v5.0 → v6.1}/config/initializers/wrap_parameters.rb +0 -0
  112. data/spec/support/{v5.1 → v6.1}/config/locales/en.yml +1 -1
  113. data/spec/support/{v5.1 → v6.1}/config/puma.rb +8 -26
  114. data/spec/support/v6.1/config/routes.rb +5 -0
  115. data/spec/support/v6.1/config/storage.yml +34 -0
  116. data/spec/support/{v5.0 → v6.1}/config.ru +0 -0
  117. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000001_create_wizards.rb +2 -2
  118. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000002_create_wands.rb +2 -2
  119. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000003_create_spell_books.rb +2 -2
  120. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000004_add_more_column_types_to_wands.rb +2 -2
  121. data/spec/support/v6.1/db/migrate/20190620000005_add_broom_to_wizard.rb +6 -0
  122. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000006_add_more_enums_to_wizard.rb +2 -2
  123. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000007_add_type_to_wizard.rb +2 -2
  124. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000008_add_robe_to_wizard.rb +2 -2
  125. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000009_add_school.rb +2 -2
  126. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000010_add_subject.rb +2 -2
  127. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000011_add_subjects_wizards.rb +2 -2
  128. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000012_add_spell.rb +2 -2
  129. data/spec/support/{v5.1 → v6.1}/db/migrate/20190620000013_add_spells_spell_books.rb +2 -2
  130. data/spec/support/{v5.0 → v6.1}/db/migrate/20190620000014_create_headmasters.rb +2 -2
  131. data/spec/support/{v5.0 → v6.1}/db/migrate/20190620000015_add_serialized_to_wizards.rb +2 -2
  132. data/spec/support/{v5.1 → v6.1}/db/schema.rb +14 -11
  133. data/spec/support/{v5.0 → v6.1}/db/seeds.rb +0 -0
  134. data/spec/support/{v5.0 → v6.1}/lib/assets/.keep +0 -0
  135. data/spec/support/{v5.0 → v6.1}/lib/mythical_rbi_plugin.rb +0 -0
  136. data/spec/support/{v5.0 → v6.1}/lib/tasks/.keep +0 -0
  137. data/spec/support/{v5.0 → v6.1}/log/.keep +0 -0
  138. data/spec/support/{v5.0 → v6.1}/sorbet_test_cases.rb +26 -4
  139. data/spec/support/{v5.0/tmp → v6.1/storage}/.keep +0 -0
  140. data/spec/support/{v5.0/vendor/assets/stylesheets → v6.1/tmp}/.keep +0 -0
  141. data/spec/support/{v5.1/app/assets/images → v6.1/tmp/pids}/.keep +0 -0
  142. data/spec/support/{v5.1/app/controllers/concerns → v6.1/vendor}/.keep +0 -0
  143. data/spec/test_data/v5.2/expected_active_record_base.rbi +10 -10
  144. data/spec/test_data/v5.2/expected_active_record_relation.rbi +10 -10
  145. data/spec/test_data/v5.2/expected_attachment.rbi +13 -7
  146. data/spec/test_data/v5.2/expected_blob.rbi +13 -7
  147. data/spec/test_data/v5.2/expected_headmaster.rbi +13 -7
  148. data/spec/test_data/v5.2/expected_internal_metadata.rbi +13 -7
  149. data/spec/test_data/v5.2/expected_potion.rbi +13 -7
  150. data/spec/test_data/v5.2/expected_robe.rbi +13 -7
  151. data/spec/test_data/v5.2/expected_routes.rbi +8 -0
  152. data/spec/test_data/v5.2/expected_schema_migration.rbi +13 -7
  153. data/spec/test_data/v5.2/expected_school.rbi +13 -7
  154. data/spec/test_data/v5.2/expected_spell/habtm_spell_books.rbi +13 -7
  155. data/spec/test_data/v5.2/expected_spell.rbi +13 -7
  156. data/spec/test_data/v5.2/expected_spell_book/habtm_spells.rbi +13 -7
  157. data/spec/test_data/v5.2/expected_spell_book.rbi +13 -7
  158. data/spec/test_data/v5.2/expected_squib.rbi +15 -9
  159. data/spec/test_data/v5.2/expected_subject/habtm_wizards.rbi +13 -7
  160. data/spec/test_data/v5.2/expected_subject.rbi +13 -7
  161. data/spec/test_data/v5.2/expected_wand.rbi +13 -7
  162. data/spec/test_data/v5.2/expected_wizard/habtm_subjects.rbi +13 -7
  163. data/spec/test_data/v5.2/expected_wizard.rbi +15 -9
  164. data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +15 -9
  165. data/spec/test_data/v6.0/expected_active_record_base.rbi +10 -10
  166. data/spec/test_data/v6.0/expected_active_record_relation.rbi +10 -10
  167. data/spec/test_data/v6.0/expected_attachment.rbi +13 -7
  168. data/spec/test_data/v6.0/expected_blob.rbi +13 -7
  169. data/spec/test_data/v6.0/expected_headmaster.rbi +13 -7
  170. data/spec/test_data/v6.0/expected_internal_metadata.rbi +13 -7
  171. data/spec/test_data/v6.0/expected_potion.rbi +13 -7
  172. data/spec/test_data/v6.0/expected_robe.rbi +13 -7
  173. data/spec/test_data/v6.0/expected_routes.rbi +8 -0
  174. data/spec/test_data/v6.0/expected_schema_migration.rbi +13 -7
  175. data/spec/test_data/v6.0/expected_school.rbi +13 -7
  176. data/spec/test_data/v6.0/expected_spell/habtm_spell_books.rbi +13 -7
  177. data/spec/test_data/v6.0/expected_spell.rbi +13 -7
  178. data/spec/test_data/v6.0/expected_spell_book/habtm_spells.rbi +13 -7
  179. data/spec/test_data/v6.0/expected_spell_book.rbi +13 -7
  180. data/spec/test_data/v6.0/expected_squib.rbi +15 -9
  181. data/spec/test_data/v6.0/expected_subject/habtm_wizards.rbi +13 -7
  182. data/spec/test_data/v6.0/expected_subject.rbi +13 -7
  183. data/spec/test_data/v6.0/expected_wand.rbi +13 -7
  184. data/spec/test_data/v6.0/expected_wizard/habtm_subjects.rbi +13 -7
  185. data/spec/test_data/v6.0/expected_wizard.rbi +15 -9
  186. data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +15 -9
  187. data/spec/test_data/{v5.1 → v6.1}/expected_active_record_base.rbi +16 -16
  188. data/spec/test_data/{v5.1 → v6.1}/expected_active_record_relation.rbi +26 -29
  189. data/spec/test_data/{v5.0 → v6.1}/expected_application_job.rbi +0 -0
  190. data/spec/test_data/{v5.0 → v6.1}/expected_application_mailer.rbi +0 -0
  191. data/spec/test_data/v6.1/expected_attachment.rbi +334 -0
  192. data/spec/test_data/{v5.0 → v6.1}/expected_award_house_point_hourglasses.rbi +0 -0
  193. data/spec/test_data/v6.1/expected_blob.rbi +382 -0
  194. data/spec/test_data/{v5.0 → v6.1}/expected_custom_application_job.rbi +0 -0
  195. data/spec/test_data/{v5.0 → v6.1}/expected_custom_application_mailer.rbi +0 -0
  196. data/spec/test_data/{v5.0 → v6.1}/expected_custom_award_house_point_hourglasses.rbi +0 -0
  197. data/spec/test_data/{v5.0 → v6.1}/expected_custom_daily_prophet_mailer.rbi +0 -0
  198. data/spec/test_data/{v5.0 → v6.1}/expected_custom_hogwarts_acceptance_mailer.rbi +0 -0
  199. data/spec/test_data/{v5.0 → v6.1}/expected_daily_prophet_mailer.rbi +0 -0
  200. data/spec/test_data/{v5.1 → v6.1}/expected_habtm_subjects.rbi +48 -0
  201. data/spec/test_data/{v5.1 → v6.1}/expected_habtm_wizards.rbi +48 -0
  202. data/spec/test_data/{v5.1 → v6.1}/expected_headmaster.rbi +33 -3
  203. data/spec/test_data/{v5.0 → v6.1}/expected_helpers.rbi +0 -0
  204. data/spec/test_data/{v5.0 → v6.1}/expected_helpers_with_application_and_devise_helpers.rbi +0 -0
  205. data/spec/test_data/{v5.0 → v6.1}/expected_hogwarts_acceptance_mailer.rbi +0 -0
  206. data/spec/test_data/{v5.1 → v6.1}/expected_internal_metadata.rbi +33 -3
  207. data/spec/test_data/{v5.0 → v6.1}/expected_no_routes.rbi +0 -0
  208. data/spec/test_data/{v5.1 → v6.1}/expected_potion.rbi +33 -3
  209. data/spec/test_data/v6.1/expected_record.rbi +295 -0
  210. data/spec/test_data/{v5.1 → v6.1}/expected_robe.rbi +33 -3
  211. data/spec/test_data/v6.1/expected_routes.rbi +175 -0
  212. data/spec/test_data/{v5.1 → v6.1}/expected_schema_migration.rbi +33 -3
  213. data/spec/test_data/{v5.1 → v6.1}/expected_school.rbi +33 -3
  214. data/spec/test_data/{v5.1 → v6.1}/expected_spell/habtm_spell_books.rbi +33 -3
  215. data/spec/test_data/{v5.1 → v6.1}/expected_spell.rbi +33 -3
  216. data/spec/test_data/{v5.1 → v6.1}/expected_spell_book/habtm_spell_books.rbi +48 -0
  217. data/spec/test_data/{v5.1 → v6.1}/expected_spell_book/habtm_spells.rbi +33 -3
  218. data/spec/test_data/{v5.1 → v6.1}/expected_spell_book.rbi +69 -3
  219. data/spec/test_data/{v5.1 → v6.1}/expected_squib.rbi +505 -61
  220. data/spec/test_data/{v5.0 → v6.1}/expected_srb_tc_output.txt +0 -0
  221. data/spec/test_data/{v5.1 → v6.1}/expected_subject/habtm_wizards.rbi +33 -3
  222. data/spec/test_data/{v5.1 → v6.1}/expected_subject.rbi +33 -3
  223. data/spec/test_data/v6.1/expected_variant_record.rbi +370 -0
  224. data/spec/test_data/{v5.1 → v6.1}/expected_wand.rbi +99 -3
  225. data/spec/test_data/{v5.1 → v6.1}/expected_wizard/habtm_subjects.rbi +33 -3
  226. data/spec/test_data/{v5.1 → v6.1}/expected_wizard.rbi +505 -61
  227. data/spec/test_data/{v5.1 → v6.1}/expected_wizard_wo_spellbook.rbi +499 -55
  228. metadata +266 -501
  229. data/.travis.yml +0 -42
  230. data/lib/sorbet-rails/type_assert/actionpack.rbi +0 -4
  231. data/spec/support/v5.0/.gitignore +0 -21
  232. data/spec/support/v5.0/Gemfile +0 -37
  233. data/spec/support/v5.0/Gemfile.lock +0 -161
  234. data/spec/support/v5.0/app/assets/stylesheets/application.css +0 -15
  235. data/spec/support/v5.0/app/jobs/application_job.rb +0 -3
  236. data/spec/support/v5.0/app/mailers/application_mailer.rb +0 -5
  237. data/spec/support/v5.0/app/models/headmaster.rb +0 -8
  238. data/spec/support/v5.0/app/models/potion.rb +0 -6
  239. data/spec/support/v5.0/app/models/robe.rb +0 -4
  240. data/spec/support/v5.0/app/models/spell.rb +0 -5
  241. data/spec/support/v5.0/app/models/subject.rb +0 -5
  242. data/spec/support/v5.0/app/views/layouts/application.html.erb +0 -13
  243. data/spec/support/v5.0/bin/bundle +0 -3
  244. data/spec/support/v5.0/bin/setup +0 -34
  245. data/spec/support/v5.0/bin/update +0 -29
  246. data/spec/support/v5.0/config/application.rb +0 -27
  247. data/spec/support/v5.0/config/database.yml +0 -25
  248. data/spec/support/v5.0/config/environments/development.rb +0 -48
  249. data/spec/support/v5.0/config/environments/production.rb +0 -75
  250. data/spec/support/v5.0/config/environments/test.rb +0 -43
  251. data/spec/support/v5.0/config/initializers/cookies_serializer.rb +0 -6
  252. data/spec/support/v5.0/config/initializers/new_framework_defaults.rb +0 -27
  253. data/spec/support/v5.0/config/initializers/session_store.rb +0 -4
  254. data/spec/support/v5.0/config/locales/en.yml +0 -23
  255. data/spec/support/v5.0/config/puma.rb +0 -48
  256. data/spec/support/v5.0/config/routes.rb +0 -5
  257. data/spec/support/v5.0/db/migrate/20190620000001_create_wizards.rb +0 -14
  258. data/spec/support/v5.0/db/migrate/20190620000002_create_wands.rb +0 -12
  259. data/spec/support/v5.0/db/migrate/20190620000003_create_spell_books.rb +0 -10
  260. data/spec/support/v5.0/db/migrate/20190620000004_add_more_column_types_to_wands.rb +0 -17
  261. data/spec/support/v5.0/db/migrate/20190620000005_add_broom_to_wizard.rb +0 -6
  262. data/spec/support/v5.0/db/migrate/20190620000006_add_more_enums_to_wizard.rb +0 -9
  263. data/spec/support/v5.0/db/migrate/20190620000007_add_type_to_wizard.rb +0 -6
  264. data/spec/support/v5.0/db/migrate/20190620000008_add_robe_to_wizard.rb +0 -8
  265. data/spec/support/v5.0/db/migrate/20190620000009_add_school.rb +0 -10
  266. data/spec/support/v5.0/db/migrate/20190620000010_add_subject.rb +0 -8
  267. data/spec/support/v5.0/db/migrate/20190620000011_add_subjects_wizards.rb +0 -8
  268. data/spec/support/v5.0/db/migrate/20190620000012_add_spell.rb +0 -8
  269. data/spec/support/v5.0/db/migrate/20190620000013_add_spells_spell_books.rb +0 -8
  270. data/spec/support/v5.0/db/schema.rb +0 -96
  271. data/spec/support/v5.0/public/robots.txt +0 -5
  272. data/spec/support/v5.1/README.md +0 -24
  273. data/spec/support/v5.1/Rakefile +0 -6
  274. data/spec/support/v5.1/app/assets/config/manifest.js +0 -2
  275. data/spec/support/v5.1/app/controllers/application_controller.rb +0 -4
  276. data/spec/support/v5.1/app/helpers/application_helper.rb +0 -3
  277. data/spec/support/v5.1/app/helpers/bar_helper.rb +0 -3
  278. data/spec/support/v5.1/app/helpers/baz_helper.rb +0 -3
  279. data/spec/support/v5.1/app/helpers/foo_helper.rb +0 -3
  280. data/spec/support/v5.1/app/jobs/application_job.rb +0 -3
  281. data/spec/support/v5.1/app/jobs/award_house_point_hourglasses.rb +0 -12
  282. data/spec/support/v5.1/app/mailers/daily_prophet_mailer.rb +0 -9
  283. data/spec/support/v5.1/app/mailers/hogwarts_acceptance_mailer.rb +0 -29
  284. data/spec/support/v5.1/app/models/application_record.rb +0 -4
  285. data/spec/support/v5.1/app/models/concerns/.keep +0 -0
  286. data/spec/support/v5.1/app/models/concerns/mythical.rb +0 -11
  287. data/spec/support/v5.1/app/models/school.rb +0 -5
  288. data/spec/support/v5.1/app/models/spell_book.rb +0 -18
  289. data/spec/support/v5.1/app/models/squib.rb +0 -6
  290. data/spec/support/v5.1/app/models/wand.rb +0 -19
  291. data/spec/support/v5.1/app/models/wizard.rb +0 -65
  292. data/spec/support/v5.1/app/views/layouts/mailer.html.erb +0 -13
  293. data/spec/support/v5.1/app/views/layouts/mailer.text.erb +0 -1
  294. data/spec/support/v5.1/bin/bundle +0 -3
  295. data/spec/support/v5.1/bin/rails +0 -4
  296. data/spec/support/v5.1/bin/rake +0 -4
  297. data/spec/support/v5.1/bin/update +0 -29
  298. data/spec/support/v5.1/bin/yarn +0 -11
  299. data/spec/support/v5.1/config/boot.rb +0 -4
  300. data/spec/support/v5.1/config/environment.rb +0 -6
  301. data/spec/support/v5.1/config/initializers/application_controller_renderer.rb +0 -9
  302. data/spec/support/v5.1/config/initializers/backtrace_silencers.rb +0 -8
  303. data/spec/support/v5.1/config/initializers/filter_parameter_logging.rb +0 -5
  304. data/spec/support/v5.1/config/initializers/inflections.rb +0 -17
  305. data/spec/support/v5.1/config/initializers/mime_types.rb +0 -5
  306. data/spec/support/v5.1/config/initializers/sorbet_rails.rb +0 -3
  307. data/spec/support/v5.1/config/initializers/wrap_parameters.rb +0 -15
  308. data/spec/support/v5.1/config/routes.rb +0 -5
  309. data/spec/support/v5.1/config.ru +0 -5
  310. data/spec/support/v5.1/db/migrate/20190620000005_add_broom_to_wizard.rb +0 -6
  311. data/spec/support/v5.1/db/migrate/20190620000014_create_headmasters.rb +0 -9
  312. data/spec/support/v5.1/db/migrate/20190620000015_add_serialized_to_wizards.rb +0 -9
  313. data/spec/support/v5.1/db/seeds.rb +0 -8
  314. data/spec/support/v5.1/lib/assets/.keep +0 -0
  315. data/spec/support/v5.1/lib/mythical_rbi_plugin.rb +0 -16
  316. data/spec/support/v5.1/lib/tasks/.keep +0 -0
  317. data/spec/support/v5.1/log/.keep +0 -0
  318. data/spec/support/v5.1/package.json +0 -5
  319. data/spec/support/v5.1/public/robots.txt +0 -1
  320. data/spec/support/v5.1/sorbet_test_cases.rb +0 -409
  321. data/spec/support/v5.1/tmp/.keep +0 -0
  322. data/spec/support/v5.1/vendor/.keep +0 -0
  323. data/spec/test_data/v5.0/expected_active_record_base.rbi +0 -113
  324. data/spec/test_data/v5.0/expected_active_record_relation.rbi +0 -198
  325. data/spec/test_data/v5.0/expected_habtm_subjects.rbi +0 -660
  326. data/spec/test_data/v5.0/expected_habtm_wizards.rbi +0 -660
  327. data/spec/test_data/v5.0/expected_headmaster.rbi +0 -328
  328. data/spec/test_data/v5.0/expected_internal_metadata.rbi +0 -298
  329. data/spec/test_data/v5.0/expected_potion.rbi +0 -280
  330. data/spec/test_data/v5.0/expected_robe.rbi +0 -301
  331. data/spec/test_data/v5.0/expected_routes.rbi +0 -27
  332. data/spec/test_data/v5.0/expected_schema_migration.rbi +0 -271
  333. data/spec/test_data/v5.0/expected_school.rbi +0 -301
  334. data/spec/test_data/v5.0/expected_spell/habtm_spell_books.rbi +0 -319
  335. data/spec/test_data/v5.0/expected_spell.rbi +0 -292
  336. data/spec/test_data/v5.0/expected_spell_book/habtm_spell_books.rbi +0 -637
  337. data/spec/test_data/v5.0/expected_spell_book/habtm_spells.rbi +0 -319
  338. data/spec/test_data/v5.0/expected_spell_book.rbi +0 -415
  339. data/spec/test_data/v5.0/expected_squib.rbi +0 -832
  340. data/spec/test_data/v5.0/expected_subject/habtm_wizards.rbi +0 -319
  341. data/spec/test_data/v5.0/expected_subject.rbi +0 -292
  342. data/spec/test_data/v5.0/expected_wand.rbi +0 -497
  343. data/spec/test_data/v5.0/expected_wizard/habtm_subjects.rbi +0 -319
  344. data/spec/test_data/v5.0/expected_wizard.rbi +0 -908
  345. data/spec/test_data/v5.0/expected_wizard_wo_spellbook.rbi +0 -902
  346. data/spec/test_data/v5.1/expected_application_job.rbi +0 -20
  347. data/spec/test_data/v5.1/expected_application_mailer.rbi +0 -5
  348. data/spec/test_data/v5.1/expected_award_house_point_hourglasses.rbi +0 -20
  349. data/spec/test_data/v5.1/expected_custom_application_job.rbi +0 -21
  350. data/spec/test_data/v5.1/expected_custom_application_mailer.rbi +0 -6
  351. data/spec/test_data/v5.1/expected_custom_award_house_point_hourglasses.rbi +0 -21
  352. data/spec/test_data/v5.1/expected_custom_daily_prophet_mailer.rbi +0 -8
  353. data/spec/test_data/v5.1/expected_custom_hogwarts_acceptance_mailer.rbi +0 -21
  354. data/spec/test_data/v5.1/expected_daily_prophet_mailer.rbi +0 -7
  355. data/spec/test_data/v5.1/expected_helpers.rbi +0 -27
  356. data/spec/test_data/v5.1/expected_helpers_with_application_and_devise_helpers.rbi +0 -34
  357. data/spec/test_data/v5.1/expected_hogwarts_acceptance_mailer.rbi +0 -20
  358. data/spec/test_data/v5.1/expected_no_routes.rbi +0 -4
  359. data/spec/test_data/v5.1/expected_routes.rbi +0 -27
  360. data/spec/test_data/v5.1/expected_srb_tc_output.txt +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33c9dda20b44067f6f788873f626fd9d2fdf5bbe8a62d8c374e2748b637f5993
4
- data.tar.gz: e2d65d1ec7c2e03d7135d7de8540b859c6348d27382732893fff611a5b627d88
3
+ metadata.gz: 99ef9d97be5d8b7c9ce91c26827337bb0cf170a704d0e1c025a1a47964b8f0cd
4
+ data.tar.gz: 831bc3d6fc4aafd8e0f4ea315369a410b3dbd90669a8bbd5b5f059fe9ce6543b
5
5
  SHA512:
6
- metadata.gz: 86a4cc741bef3972a5a8cb3a77d1eaa1f1fe4924d816c5ba681bf6fe5b5d91d0b6e94410a2a08fe15b8d696b80e50b7ff7f4c5a049e58a841fa9d2ecd83fd9c0
7
- data.tar.gz: 6120f8d8fdf6e631f92cf6428774cd6df1a410d64282d96ed4921202c1715e2211e15823a510234849615cb7e3dc08368121fd663ad1ab9148ad337123799dca
6
+ metadata.gz: 7309e5f22a4f7979ff5665c0d17d2c22bf823d9bbb4d6468668d6df0ad5b6e4243a300974e5b289c8314adbfc40f04d889a3d4a69a1d932b443d5ae688a11256
7
+ data.tar.gz: '06496c5b1cf2b7e688fb100cba9d3dfae8baded69712b0a8b2e4adfbef27ec93dca88205813776c9905329ac17e118bb871c19a2d6abfbaff1dce006c27eda3d'
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ # Files stored in repository root
5
+ directory: "/"
6
+ schedule:
7
+ interval: "daily"
@@ -0,0 +1,28 @@
1
+ name: ci-master
2
+
3
+ on:
4
+ push:
5
+ branches: # Trigger only on the main branch to avoid duplicate runs on PR branches
6
+ - master
7
+
8
+ jobs:
9
+ rspec:
10
+ runs-on: ubuntu-latest
11
+
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby: [2.5, 2.6, 2.7]
16
+ rails: [5.2, 6.0, 6.1]
17
+
18
+ env:
19
+ RAILS_VERSION: ${{ matrix.rails }}
20
+ CI: true
21
+
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ # bundler-cache: true -- this messes up some dynamic constants
28
+ - run: "./spec/bin/run_spec.sh"
@@ -0,0 +1,26 @@
1
+ name: ci
2
+
3
+ on:
4
+ pull_request: # Trigger All PRs
5
+
6
+ jobs:
7
+ rspec:
8
+ runs-on: ubuntu-latest
9
+
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby: [2.5, 2.6, 2.7]
14
+ rails: [5.2, 6.0, 6.1]
15
+
16
+ env:
17
+ RAILS_VERSION: ${{ matrix.rails }}
18
+
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ # bundler-cache: true -- this messes up some dynamic constants
25
+ - run: "./spec/bin/run_spec.sh"
26
+ - run: bundle exec srb tc
@@ -0,0 +1,27 @@
1
+ name: publish-gem
2
+
3
+ on:
4
+ # pull_request: # test with pull request
5
+ push:
6
+ branches: # Trigger only on the main branch to avoid duplicate runs on PR branches
7
+ - master
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ env:
14
+ RAILS_VERSION: 6.0
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: 2.7
21
+ # bundler-cache: true -- this messes up some dynamic constants
22
+ - run: "./spec/bin/run_spec.sh"
23
+ - run: bundle exec srb tc
24
+ - name: Release Gem
25
+ uses: dawidd6/action-publish-gem@v1
26
+ with:
27
+ api_key: ${{secrets.RUBYGEMS_API_KEY}}
data/CONTRIBUTING.md CHANGED
@@ -87,10 +87,9 @@ To run the tests against all supported Rails branches, use:
87
87
  You can also switch to a version of Rails with `RAILS_VERSION`:
88
88
 
89
89
  ```sh
90
- ❯ RAILS_VERSION=5.0 ./spec/bin/run_spec.sh
91
- ❯ RAILS_VERSION=5.1 ./spec/bin/run_spec.sh
92
90
  ❯ RAILS_VERSION=5.2 ./spec/bin/run_spec.sh
93
91
  ❯ RAILS_VERSION=6.0 ./spec/bin/run_spec.sh
92
+ ❯ RAILS_VERSION=6.1 ./spec/bin/run_spec.sh
94
93
  ```
95
94
 
96
95
  #### Debugging
data/Gemfile CHANGED
@@ -13,14 +13,6 @@ case rails_version
13
13
  when "master"
14
14
  gem "rails", {github: "rails/rails"}
15
15
  gem "bundler", ">= 1.3.0"
16
- when "5.0"
17
- gem "rails", "~> 5.0.7"
18
- gem "bundler", ">= 2.0"
19
- gem "sqlite3", "~> 1.3.6"
20
- when "5.1"
21
- gem "rails", "~> 5.1.7"
22
- gem "bundler", ">= 2.0"
23
- gem "sqlite3", "~> 1.4.1"
24
16
  when "5.2"
25
17
  gem "rails", "~> 5.2.3"
26
18
  gem "bundler", ">= 2.0"
@@ -29,8 +21,12 @@ when "6.0"
29
21
  gem "rails", "~> 6.0.0"
30
22
  gem "bundler", ">= 2.0"
31
23
  gem "sqlite3", "~> 1.4.1"
24
+ when "6.1"
25
+ gem "rails", "~> 6.1.0"
26
+ gem "bundler", ">= 2.0"
27
+ gem "sqlite3", "~> 1.4.1"
32
28
  else
33
- gem "rails", "~> 5.2.3"
29
+ gem "rails", "~> 6.0.0"
34
30
  gem "bundler", ">= 2.0"
35
31
  gem "sqlite3", "~> 1.4.1"
36
32
  end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # sorbet-rails
2
2
  [![Gem Version](https://badge.fury.io/rb/sorbet-rails.svg)](https://badge.fury.io/rb/sorbet-rails)
3
- [![Build Status](https://travis-ci.com/chanzuckerberg/sorbet-rails.svg?branch=master)](https://travis-ci.com/chanzuckerberg/sorbet-rails)
3
+ [![Build Status](https://github.com/chanzuckerberg/sorbet-rails/actions/workflows/ci-master.yml/badge.svg)](https://github.com/chanzuckerberg/sorbet-rails)
4
4
  [![codecov](https://codecov.io/gh/chanzuckerberg/sorbet-rails/branch/master/graph/badge.svg)](https://codecov.io/gh/chanzuckerberg/sorbet-rails)
5
5
 
6
6
  A set of tools to make the [Sorbet](https://sorbet.org) typechecker work with Ruby on Rails seamlessly.
@@ -9,6 +9,8 @@ This gem adds a few Rake tasks to generate Ruby Interface (RBI) files for dynami
9
9
 
10
10
  `sorbet-rails` supports Rails 5+ or later.
11
11
 
12
+ **Notice**: we automatically creates a new release on Rubygems with every merges to the master branch
13
+
12
14
  **Notice**: we no longer support Rails 4.2. [Version 0.5.6](https://github.com/chanzuckerberg/sorbet-rails/releases/tag/v0.5.6) is the last version supporting Rails 4.2.
13
15
 
14
16
  ## Initial Setup
@@ -206,7 +208,7 @@ end
206
208
  ❯ bundle exec rake rails_rbi:custom
207
209
  ```
208
210
 
209
- `sorbet-rails` adds `TypedParams` to extact typed controller parameters.
211
+ `sorbet-rails` adds `TypedParams` to extract typed controller parameters.
210
212
 
211
213
  TypedParams takes a parameter definition, which is a subclass of `T::Struct` and coerces the `params` object into an instance of that subclass using [sorbet-coerce](https://github.com/chanzuckerberg/sorbet-coerce):
212
214
  ```ruby
@@ -311,7 +313,7 @@ It is worth going through the list of files that is ignored and resolve them (an
311
313
 
312
314
  ### Overriding generated signatures if needed
313
315
 
314
- `sorbet-rails` relies on Rails reflection to generate signatures. There are features this gem doesn't support yet such as [serialize](https://github.com/chanzuckerberg/sorbet-rails/issues/49) and [attribute custom types](https://github.com/chanzuckerberg/sorbet-rails/issues/16). The gem also doesn't know the signature of any methods you have overridden. However, it is possible to override the signatures that `sorbet-rails` generates.
316
+ `sorbet-rails` relies on Rails reflection to generate signatures. There are features this gem doesn't support yet such as [attribute custom types](https://github.com/chanzuckerberg/sorbet-rails/issues/16). The gem also doesn't know the signature of any methods you have overridden. However, it is possible to override the signatures that `sorbet-rails` generates.
315
317
 
316
318
  For example, here is how to override the signature for a method in a model:
317
319
 
@@ -409,8 +411,16 @@ Model.unscoped.scoping do … end
409
411
 
410
412
  ### `select` with a block
411
413
 
412
- The [`select` method](https://apidock.com/rails/v4.0.2/ActiveRecord/QueryMethods/select) in Rails has two modes: it can be given a list of symbols, in which case rails will only return the given columns from the database, or it can be given a block, in which case it acts like [`Enumerable.select`](https://ruby-doc.org/core-2.6.4/Enumerable.html) and returns an array. We have chosen to support the first use case. If you want to pass a block to `select`, you can simply call `to_a` before you do. Note that this would be done within the `select` call anyway, so the performance penalty will be minimal.
414
+ The [`select` method](https://apidock.com/rails/v4.0.2/ActiveRecord/QueryMethods/select) in Rails has two modes: it can be given a list of symbols, in which case rails will only return the given columns from the database, or it can be given a block, in which case it acts like [`Enumerable.select`](https://ruby-doc.org/core-2.6.4/Enumerable.html) and returns an array.
415
+
416
+ We have chosen to support `select` with a block as the primary use case, since it is a more prevalent use of this method. We provide `select_columns` as an alternative if you want to select a list of columns.
413
417
 
418
+ ```
419
+ Model.select { |record| record.id > 1} # valid, returns an array
420
+ Model.select_columns(:id, :name) # valid, returns an association
421
+
422
+ Model.select(:id, :name) # sorbet error, use `select_column` instead
423
+ ```
414
424
  ### `flatten` an array of relation
415
425
 
416
426
  When you call `flatten` on an array of ActiveRecord::Relation, sorbet [doesn't recognize](https://github.com/sorbet/sorbet/issues/2767) that it will flatten the relation and return an array of model. The work around is to call `to_a` on the relation first.
@@ -524,6 +534,8 @@ These are the currently-supported gems and their symbolized names:
524
534
  | [Paperclip] | `:paperclip` |
525
535
  | [AttrJson] | `:attr_json` |
526
536
  | [FlagShihTzu] | `:flag_shih_tzu` |
537
+ | [AASM] | `:aasm` |
538
+ | [Money-Rails] | `:money_rails` |
527
539
 
528
540
  You can also configure the core model plugins if needed. The default plugins are defined in the [config](https://github.com/chanzuckerberg/sorbet-rails/blob/master/lib/sorbet-rails/config.rb). For the full list of plugin symbols, check out [here](https://github.com/chanzuckerberg/sorbet-rails/blob/master/lib/sorbet-rails/model_plugins/plugins.rb).
529
541
 
@@ -537,6 +549,8 @@ You can also configure the core model plugins if needed. The default plugins are
537
549
  [Paperclip]: https://github.com/thoughtbot/paperclip
538
550
  [AttrJson]: https://github.com/jrochkind/attr_json
539
551
  [FlagShihTzu]: https://github.com/pboling/flag_shih_tzu
552
+ [AASM]: https://github.com/aasm/aasm
553
+ [Money-Rails]: https://github.com/RubyMoney/money-rails
540
554
 
541
555
  ### Customize Generation Class
542
556
 
data/Rakefile CHANGED
@@ -10,13 +10,22 @@ namespace :update_spec do
10
10
 
11
11
  desc "Generate Rails apps for all versions."
12
12
  task :all do |t, args|
13
+ Rake::Task['update_spec:v6_1'].invoke
13
14
  Rake::Task['update_spec:v6_0'].invoke
14
15
  Rake::Task['update_spec:v5_2'].invoke
15
- Rake::Task['update_spec:v5_1'].invoke
16
- Rake::Task['update_spec:v5_0'].invoke
17
16
  end
18
17
 
19
- desc "Delete the Rails 6 spec directory and regenerate it."
18
+ desc "Delete the Rails 6.1 spec directory and regenerate it."
19
+ task :v6_1 do |t, args|
20
+ Bundler.with_clean_env do
21
+ FileUtils.rm_rf 'spec/support/v6.1' if File.directory?('spec/support/v6.1')
22
+ system("gem install rails -v 6.1.4")
23
+ system("rails _6.1.4_ -v")
24
+ system("RAILS_VERSION='6.1' rails _6.1.4_ new --template spec/generators/rails-template.rb spec/support/v6.0 --skip-javascript --skip-action-cable --skip-test --skip-sprockets --skip-spring --skip-bootsnap --skip-listen")
25
+ end
26
+ end
27
+
28
+ desc "Delete the Rails 6.0 spec directory and regenerate it."
20
29
  task :v6_0 do |t, args|
21
30
  Bundler.with_clean_env do
22
31
  FileUtils.rm_rf 'spec/support/v6.0' if File.directory?('spec/support/v6.0')
@@ -36,29 +45,9 @@ namespace :update_spec do
36
45
  end
37
46
  end
38
47
 
39
- desc "Delete the Rails 5.1 spec directory and regenerate it."
40
- task :v5_1 do |t, args|
41
- Bundler.with_clean_env do
42
- FileUtils.rm_rf 'spec/support/v5.1' if File.directory?('spec/support/v5.1')
43
- system("gem install rails -v 5.1.7")
44
- system("rails _5.1.7_ -v")
45
- system("RAILS_VERSION='5.1' rails _5.1.7_ new --template spec/generators/rails-template.rb spec/support/v5.1 --skip-javascript --skip-action-cable --skip-test --skip-sprockets --skip-spring --skip-listen")
46
- end
47
- end
48
-
49
- desc "Delete the Rails 5.0 spec directory and regenerate it."
50
- task :v5_0 do |t, args|
51
- Bundler.with_clean_env do
52
- FileUtils.rm_rf 'spec/support/v5.0' if File.directory?('spec/support/v5.0')
53
- system("gem install rails -v 5.0.7")
54
- system("rails _5.0.7_ -v")
55
- system("RAILS_VERSION='5.0' rails _5.0.7_ new --template spec/generators/rails-template.rb spec/support/v5.0 --skip-javascript --skip-action-cable --skip-test --skip-sprockets --skip-spring --skip-listen")
56
- end
57
- end
58
-
59
48
  desc "Update sorbet_test_cases.rb in all the Rails apps in spec/support."
60
49
  task :sorbet_test_cases do |t, args|
61
- ['v6.0', 'v5.2', 'v5.1', 'v5.0'].each do |version|
50
+ ['v6.1', 'v6.0', 'v5.2'].each do |version|
62
51
  FileUtils.cp("spec/generators/sorbet_test_cases.rb", "spec/support/#{version}/sorbet_test_cases.rb")
63
52
  end
64
53
  end
@@ -273,6 +273,18 @@ class SorbetRails::ActiveRecordRbiFormatter
273
273
  class_method: class_method,
274
274
  )
275
275
  end
276
+
277
+ boolean_methods = %w(any? many? none? one?)
278
+ boolean_methods.each do |boolean_method|
279
+ class_rbi.create_method(
280
+ boolean_method,
281
+ parameters: [
282
+ Parameter.new("&block", type: "T.nilable(T.proc.params(e: #{type}).returns(T.nilable(T::Boolean)))"),
283
+ ],
284
+ return_type: "T::Boolean",
285
+ class_method: class_method,
286
+ )
287
+ end
276
288
  end
277
289
 
278
290
  sig {
@@ -288,14 +300,5 @@ class SorbetRails::ActiveRecordRbiFormatter
288
300
  return_type: "T::Boolean",
289
301
  class_method: class_method,
290
302
  )
291
-
292
- boolean_methods = %w(any? many? none? one?)
293
- boolean_methods.each do |boolean_method|
294
- class_rbi.create_method(
295
- boolean_method,
296
- return_type: "T::Boolean",
297
- class_method: class_method,
298
- )
299
- end
300
303
  end
301
304
  end
@@ -42,3 +42,7 @@ module ActiveModel::Validations
42
42
  def validators_on(*attributes); end
43
43
  end
44
44
  end
45
+
46
+ class ActiveRecord::Type::Serialized
47
+ def coder; end
48
+ end
@@ -1,4 +1,4 @@
1
- # typed: strong
1
+ # typed: ignore
2
2
  module Kernel
3
3
  end
4
4
 
@@ -0,0 +1,50 @@
1
+ # typed: false
2
+ class AasmPlugin < SorbetRails::ModelPlugins::Base
3
+ sig { override.params(root: Parlour::RbiGenerator::Namespace).void }
4
+ def generate(root)
5
+ return unless @model_class.include?(::AASM)
6
+
7
+ model_rbi = root.create_class(
8
+ model_class_name
9
+ )
10
+
11
+ aasm_events = @model_class.aasm.events.map(&:name)
12
+ aasm_states = @model_class.aasm.states.map(&:name)
13
+
14
+ # If you have an event like :bazify, you get these methods:
15
+ # - `may_bazify?`
16
+ # - `bazify`
17
+ # - `bazify!`
18
+ # - `bazify_without_validation!`
19
+ aasm_events.each do |event|
20
+ model_rbi.create_method(
21
+ "may_#{event}?",
22
+ return_type: 'T::Boolean'
23
+ )
24
+
25
+ model_rbi.create_method(
26
+ event.to_s,
27
+ return_type: 'T::Boolean'
28
+ )
29
+
30
+ model_rbi.create_method(
31
+ "#{event}!",
32
+ return_type: 'T::Boolean'
33
+ )
34
+
35
+ model_rbi.create_method(
36
+ "#{event}_without_validation!",
37
+ return_type: 'T::Boolean'
38
+ )
39
+ end
40
+
41
+ # - If you have a state like :baz, you get these methods:
42
+ # - `baz?`
43
+ aasm_states.each do |state|
44
+ model_rbi.create_method(
45
+ "#{state}?",
46
+ return_type: 'T::Boolean'
47
+ )
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,76 @@
1
+ # typed: strict
2
+ class MoneyRailsPlugin < SorbetRails::ModelPlugins::Base
3
+ sig { params(attribute: T.any(Symbol, String)).returns(T::Boolean) }
4
+ def allows_nil(attribute)
5
+ validators = model_class.validators_on(attribute)
6
+ return false if validators.empty?
7
+
8
+ validators.any? do |validator|
9
+ validator.respond_to?(:options) &&
10
+ validator.options[:allow_nil]
11
+ end
12
+ end
13
+
14
+ sig { override.params(root: Parlour::RbiGenerator::Namespace).void }
15
+ def generate(root)
16
+ return unless exists_class_method?(:monetize)
17
+
18
+ # money-rails gives us a hash mapping the monetized attribute to its subunit
19
+ # equivalent, eg: `{"price": "price_cents"}`
20
+ monetized_attributes = T.let(
21
+ T.unsafe(model_class).monetized_attributes,
22
+ T::Hash[String,String]
23
+ )
24
+
25
+ return if monetized_attributes.empty?
26
+
27
+ module_name = model_module_name("GeneratedMoneyRailsMethods")
28
+ module_rbi = root.create_module(module_name)
29
+
30
+ model_class_rbi = root.create_class(model_class_name)
31
+ model_class_rbi.create_include(module_name)
32
+
33
+ monetized_attributes.each do |name, subunit_name|
34
+ validators = model_class.validators_on(name)
35
+
36
+ money_attribute_type = allows_nil(name) ? "T.nilable(::Money)" : "::Money"
37
+ subunit_attribute_type = allows_nil(name) ? "T.nilable(Integer)" : "Integer"
38
+
39
+ module_rbi.create_method(
40
+ name,
41
+ return_type: money_attribute_type
42
+ )
43
+
44
+ module_rbi.create_method(
45
+ subunit_name,
46
+ return_type: subunit_attribute_type
47
+ )
48
+
49
+ module_rbi.create_method(
50
+ "#{name}_money_before_type_cast",
51
+ return_type: 'T.untyped'
52
+ )
53
+
54
+ module_rbi.create_method(
55
+ "#{name}=",
56
+ parameters: [
57
+ Parlour::RbiGenerator::Parameter.new("value", type: money_attribute_type)
58
+ ],
59
+ return_type: nil
60
+ )
61
+
62
+ module_rbi.create_method(
63
+ "#{subunit_name}=",
64
+ parameters: [
65
+ Parlour::RbiGenerator::Parameter.new("value", type: subunit_attribute_type)
66
+ ],
67
+ return_type: nil
68
+ )
69
+
70
+ module_rbi.create_method(
71
+ "currency_for_#{name}",
72
+ return_type: "T.nilable(::Money::Currency)"
73
+ )
74
+ end
75
+ end
76
+ end
@@ -80,7 +80,7 @@ module SorbetRails
80
80
 
81
81
  sig { returns(String) }
82
82
  def generate_rbi
83
- puts "-- Generate sigs for mailer #{@job_class.name} --"
83
+ puts "-- Generate sigs for ActiveJob #{@job_class.name} --"
84
84
  populate_rbi
85
85
  @rbi_generator.rbi
86
86
  end
@@ -25,7 +25,8 @@ class SorbetRails::ModelPlugins::ActiveRecordQuerying < SorbetRails::ModelPlugin
25
25
  # <Model>::Relation class.
26
26
  # rails/activerecord/lib/active_record/querying.rb
27
27
  model_query_relation_methods = [
28
- :select, :reselect, :order, :reorder, :group, :limit, :offset, :joins, :left_joins, :left_outer_joins,
28
+ # :select,
29
+ :reselect, :order, :reorder, :group, :limit, :offset, :joins, :left_joins, :left_outer_joins,
29
30
  :where, :rewhere, :preload, :extract_associated, :eager_load, :includes, :from, :lock, :readonly, :or,
30
31
  :having, :create_with, :distinct, :references, :none, :unscope, :optimizer_hints, :merge, :except, :only,
31
32
  ]
@@ -39,6 +40,29 @@ class SorbetRails::ModelPlugins::ActiveRecordQuerying < SorbetRails::ModelPlugin
39
40
  builtin_query_method: true,
40
41
  ) if exists_class_method?(method_name)
41
42
  end
43
+ if exists_class_method?("select")
44
+ # `select` can be used with a block to return an array, or with a list of column name
45
+ # to return a relation object that can be chained.
46
+ # I've seen usage of `select` with a block more often than with a list of column name.
47
+ # here we define select as taking a block, and add a `select_column` method for the other usage
48
+ add_relation_query_method(
49
+ root,
50
+ "select",
51
+ parameters: [
52
+ Parameter.new("&block", type: "T.proc.params(e: #{self.model_class_name}).returns(T::Boolean)"),
53
+ ],
54
+ builtin_query_method: true,
55
+ custom_return_value: "T::Array[#{self.model_class_name}]",
56
+ )
57
+ add_relation_query_method(
58
+ root,
59
+ "select_columns", # select_column is injected by sorbet-rails
60
+ parameters: [
61
+ Parameter.new("*args", type: "T.any(String, Symbol, T::Array[T.any(String, Symbol)])"),
62
+ ],
63
+ builtin_query_method: true,
64
+ )
65
+ end
42
66
 
43
67
  add_relation_query_method(
44
68
  root,
@@ -60,9 +60,10 @@ class SorbetRails::ModelPlugins::ActiveRecordSerializedAttribute < SorbetRails::
60
60
  # ActiveSupport::JSON.encode/ActiveSupport::JSON.decode
61
61
  # note that Hash keys are Strings since this is JSON
62
62
  'T.any(T::Array[T.untyped], T::Boolean, Float, T::Hash[String, T.untyped], Integer, String)'
63
- else
64
- # unknown uses YAML.load/YAML.dump
63
+ when 'Object', ''
65
64
  'T.any(T::Array[T.untyped], T::Boolean, Float, T::Hash[T.untyped, T.untyped], Integer, String)'
65
+ else
66
+ serialization_coder.to_s
66
67
  end
67
68
  end
68
69
  end
@@ -35,7 +35,14 @@ module SorbetRails::ModelPlugins
35
35
  column_type = @model_class.type_for_attribute(column_name)
36
36
  return unless column_type.is_a?(ActiveRecord::Type::Serialized)
37
37
 
38
- column_type.coder.try(:object_class) || Object
38
+ object_class = column_type.coder.try(:object_class)
39
+ if object_class
40
+ object_class
41
+ elsif column_type.coder.is_a? Class
42
+ column_type.coder
43
+ else
44
+ Object
45
+ end
39
46
  end
40
47
  end
41
48
  end
@@ -39,7 +39,7 @@ class SorbetRails::ModelPlugins::CustomFinderMethods < SorbetRails::ModelPlugins
39
39
  # allow common cases find_by_id
40
40
  custom_module_rbi.create_method(
41
41
  "find_by_id",
42
- parameters: [ Parameter.new("id", type: "Integer") ],
42
+ parameters: [ Parameter.new("id", type: "T.nilable(Integer)") ],
43
43
  return_type: "T.nilable(#{self.model_class_name})",
44
44
  )
45
45
  custom_module_rbi.create_method(
@@ -87,6 +87,12 @@ module SorbetRails::ModelPlugins
87
87
  when :flag_shih_tzu
88
88
  require('sorbet-rails/gem_plugins/flag_shih_tzu_plugin')
89
89
  FlagShihTzuPlugin
90
+ when :aasm
91
+ require('sorbet-rails/gem_plugins/aasm_plugin')
92
+ AasmPlugin
93
+ when :money_rails
94
+ require('sorbet-rails/gem_plugins/money_rails_plugin')
95
+ MoneyRailsPlugin
90
96
  else
91
97
  raise UnrecognizedPluginName.new(
92
98
  "Unrecognized plugin with name: #{plugin_name}. Please check available plugins in the
@@ -90,9 +90,16 @@ module SorbetRails::ModelUtils
90
90
  # where, limit, etc and not something like a named scope. It should likely
91
91
  # only be set to `true` when called from the ActiveRecordQuerying plugin.
92
92
  builtin_query_method: T::Boolean,
93
+ custom_return_value: T.nilable(String),
93
94
  ).void
94
95
  }
95
- def add_relation_query_method(root, method_name, parameters: nil, builtin_query_method: false)
96
+ def add_relation_query_method(
97
+ root,
98
+ method_name,
99
+ parameters: nil,
100
+ builtin_query_method: false,
101
+ custom_return_value: nil
102
+ )
96
103
  # a relation querying method will be available on
97
104
  # - model (as a class method)
98
105
  # - activerecord relation
@@ -114,14 +121,14 @@ module SorbetRails::ModelUtils
114
121
  relation_module_rbi.create_method(
115
122
  method_name,
116
123
  parameters: parameters,
117
- return_type: self.model_relation_class_name,
124
+ return_type: custom_return_value || self.model_relation_class_name,
118
125
  )
119
126
 
120
127
  assoc_relation_module_rbi = root.create_module(self.model_query_methods_returning_assoc_relation_module_name)
121
128
  assoc_relation_module_rbi.create_method(
122
129
  method_name,
123
130
  parameters: parameters,
124
- return_type: assoc_return_value,
131
+ return_type: custom_return_value || assoc_return_value,
125
132
  )
126
133
  else
127
134
  # force generating these methods because sorbet's hidden-definitions generate & override them
@@ -129,7 +136,7 @@ module SorbetRails::ModelUtils
129
136
  model_class_rbi.create_method(
130
137
  method_name,
131
138
  parameters: parameters,
132
- return_type: self.model_relation_class_name,
139
+ return_type: custom_return_value || self.model_relation_class_name,
133
140
  class_method: true,
134
141
  )
135
142
 
@@ -137,21 +144,21 @@ module SorbetRails::ModelUtils
137
144
  model_relation_rbi.create_method(
138
145
  method_name,
139
146
  parameters: parameters,
140
- return_type: self.model_relation_class_name,
147
+ return_type: custom_return_value || self.model_relation_class_name,
141
148
  )
142
149
 
143
150
  model_assoc_relation_rbi = root.create_class(self.model_assoc_relation_class_name)
144
151
  model_assoc_relation_rbi.create_method(
145
152
  method_name,
146
153
  parameters: parameters,
147
- return_type: assoc_return_value,
154
+ return_type: custom_return_value || assoc_return_value,
148
155
  )
149
156
 
150
157
  collection_proxy_rbi = root.create_class(self.model_assoc_proxy_class_name)
151
158
  collection_proxy_rbi.create_method(
152
159
  method_name,
153
160
  parameters: parameters,
154
- return_type: assoc_return_value,
161
+ return_type: custom_return_value || assoc_return_value,
155
162
  )
156
163
  end
157
164
  end
@@ -13,6 +13,10 @@ module SorbetRails
13
13
  last(n)
14
14
  end
15
15
 
16
+ def select_columns(*args)
17
+ select(*args)
18
+ end
19
+
16
20
  # Redeclare these dynamic methods here otherwise they will be generated by
17
21
  # `srb rbi hidden-definitions`
18
22
  def find_by_id(id)
@@ -1,4 +1,4 @@
1
- # typed: true
1
+ # typed: false
2
2
  require "rails"
3
3
  require "sorbet-runtime"
4
4
  require "sorbet-rails/config"
@@ -39,6 +39,14 @@ class SorbetRails::RoutesRbiFormatter
39
39
  @parlour.root.create_class('ActionMailer::Base') do |mod|
40
40
  mod.create_include('GeneratedUrlHelpers')
41
41
  end
42
+
43
+ @parlour.root.create_class('ActionDispatch::IntegrationTest') do |mod|
44
+ mod.create_include('GeneratedUrlHelpers')
45
+ end
46
+
47
+ @parlour.root.create_class('ActionDispatch::SystemTestCase') do |mod|
48
+ mod.create_include('GeneratedUrlHelpers')
49
+ end
42
50
  end
43
51
 
44
52
  sig { params(routes: T.untyped, filter: T.untyped).void }