sorbet-rails 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (404) hide show
  1. checksums.yaml +4 -4
  2. data/.codecov.yml +4 -0
  3. data/.github/ISSUE_TEMPLATE/bug.md +26 -0
  4. data/.gitignore +5 -0
  5. data/.travis.yml +26 -7
  6. data/CONTRIBUTING.md +135 -0
  7. data/Gemfile +29 -11
  8. data/README.md +40 -7
  9. data/lib/sorbet-rails/custom_finder_methods.rb +1 -1
  10. data/lib/sorbet-rails/model_rbi_formatter.rb +72 -41
  11. data/lib/sorbet-rails/routes_rbi_formatter.rb +6 -14
  12. data/lib/sorbet-rails/tasks/rails_rbi.rake +13 -6
  13. data/rbi/activerecord.rbi +32 -7
  14. data/sorbet-rails.gemspec +2 -4
  15. data/spec/bin/install.sh +11 -0
  16. data/spec/bin/run_all_specs.sh +9 -5
  17. data/spec/bin/run_spec.sh +33 -0
  18. data/spec/bin/{reset_test_data.sh → update_test_data.sh} +2 -1
  19. data/spec/custom_finder_methods_spec.rb +75 -0
  20. data/spec/model_rbi_formatter_spec.rb +8 -6
  21. data/spec/rails_helper.rb +32 -5
  22. data/spec/rake_helper.rb +47 -0
  23. data/spec/rake_rails_rbi_models_spec.rb +64 -0
  24. data/spec/rake_rails_rbi_routes_spec.rb +15 -0
  25. data/spec/support/rails_shared/app/models/wizard.rb +4 -4
  26. data/spec/support/rails_shared/db/migrate/20190620001234_create_wizards.rb +1 -1
  27. data/spec/support/rails_shared/db/migrate/20190620003037_create_wands.rb +1 -1
  28. data/spec/support/rails_shared/db/migrate/20190620003739_create_spell_books.rb +1 -1
  29. data/spec/support/rails_shared/db/migrate/20190622000000_add_more_column_types_to_wands.rb +5 -3
  30. data/spec/support/rails_symlinks/app/controllers +1 -0
  31. data/spec/support/rails_symlinks/app/models +1 -0
  32. data/spec/support/rails_symlinks/config/routes.rb +5 -0
  33. data/spec/support/rails_symlinks/db/migrate +1 -0
  34. data/spec/support/v4.2/.gitignore +17 -0
  35. data/spec/support/v4.2/Gemfile +31 -0
  36. data/spec/support/v4.2/README.rdoc +28 -0
  37. data/spec/support/v4.2/Rakefile +6 -0
  38. data/spec/support/{5.1.7/lib/tasks → v4.2/app/assets/images}/.keep +0 -0
  39. data/spec/support/v4.2/app/assets/stylesheets/application.css +15 -0
  40. data/spec/support/v4.2/app/controllers/application_controller.rb +5 -0
  41. data/spec/support/{5.1.7/log → v4.2/app/controllers/concerns}/.keep +0 -0
  42. data/spec/support/v4.2/app/helpers/application_helper.rb +2 -0
  43. data/spec/support/{5.1.7/test/controllers → v4.2/app/mailers}/.keep +0 -0
  44. data/spec/support/v4.2/app/models +1 -0
  45. data/spec/support/v4.2/app/views/layouts/application.html.erb +13 -0
  46. data/spec/support/{5.1.7 → v4.2}/bin/bundle +0 -0
  47. data/spec/support/v4.2/bin/rails +4 -0
  48. data/spec/support/v4.2/bin/rake +4 -0
  49. data/spec/support/v4.2/bin/setup +29 -0
  50. data/spec/support/v4.2/config.ru +4 -0
  51. data/spec/support/v4.2/config/application.rb +35 -0
  52. data/spec/support/v4.2/config/boot.rb +3 -0
  53. data/spec/support/v4.2/config/database.yml +25 -0
  54. data/spec/support/v4.2/config/environment.rb +5 -0
  55. data/spec/support/v4.2/config/environments/development.rb +28 -0
  56. data/spec/support/v4.2/config/environments/production.rb +67 -0
  57. data/spec/support/v4.2/config/environments/test.rb +42 -0
  58. data/spec/support/{5.1.7 → v4.2}/config/initializers/backtrace_silencers.rb +0 -0
  59. data/spec/support/v4.2/config/initializers/cookies_serializer.rb +3 -0
  60. data/spec/support/{5.1.7 → v4.2}/config/initializers/filter_parameter_logging.rb +0 -0
  61. data/spec/support/{5.1.7 → v4.2}/config/initializers/inflections.rb +0 -0
  62. data/spec/support/{5.1.7 → v4.2}/config/initializers/mime_types.rb +0 -0
  63. data/spec/support/v4.2/config/initializers/session_store.rb +3 -0
  64. data/spec/support/v4.2/config/initializers/to_time_preserves_timezone.rb +10 -0
  65. data/spec/support/v4.2/config/initializers/wrap_parameters.rb +14 -0
  66. data/spec/support/v4.2/config/locales/en.yml +23 -0
  67. data/spec/support/v4.2/config/routes.rb +5 -0
  68. data/spec/support/v4.2/config/secrets.yml +22 -0
  69. data/spec/support/v4.2/db/migrate/20190620001234_create_wizards.rb +12 -0
  70. data/spec/support/v4.2/db/migrate/20190620003037_create_wands.rb +11 -0
  71. data/spec/support/v4.2/db/migrate/20190620003739_create_spell_books.rb +8 -0
  72. data/spec/support/v4.2/db/migrate/20190622000000_add_more_column_types_to_wands.rb +10 -0
  73. data/spec/support/v4.2/db/schema.rb +44 -0
  74. data/spec/support/v4.2/db/seeds.rb +7 -0
  75. data/spec/support/{5.1.7/test/fixtures → v4.2/lib/assets}/.keep +0 -0
  76. data/spec/support/{5.1.7/test/fixtures/files → v4.2/lib/tasks}/.keep +0 -0
  77. data/spec/support/{5.1.7/test/integration → v4.2/log}/.keep +0 -0
  78. data/spec/support/v4.2/public/404.html +67 -0
  79. data/spec/support/v4.2/public/422.html +67 -0
  80. data/spec/support/v4.2/public/500.html +66 -0
  81. data/spec/support/{5.1.7/test/mailers/.keep → v4.2/public/favicon.ico} +0 -0
  82. data/spec/support/v4.2/public/robots.txt +5 -0
  83. data/spec/support/{5.1.7/test/models → v4.2/test/controllers}/.keep +0 -0
  84. data/spec/support/{5.1.7/tmp → v4.2/test/fixtures}/.keep +0 -0
  85. data/spec/support/{5.1.7/vendor → v4.2/test/helpers}/.keep +0 -0
  86. data/spec/support/{5.2.3/lib/tasks → v4.2/test/integration}/.keep +0 -0
  87. data/spec/support/{5.2.3/log → v4.2/test/mailers}/.keep +0 -0
  88. data/spec/support/{5.2.3/storage → v4.2/test/models}/.keep +0 -0
  89. data/spec/support/{5.1.7 → v4.2}/test/test_helper.rb +0 -0
  90. data/spec/support/{5.2.3/test/controllers → v4.2/vendor/assets/stylesheets}/.keep +0 -0
  91. data/spec/support/v5.0/.gitignore +21 -0
  92. data/spec/support/v5.0/Gemfile +37 -0
  93. data/spec/support/{5.1.7 → v5.0}/README.md +0 -0
  94. data/spec/support/{5.1.7 → v5.0}/Rakefile +0 -0
  95. data/spec/support/{5.1.7 → v5.0}/app/channels/application_cable/channel.rb +0 -0
  96. data/spec/support/{5.1.7 → v5.0}/app/channels/application_cable/connection.rb +0 -0
  97. data/spec/support/v5.0/app/controllers +1 -0
  98. data/spec/support/{5.1.7 → v5.0}/app/jobs/application_job.rb +0 -0
  99. data/spec/support/{5.1.7 → v5.0}/app/mailers/application_mailer.rb +0 -0
  100. data/spec/support/v5.0/app/models +1 -0
  101. data/spec/support/{5.1.7 → v5.0}/app/views/layouts/mailer.html.erb +0 -0
  102. data/spec/support/{5.1.7 → v5.0}/app/views/layouts/mailer.text.erb +0 -0
  103. data/spec/support/v5.0/bin/bundle +3 -0
  104. data/spec/support/v5.0/bin/rails +4 -0
  105. data/spec/support/v5.0/bin/rake +4 -0
  106. data/spec/support/v5.0/bin/setup +34 -0
  107. data/spec/support/{5.1.7 → v5.0}/bin/update +0 -0
  108. data/spec/support/{5.1.7 → v5.0}/config.ru +0 -0
  109. data/spec/support/v5.0/config/application.rb +30 -0
  110. data/spec/support/{5.1.7 → v5.0}/config/boot.rb +0 -0
  111. data/spec/support/v5.0/config/cable.yml +9 -0
  112. data/spec/support/v5.0/config/database.yml +25 -0
  113. data/spec/support/{5.1.7 → v5.0}/config/environment.rb +0 -0
  114. data/spec/support/v5.0/config/environments/development.rb +47 -0
  115. data/spec/support/v5.0/config/environments/production.rb +78 -0
  116. data/spec/support/v5.0/config/environments/test.rb +42 -0
  117. data/spec/support/{5.1.7 → v5.0}/config/initializers/application_controller_renderer.rb +0 -0
  118. data/spec/support/{5.2.3 → v5.0}/config/initializers/backtrace_silencers.rb +0 -0
  119. data/spec/support/{5.1.7 → v5.0}/config/initializers/cors.rb +0 -0
  120. data/spec/support/{5.2.3 → v5.0}/config/initializers/filter_parameter_logging.rb +0 -0
  121. data/spec/support/{5.2.3 → v5.0}/config/initializers/inflections.rb +0 -0
  122. data/spec/support/{5.2.3 → v5.0}/config/initializers/mime_types.rb +0 -0
  123. data/spec/support/v5.0/config/initializers/new_framework_defaults.rb +18 -0
  124. data/spec/support/{5.1.7 → v5.0}/config/initializers/wrap_parameters.rb +0 -0
  125. data/spec/support/v5.0/config/locales/en.yml +23 -0
  126. data/spec/support/v5.0/config/puma.rb +47 -0
  127. data/spec/support/v5.0/config/routes.rb +5 -0
  128. data/spec/support/v5.0/config/secrets.yml +22 -0
  129. data/spec/support/v5.0/db/migrate +1 -0
  130. data/spec/support/v5.0/db/schema.rb +45 -0
  131. data/spec/support/{5.1.7 → v5.0}/db/seeds.rb +0 -0
  132. data/spec/support/{5.2.3/test/fixtures → v5.0/lib/tasks}/.keep +0 -0
  133. data/spec/support/{5.2.3/test/fixtures/files → v5.0/log}/.keep +0 -0
  134. data/spec/support/v5.0/public/robots.txt +5 -0
  135. data/spec/support/v5.0/rails_symlinks/app/controllers +1 -0
  136. data/spec/support/v5.0/rails_symlinks/app/models +1 -0
  137. data/spec/support/v5.0/rails_symlinks/config/routes.rb +5 -0
  138. data/spec/support/v5.0/rails_symlinks/db/migrate +1 -0
  139. data/spec/support/{5.2.3/test/integration → v5.0/test/controllers}/.keep +0 -0
  140. data/spec/support/{5.2.3/test/mailers → v5.0/test/fixtures}/.keep +0 -0
  141. data/spec/support/{5.2.3/test/models → v5.0/test/fixtures/files}/.keep +0 -0
  142. data/spec/support/{5.2.3/tmp → v5.0/test/integration}/.keep +0 -0
  143. data/spec/support/{5.2.3/vendor → v5.0/test/mailers}/.keep +0 -0
  144. data/spec/support/v5.0/test/models/.keep +0 -0
  145. data/spec/support/v5.0/test/test_helper.rb +10 -0
  146. data/spec/support/v5.0/tmp/.keep +0 -0
  147. data/spec/support/{5.1.7 → v5.1}/Gemfile +6 -6
  148. data/spec/support/{5.2.3 → v5.1}/README.md +0 -0
  149. data/spec/support/{5.2.3 → v5.1}/Rakefile +0 -0
  150. data/spec/support/{5.2.3 → v5.1}/app/channels/application_cable/channel.rb +0 -0
  151. data/spec/support/{5.2.3 → v5.1}/app/channels/application_cable/connection.rb +0 -0
  152. data/spec/support/v5.1/app/controllers +1 -0
  153. data/spec/support/{5.2.3 → v5.1}/app/jobs/application_job.rb +0 -0
  154. data/spec/support/{5.2.3 → v5.1}/app/mailers/application_mailer.rb +0 -0
  155. data/spec/support/v5.1/app/models +1 -0
  156. data/spec/support/{5.2.3 → v5.1}/app/views/layouts/mailer.html.erb +0 -0
  157. data/spec/support/{5.2.3 → v5.1}/app/views/layouts/mailer.text.erb +0 -0
  158. data/spec/support/v5.1/bin/bundle +3 -0
  159. data/spec/support/{5.1.7 → v5.1}/bin/rails +0 -0
  160. data/spec/support/{5.1.7 → v5.1}/bin/rake +0 -0
  161. data/spec/support/{5.1.7 → v5.1}/bin/setup +0 -0
  162. data/spec/support/{5.1.7 → v5.1}/bin/spring +0 -0
  163. data/spec/support/v5.1/bin/update +29 -0
  164. data/spec/support/{5.2.3 → v5.1}/config.ru +0 -0
  165. data/spec/support/{5.1.7 → v5.1}/config/application.rb +0 -0
  166. data/spec/support/{5.2.3 → v5.1}/config/boot.rb +0 -0
  167. data/spec/support/{5.1.7 → v5.1}/config/cable.yml +0 -0
  168. data/spec/support/{5.1.7 → v5.1}/config/database.yml +0 -0
  169. data/spec/support/{5.2.3 → v5.1}/config/environment.rb +0 -0
  170. data/spec/support/{5.1.7 → v5.1}/config/environments/development.rb +0 -0
  171. data/spec/support/{5.1.7 → v5.1}/config/environments/production.rb +0 -0
  172. data/spec/support/{5.1.7 → v5.1}/config/environments/test.rb +0 -0
  173. data/spec/support/{5.2.3 → v5.1}/config/initializers/application_controller_renderer.rb +0 -0
  174. data/spec/support/v5.1/config/initializers/backtrace_silencers.rb +7 -0
  175. data/spec/support/{5.2.3 → v5.1}/config/initializers/cors.rb +0 -0
  176. data/spec/support/v5.1/config/initializers/filter_parameter_logging.rb +4 -0
  177. data/spec/support/v5.1/config/initializers/inflections.rb +16 -0
  178. data/spec/support/v5.1/config/initializers/mime_types.rb +4 -0
  179. data/spec/support/{5.2.3 → v5.1}/config/initializers/wrap_parameters.rb +0 -0
  180. data/spec/support/{5.1.7 → v5.1}/config/locales/en.yml +0 -0
  181. data/spec/support/{5.1.7 → v5.1}/config/puma.rb +0 -0
  182. data/spec/support/v5.1/config/routes.rb +1 -0
  183. data/spec/support/{5.1.7 → v5.1}/config/secrets.yml +0 -0
  184. data/spec/support/{5.1.7 → v5.1}/config/spring.rb +0 -0
  185. data/spec/support/v5.1/db/migrate +1 -0
  186. data/spec/support/{5.1.7 → v5.1}/db/schema.rb +0 -0
  187. data/spec/support/{5.2.3 → v5.1}/db/seeds.rb +0 -0
  188. data/spec/support/v5.1/lib/tasks/.keep +0 -0
  189. data/spec/support/v5.1/log/.keep +0 -0
  190. data/spec/support/{5.1.7 → v5.1}/public/robots.txt +0 -0
  191. data/spec/support/v5.1/test/controllers/.keep +0 -0
  192. data/spec/support/v5.1/test/fixtures/.keep +0 -0
  193. data/spec/support/v5.1/test/fixtures/files/.keep +0 -0
  194. data/spec/support/v5.1/test/integration/.keep +0 -0
  195. data/spec/support/v5.1/test/mailers/.keep +0 -0
  196. data/spec/support/v5.1/test/models/.keep +0 -0
  197. data/spec/support/v5.1/test/test_helper.rb +10 -0
  198. data/spec/support/v5.1/tmp/.keep +0 -0
  199. data/spec/support/v5.1/vendor/.keep +0 -0
  200. data/spec/support/{5.2.3 → v5.2}/Gemfile +4 -15
  201. data/spec/support/v5.2/README.md +24 -0
  202. data/spec/support/v5.2/Rakefile +6 -0
  203. data/spec/support/v5.2/app/channels/application_cable/channel.rb +4 -0
  204. data/spec/support/v5.2/app/channels/application_cable/connection.rb +4 -0
  205. data/spec/support/v5.2/app/controllers +1 -0
  206. data/spec/support/v5.2/app/jobs/application_job.rb +2 -0
  207. data/spec/support/v5.2/app/mailers/application_mailer.rb +4 -0
  208. data/spec/support/v5.2/app/models +1 -0
  209. data/spec/support/v5.2/app/views/layouts/mailer.html.erb +13 -0
  210. data/spec/support/v5.2/app/views/layouts/mailer.text.erb +1 -0
  211. data/spec/support/{5.2.3 → v5.2}/bin/bundle +0 -0
  212. data/spec/support/{5.2.3 → v5.2}/bin/rails +0 -0
  213. data/spec/support/{5.2.3 → v5.2}/bin/rake +0 -0
  214. data/spec/support/{5.2.3 → v5.2}/bin/setup +0 -0
  215. data/spec/support/{5.2.3 → v5.2}/bin/spring +0 -0
  216. data/spec/support/{5.2.3 → v5.2}/bin/update +0 -0
  217. data/spec/support/v5.2/config.ru +5 -0
  218. data/spec/support/{5.2.3 → v5.2}/config/application.rb +0 -0
  219. data/spec/support/v5.2/config/boot.rb +3 -0
  220. data/spec/support/{5.2.3 → v5.2}/config/cable.yml +0 -0
  221. data/spec/support/{5.2.3 → v5.2}/config/credentials.yml.enc +0 -0
  222. data/spec/support/{5.2.3 → v5.2}/config/database.yml +0 -0
  223. data/spec/support/v5.2/config/environment.rb +5 -0
  224. data/spec/support/{5.2.3 → v5.2}/config/environments/development.rb +1 -1
  225. data/spec/support/{5.2.3 → v5.2}/config/environments/production.rb +0 -0
  226. data/spec/support/{5.2.3 → v5.2}/config/environments/test.rb +0 -0
  227. data/spec/support/v5.2/config/initializers/application_controller_renderer.rb +8 -0
  228. data/spec/support/v5.2/config/initializers/backtrace_silencers.rb +7 -0
  229. data/spec/support/v5.2/config/initializers/cors.rb +16 -0
  230. data/spec/support/v5.2/config/initializers/filter_parameter_logging.rb +4 -0
  231. data/spec/support/v5.2/config/initializers/inflections.rb +16 -0
  232. data/spec/support/v5.2/config/initializers/mime_types.rb +4 -0
  233. data/spec/support/v5.2/config/initializers/wrap_parameters.rb +14 -0
  234. data/spec/support/{5.2.3 → v5.2}/config/locales/en.yml +0 -0
  235. data/spec/support/{5.2.3 → v5.2}/config/puma.rb +0 -0
  236. data/spec/support/v5.2/config/routes.rb +1 -0
  237. data/spec/support/{5.2.3 → v5.2}/config/spring.rb +0 -0
  238. data/spec/support/{5.2.3 → v5.2}/config/storage.yml +0 -0
  239. data/spec/support/v5.2/db/migrate +1 -0
  240. data/spec/support/{5.2.3 → v5.2}/db/schema.rb +4 -4
  241. data/spec/support/v5.2/db/seeds.rb +7 -0
  242. data/spec/support/v5.2/lib/tasks/.keep +0 -0
  243. data/spec/support/v5.2/log/.keep +0 -0
  244. data/spec/support/{5.2.3 → v5.2}/public/robots.txt +0 -0
  245. data/spec/support/v5.2/sorbet/.keep +0 -0
  246. data/spec/support/v5.2/sorbet/config +2 -0
  247. data/spec/support/v5.2/sorbet/rbi/gems/actioncable.rbi +309 -0
  248. data/spec/support/v5.2/sorbet/rbi/gems/actionmailer.rbi +439 -0
  249. data/spec/support/v5.2/sorbet/rbi/gems/actionpack.rbi +3245 -0
  250. data/spec/support/v5.2/sorbet/rbi/gems/actionview.rbi +1129 -0
  251. data/spec/support/v5.2/sorbet/rbi/gems/activejob.rbi +281 -0
  252. data/spec/support/v5.2/sorbet/rbi/gems/activemodel.rbi +740 -0
  253. data/spec/support/v5.2/sorbet/rbi/gems/activerecord.rbi +3996 -0
  254. data/spec/support/v5.2/sorbet/rbi/gems/activestorage.rbi +173 -0
  255. data/spec/support/v5.2/sorbet/rbi/gems/activesupport.rbi +2309 -0
  256. data/spec/support/v5.2/sorbet/rbi/gems/arel.rbi +1248 -0
  257. data/spec/support/v5.2/sorbet/rbi/gems/byebug.rbi +1039 -0
  258. data/spec/support/v5.2/sorbet/rbi/gems/concurrent-ruby.rbi +1583 -0
  259. data/spec/support/v5.2/sorbet/rbi/gems/crass.rbi +92 -0
  260. data/spec/support/v5.2/sorbet/rbi/gems/erubi.rbi +26 -0
  261. data/spec/support/v5.2/sorbet/rbi/gems/globalid.rbi +98 -0
  262. data/spec/support/v5.2/sorbet/rbi/gems/i18n.rbi +191 -0
  263. data/spec/support/v5.2/sorbet/rbi/gems/loofah.rbi +129 -0
  264. data/spec/support/v5.2/sorbet/rbi/gems/mail.rbi +1091 -0
  265. data/spec/support/v5.2/sorbet/rbi/gems/marcel.rbi +12 -0
  266. data/spec/support/v5.2/sorbet/rbi/gems/method_source.rbi +63 -0
  267. data/spec/support/v5.2/sorbet/rbi/gems/mini_mime.rbi +45 -0
  268. data/spec/support/v5.2/sorbet/rbi/gems/minitest.rbi +276 -0
  269. data/spec/support/v5.2/sorbet/rbi/gems/nokogiri.rbi +1006 -0
  270. data/spec/support/v5.2/sorbet/rbi/gems/puma.rbi +570 -0
  271. data/spec/support/v5.2/sorbet/rbi/gems/rack-test.rbi +161 -0
  272. data/spec/support/v5.2/sorbet/rbi/gems/rack.rbi +534 -0
  273. data/spec/support/v5.2/sorbet/rbi/gems/rails-dom-testing.rbi +67 -0
  274. data/spec/support/v5.2/sorbet/rbi/gems/rails-html-sanitizer.rbi +90 -0
  275. data/spec/support/v5.2/sorbet/rbi/gems/railties.rbi +722 -0
  276. data/spec/support/v5.2/sorbet/rbi/gems/rake.rbi +251 -0
  277. data/spec/support/v5.2/sorbet/rbi/gems/sqlite3.rbi +353 -0
  278. data/spec/support/v5.2/sorbet/rbi/gems/thor.rbi +449 -0
  279. data/spec/support/v5.2/sorbet/rbi/gems/thread_safe.rbi +81 -0
  280. data/spec/support/v5.2/sorbet/rbi/gems/tzinfo.rbi +407 -0
  281. data/spec/support/v5.2/sorbet/rbi/hidden-definitions/errors.txt +10040 -0
  282. data/spec/support/v5.2/sorbet/rbi/hidden-definitions/hidden.rbi +24386 -0
  283. data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/actionmailer/all/actionmailer.rbi +13 -0
  284. data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/actionpack/all/actionpack.rbi +13 -0
  285. data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/activerecord/all/activerecord.rbi +51 -0
  286. data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/activerecord/~>5.2/activerecord.rbi +10 -0
  287. data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/activesupport/all/activesupport.rbi +107 -0
  288. data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +8547 -0
  289. data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/railties/all/railties.rbi +22 -0
  290. data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +111 -0
  291. data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +543 -0
  292. data/spec/support/v5.2/sorbet/rbi/todo.rbi +11 -0
  293. data/spec/support/v5.2/storage/.keep +0 -0
  294. data/spec/support/v5.2/test/controllers/.keep +0 -0
  295. data/spec/support/v5.2/test/fixtures/.keep +0 -0
  296. data/spec/support/v5.2/test/fixtures/files/.keep +0 -0
  297. data/spec/support/v5.2/test/integration/.keep +0 -0
  298. data/spec/support/v5.2/test/mailers/.keep +0 -0
  299. data/spec/support/v5.2/test/models/.keep +0 -0
  300. data/spec/support/{5.2.3 → v5.2}/test/test_helper.rb +0 -0
  301. data/spec/support/v5.2/tmp/.keep +0 -0
  302. data/spec/support/v5.2/vendor/.keep +0 -0
  303. data/spec/support/v6.0/.gitignore +26 -0
  304. data/spec/support/v6.0/Gemfile +35 -0
  305. data/spec/support/v6.0/README.md +24 -0
  306. data/spec/support/v6.0/Rakefile +6 -0
  307. data/spec/support/v6.0/app/channels/application_cable/channel.rb +4 -0
  308. data/spec/support/v6.0/app/channels/application_cable/connection.rb +4 -0
  309. data/spec/support/v6.0/app/controllers +1 -0
  310. data/spec/support/v6.0/app/jobs/application_job.rb +7 -0
  311. data/spec/support/v6.0/app/mailers/application_mailer.rb +4 -0
  312. data/spec/support/v6.0/app/models +1 -0
  313. data/spec/support/v6.0/app/views/layouts/mailer.html.erb +13 -0
  314. data/spec/support/v6.0/app/views/layouts/mailer.text.erb +1 -0
  315. data/spec/support/v6.0/bin/bundle +105 -0
  316. data/spec/support/v6.0/bin/rails +4 -0
  317. data/spec/support/v6.0/bin/rake +4 -0
  318. data/spec/support/v6.0/bin/setup +33 -0
  319. data/spec/support/v6.0/config.ru +5 -0
  320. data/spec/support/v6.0/config/application.rb +37 -0
  321. data/spec/support/v6.0/config/boot.rb +3 -0
  322. data/spec/support/v6.0/config/cable.yml +10 -0
  323. data/spec/support/v6.0/config/credentials.yml.enc +1 -0
  324. data/spec/support/v6.0/config/database.yml +25 -0
  325. data/spec/support/v6.0/config/environment.rb +5 -0
  326. data/spec/support/v6.0/config/environments/development.rb +52 -0
  327. data/spec/support/v6.0/config/environments/production.rb +105 -0
  328. data/spec/support/v6.0/config/environments/test.rb +48 -0
  329. data/spec/support/v6.0/config/initializers/application_controller_renderer.rb +8 -0
  330. data/spec/support/v6.0/config/initializers/backtrace_silencers.rb +7 -0
  331. data/spec/support/v6.0/config/initializers/cors.rb +16 -0
  332. data/spec/support/v6.0/config/initializers/filter_parameter_logging.rb +4 -0
  333. data/spec/support/v6.0/config/initializers/inflections.rb +16 -0
  334. data/spec/support/v6.0/config/initializers/mime_types.rb +4 -0
  335. data/spec/support/v6.0/config/initializers/wrap_parameters.rb +14 -0
  336. data/spec/support/v6.0/config/locales/en.yml +33 -0
  337. data/spec/support/v6.0/config/puma.rb +35 -0
  338. data/spec/support/v6.0/config/routes.rb +5 -0
  339. data/spec/support/v6.0/config/storage.yml +34 -0
  340. data/spec/support/v6.0/db/migrate +1 -0
  341. data/spec/support/v6.0/db/schema.rb +47 -0
  342. data/spec/support/v6.0/db/seeds.rb +7 -0
  343. data/spec/support/v6.0/lib/tasks/.keep +0 -0
  344. data/spec/support/v6.0/log/.keep +0 -0
  345. data/spec/support/v6.0/public/robots.txt +1 -0
  346. data/spec/support/v6.0/storage/.keep +0 -0
  347. data/spec/support/v6.0/test/channels/application_cable/connection_test.rb +11 -0
  348. data/spec/support/v6.0/test/controllers/.keep +0 -0
  349. data/spec/support/v6.0/test/fixtures/.keep +0 -0
  350. data/spec/support/v6.0/test/fixtures/files/.keep +0 -0
  351. data/spec/support/v6.0/test/integration/.keep +0 -0
  352. data/spec/support/v6.0/test/mailers/.keep +0 -0
  353. data/spec/support/v6.0/test/models/.keep +0 -0
  354. data/spec/support/v6.0/test/test_helper.rb +13 -0
  355. data/spec/support/v6.0/tmp/.keep +0 -0
  356. data/spec/support/v6.0/vendor/.keep +0 -0
  357. data/spec/test_data/{5.2.3 → v4.2}/expected_no_routes.rbi +1 -1
  358. data/spec/test_data/v4.2/expected_potion.rbi +113 -0
  359. data/spec/test_data/{5.1.7 → v4.2}/expected_routes.rbi +0 -0
  360. data/spec/test_data/v4.2/expected_spell_book.rbi +146 -0
  361. data/spec/test_data/v4.2/expected_wand.rbi +278 -0
  362. data/spec/test_data/v4.2/expected_wizard.rbi +239 -0
  363. data/spec/test_data/v4.2/expected_wizard_wo_spellbook.rbi +239 -0
  364. data/spec/test_data/{5.1.7 → v5.0}/expected_no_routes.rbi +1 -1
  365. data/spec/test_data/{5.2.3 → v5.0}/expected_potion.rbi +58 -62
  366. data/spec/test_data/v5.0/expected_routes.rbi +13 -0
  367. data/spec/test_data/v5.0/expected_spell_book.rbi +155 -0
  368. data/spec/test_data/{5.1.7 → v5.0}/expected_wand.rbi +125 -72
  369. data/spec/test_data/v5.0/expected_wizard.rbi +248 -0
  370. data/spec/test_data/v5.0/expected_wizard_wo_spellbook.rbi +248 -0
  371. data/spec/test_data/v5.1/expected_no_routes.rbi +11 -0
  372. data/spec/test_data/{5.1.7 → v5.1}/expected_potion.rbi +62 -60
  373. data/spec/test_data/v5.1/expected_routes.rbi +13 -0
  374. data/spec/test_data/v5.1/expected_spell_book.rbi +161 -0
  375. data/spec/test_data/v5.1/expected_wand.rbi +293 -0
  376. data/spec/test_data/v5.1/expected_wizard.rbi +254 -0
  377. data/spec/test_data/v5.1/expected_wizard_wo_spellbook.rbi +254 -0
  378. data/spec/test_data/v5.2/expected_no_routes.rbi +11 -0
  379. data/spec/test_data/v5.2/expected_potion.rbi +128 -0
  380. data/spec/test_data/{5.2.3 → v5.2}/expected_routes.rbi +0 -0
  381. data/spec/test_data/v5.2/expected_spell_book.rbi +161 -0
  382. data/spec/test_data/{5.2.3 → v5.2}/expected_wand.rbi +135 -70
  383. data/spec/test_data/v5.2/expected_wizard.rbi +254 -0
  384. data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +254 -0
  385. data/spec/test_data/v6.0/expected_no_routes.rbi +11 -0
  386. data/spec/test_data/v6.0/expected_potion.rbi +140 -0
  387. data/spec/test_data/v6.0/expected_routes.rbi +91 -0
  388. data/spec/test_data/v6.0/expected_spell_book.rbi +173 -0
  389. data/spec/test_data/v6.0/expected_wand.rbi +335 -0
  390. data/spec/test_data/v6.0/expected_wizard.rbi +278 -0
  391. data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +278 -0
  392. metadata +752 -281
  393. data/spec/support/5.1.7/app/controllers +0 -1
  394. data/spec/support/5.1.7/app/models +0 -1
  395. data/spec/support/5.1.7/config/routes.rb +0 -1
  396. data/spec/support/5.1.7/db/migrate +0 -1
  397. data/spec/support/5.2.3/app/controllers +0 -1
  398. data/spec/support/5.2.3/app/models +0 -1
  399. data/spec/support/5.2.3/config/routes.rb +0 -1
  400. data/spec/support/5.2.3/db/migrate +0 -1
  401. data/spec/test_data/5.1.7/expected_wizard.rbi +0 -207
  402. data/spec/test_data/5.1.7/expected_wizard_wo_spellbook.rbi +0 -207
  403. data/spec/test_data/5.2.3/expected_wizard.rbi +0 -207
  404. data/spec/test_data/5.2.3/expected_wizard_wo_spellbook.rbi +0 -207
@@ -15,21 +15,13 @@ class RoutesRbiFormatter
15
15
  def header(routes)
16
16
  end
17
17
 
18
- def no_routes(routes, filter=nil)
19
- puts routes
18
+ def no_routes(routes=nil, filter=nil)
20
19
  @buffer <<
21
- if routes.none?
22
- <<~MESSAGE
23
- # You do not have any routes defined!
24
- # Please add some routes in config/routes.rb.
25
- MESSAGE
26
- elsif filter && filter.key?(:controller)
27
- "# No routes were found for this controller."
28
- elsif filter && filter.key?(:grep)
29
- "# No routes were found for this grep pattern."
30
- end
31
-
32
- @buffer << "# For more information about routes, see the Rails guide: https://guides.rubyonrails.org/routing.html."
20
+ <<~MESSAGE
21
+ # You do not have any routes defined!
22
+ # Please add some routes in config/routes.rb.
23
+ # For more information about routes, see the Rails guide: https://guides.rubyonrails.org/routing.html.
24
+ MESSAGE
33
25
  end
34
26
 
35
27
  def result
@@ -18,12 +18,12 @@ namespace :rails_rbi do
18
18
  task models: :environment do |t, args|
19
19
  # need to eager load to see all models
20
20
  Rails.application.eager_load!
21
+ # Rails 6.0 change the loading logic to use Zeitwerk
22
+ # https://github.com/rails/rails/blob/master/railties/lib/rails/application/finisher.rb#L116
23
+ # But this is not applied to Rails.application.eager_load! method
24
+ Zeitwerk::Loader.eager_load_all if defined?(Zeitwerk)
21
25
 
22
- blacklisted_models = []
23
- blacklisted_models << ActiveRecord::SchemaMigration if defined?(ActiveRecord::SchemaMigration)
24
- blacklisted_models << ApplicationRecord if defined?(ApplicationRecord)
25
-
26
- all_models = ActiveRecord::Base.descendants - blacklisted_models
26
+ all_models = Set.new(ActiveRecord::Base.descendants + whitelisted_models - blacklisted_models)
27
27
 
28
28
  models_to_generate = args.extras.size > 0 ?
29
29
  args.extras.map { |m| Object.const_get(m) } :
@@ -54,8 +54,15 @@ namespace :rails_rbi do
54
54
 
55
55
  def blacklisted_models
56
56
  blacklisted_models = []
57
- blacklisted_models << ActiveRecord::SchemaMigration if defined?(ActiveRecord::SchemaMigration)
58
57
  blacklisted_models << ApplicationRecord if defined?(ApplicationRecord)
59
58
  blacklisted_models
60
59
  end
60
+
61
+ def whitelisted_models
62
+ # force generating these models because they aren't loaded with eager_load!
63
+ whitelisted_models = []
64
+ whitelisted_models << ActiveRecord::InternalMetadata if Object.const_defined?('ActiveRecord::InternalMetadata')
65
+ whitelisted_models << ActiveRecord::SchemaMigration if Object.const_defined?('ActiveRecord::SchemaMigration')
66
+ whitelisted_models
67
+ end
61
68
  end
@@ -5,7 +5,7 @@ class ActiveRecord::Relation
5
5
  include Enumerable
6
6
  include ActiveRecord::Querying::Typed
7
7
 
8
- Elem = type_member
8
+ Elem = type_member(fixed: ActiveRecord::Base)
9
9
 
10
10
  sig { params(block: T.proc.params(e: Elem).void).void }
11
11
  def each(&block); end
@@ -21,14 +21,14 @@ class ActiveRecord::Relation
21
21
  # TODO normally this method could return Elem or Array[Elem]
22
22
  # however, we think it's better to limit the interface to returning Elem only
23
23
  # Use `find_n` as a replacement if you want to get an array from `find`
24
- sig { params(args: T.untyped).returns(Elem).soft }
24
+ sig { params(args: T.untyped).returns(Elem) }
25
25
  def find(*args); end
26
26
  end
27
27
 
28
28
  class ActiveRecord::Associations::CollectionProxy < ActiveRecord::Relation
29
29
  extend T::Generic
30
30
 
31
- Elem = type_member
31
+ Elem = type_member(fixed: ActiveRecord::Base)
32
32
 
33
33
  # -- << and aliases
34
34
  sig { params(records: T.any(Elem, T::Array[Elem])).returns(T.self_type) }
@@ -45,7 +45,7 @@ end
45
45
  module ActiveRecord::Querying::Typed
46
46
  extend T::Sig
47
47
  extend T::Generic
48
- Elem = type_member
48
+ Elem = type_member(fixed: ActiveRecord::Base)
49
49
 
50
50
  # -- Booleans
51
51
  sig { params(args: T.untyped, block: T.nilable(T.proc.void)).returns(T::Boolean) }
@@ -94,13 +94,13 @@ module ActiveRecord::Querying::Typed
94
94
  # array of element when there is a limit passed in.
95
95
  # The more common use case is to find 1 object. We use that as the default sig
96
96
  # and add custom first_n, last_n method for the cases that return an array
97
- sig { params(limit: T.nilable(Integer)).returns(T.nilable(Elem)).soft }
97
+ sig { params(limit: T.nilable(Integer)).returns(T.nilable(Elem)) }
98
98
  def first(limit = nil); end
99
- sig { params(limit: T.nilable(Integer)).returns(T.nilable(Elem)).soft }
99
+ sig { params(limit: T.nilable(Integer)).returns(T.nilable(Elem)) }
100
100
  def last(limit = nil); end
101
101
  # Similar to first & last, normally this method could return Elem or Array[Elem]
102
102
  # But we enforce that `find` return Elem by default and provide find_n as an alternative
103
- sig { params(args: T.any(Integer, String)).returns(Elem).soft }
103
+ sig { params(args: T.any(Integer, String)).returns(Elem) }
104
104
  def find(*args); end
105
105
  # These are custom finder methods to provide strong type for secondary use case of first, last & find
106
106
  # See sorbet_rails/custom_finder_methods
@@ -142,9 +142,34 @@ class ActiveRecord::Base
142
142
  extend ActiveRecord::Querying::Typed
143
143
  extend T::Generic
144
144
  Elem = type_template(fixed: ActiveRecord::Base)
145
+ include ActiveRecord::AttributeMethods::Dirty
146
+ include ActiveModel::Dirty
145
147
  end
146
148
 
147
149
  class ApplicationRecord
148
150
  extend T::Generic
149
151
  Elem = type_template(fixed: ApplicationRecord)
150
152
  end
153
+
154
+ module ActiveModel::Dirty
155
+ extend T::Sig
156
+
157
+ sig { params(attr: Symbol, from: T.untyped, to: T.untyped).returns(T::Boolean) }
158
+ def attribute_changed?(attr, from: nil, to: nil); end
159
+
160
+ sig { params(attr_name: Symbol).returns(T::Boolean) }
161
+ def attribute_changed_in_place?(attr_name); end
162
+
163
+ sig { params(attr_name: Symbol).returns(T::Boolean) }
164
+ def attribute_previously_changed?(attr_name); end
165
+
166
+ sig { returns(T::Boolean) }
167
+ def changed?; end
168
+ end
169
+
170
+ module ActiveRecord::AttributeMethods::Dirty
171
+ extend T::Sig
172
+
173
+ sig { params(attr_name: Symbol, options: T.untyped).returns(T::Boolean) }
174
+ def saved_change_to_attribute?(attr_name, **options); end
175
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{sorbet-rails}
3
- s.version = "0.2.0"
3
+ s.version = "0.3.0"
4
4
  s.date = %q{2019-04-18}
5
5
  s.summary = %q{Set of tools to make Sorbet work with Rails seamlessly.}
6
6
  s.authors = ["Chan Zuckerberg Initiative"]
@@ -22,9 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency 'byebug', '~>11.0.1', '>=11.0.1'
23
23
 
24
24
  # for testing a gem with a rails app (controller specs)
25
- s.add_development_dependency 'bundler', '>=1.3.0'
26
25
  s.add_development_dependency 'rspec-rails', '>=3.8.2'
27
- s.add_development_dependency 'sqlite3', '>=1.4.1'
28
26
  s.add_development_dependency 'puma', '>=3.12.1'
29
- s.add_development_dependency 'listen', '>=3.1.5'
27
+ s.add_development_dependency 'database_cleaner', '>= 1.7.0'
30
28
  end
@@ -0,0 +1,11 @@
1
+ #!/bin/sh
2
+ # A simple script to run bundle install
3
+
4
+ case $RAILS_VERSION in
5
+ 4.2)
6
+ RAILS_VERSION=4.2 bundle _1.17.3_ install --jobs=3 --retry=3
7
+ ;;
8
+ *)
9
+ bundle install --jobs=3 --retry=3
10
+ ;;
11
+ esac
@@ -1,9 +1,13 @@
1
1
  #!/bin/bash
2
- # A simple script to run all specs for all Rails versions
2
+ # A simple script to run all specs for all supported Rails branches
3
3
 
4
- # 5.1.7
5
- RAILS_VERSION=5.1.7 bundle update && RAILS_VERSION=5.1.7 bundle exec rake
4
+ wd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5
+
6
+ RAILS_VERSION=4.2 bash $wd/run_spec.sh
7
+ RAILS_VERSION=5.0 bash $wd/run_spec.sh
8
+ RAILS_VERSION=5.1 bash $wd/run_spec.sh
9
+ RAILS_VERSION=5.2 bash $wd/run_spec.sh
10
+ RAILS_VERSION=6.0 bash $wd/run_spec.sh
6
11
 
7
12
  # Always end with the default version
8
- # 5.2.3
9
- bundle update && bundle exec rake
13
+ sh $wd/run_spec.sh
@@ -0,0 +1,33 @@
1
+ #!/bin/bash
2
+ # A simple script to run spec for a single version of Rails
3
+
4
+ # need to use bash so that $wd returns the location of the script
5
+ wd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6
+ rm $wd/../../Gemfile.lock 2>/dev/null # clean up Gemfile.lock first
7
+
8
+ case $RAILS_VERSION in
9
+ 4.2)
10
+ echo 'run spec with Rails 4.2'
11
+ RAILS_VERSION=4.2 bundle _1.17.3_ update && RAILS_VERSION=4.2 bundle _1.17.3_ exec rake
12
+ ;;
13
+ 5.0)
14
+ echo 'run spec with Rails 5.0'
15
+ RAILS_VERSION=5.0 bundle update && RAILS_VERSION=5.0 bundle exec rake
16
+ ;;
17
+ 5.1)
18
+ echo 'run spec with Rails 5.1'
19
+ RAILS_VERSION=5.1 bundle update && RAILS_VERSION=5.1 bundle exec rake
20
+ ;;
21
+ 5.2)
22
+ echo 'run spec with Rails 5.2'
23
+ RAILS_VERSION=5.2 bundle update && RAILS_VERSION=5.2 bundle exec rake
24
+ ;;
25
+ 6.0)
26
+ echo 'run spec with Rails 6.0'
27
+ RAILS_VERSION=6.0 bundle update && RAILS_VERSION=6.0 bundle exec rake
28
+ ;;
29
+ *)
30
+ echo 'run default'
31
+ bundle update && bundle exec rake
32
+ ;;
33
+ esac
@@ -2,4 +2,5 @@
2
2
  # A simple script to reset test data for all Rails versions
3
3
 
4
4
  wd="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5
- RESET_TEST_DATA=true sh $wd/run_all_specs.sh
5
+
6
+ RESET_TEST_DATA=true bash $wd/run_all_specs.sh
@@ -0,0 +1,75 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe SorbetRails::CustomFinderMethods do
4
+ let!(:harry) do
5
+ Wizard.create!(
6
+ name: 'Harry Potter',
7
+ house: :Gryffindor,
8
+ )
9
+ end
10
+ let!(:ron) do
11
+ Wizard.create!(
12
+ name: 'Ron Weasley',
13
+ house: :Gryffindor,
14
+ )
15
+ end
16
+ let!(:hermione) do
17
+ Wizard.create!(
18
+ name: 'Hermione Granger',
19
+ house: :Gryffindor,
20
+ )
21
+ end
22
+ let!(:wizard_ids) { Wizard.all.pluck(:id) }
23
+
24
+ context 'test find_n' do
25
+ it 'works with array input' do
26
+ with_array = Wizard.find_n(wizard_ids)
27
+ expect(with_array.size).to eql(3)
28
+ end
29
+
30
+ it 'works with multiple ids' do
31
+ with_splash = Wizard.find_n(*wizard_ids)
32
+ expect(with_splash.size).to eql(3)
33
+ end
34
+
35
+ it 'works with single id array' do
36
+ with_one_element = Wizard.find_n([wizard_ids.first])
37
+ expect(with_one_element.size).to eql(1)
38
+ end
39
+
40
+ it 'works with string ids' do
41
+ with_array_string = Wizard.find_n(wizard_ids.map(&:to_s))
42
+ expect(with_array_string.size).to eql(3)
43
+ end
44
+ end
45
+
46
+ context 'test first_n' do
47
+ it 'handles n = 1' do
48
+ first_wizard = Wizard.order(:id).first_n(1)
49
+ expect(first_wizard).to eq([harry])
50
+ end
51
+
52
+ it 'handles n > 1' do
53
+ wizards_2 = Wizard.order(:id).first_n(2)
54
+ expect(wizards_2).to eq([harry, ron])
55
+
56
+ wizards_3 = Wizard.order(:id).first_n(3)
57
+ expect(wizards_3).to eq([harry, ron, hermione])
58
+ end
59
+ end
60
+
61
+ context 'test last_n' do
62
+ it 'handles n = 1' do
63
+ last_wizard = Wizard.order(:id).last_n(1)
64
+ expect(last_wizard).to eq([hermione])
65
+ end
66
+
67
+ it 'handles n > 1' do
68
+ wizards_2 = Wizard.order(:id).last_n(2)
69
+ expect(wizards_2).to eq([ron, hermione])
70
+
71
+ wizards_3 = Wizard.order(:id).first_n(3)
72
+ expect(wizards_3).to eq([harry, ron, hermione])
73
+ end
74
+ end
75
+ end
@@ -4,16 +4,18 @@ require 'sorbet-rails/model_rbi_formatter'
4
4
  RSpec.describe ModelRbiFormatter do
5
5
 
6
6
  it 'loads all the models in the app' do
7
- Rails.application.eager_load!
8
- all_models = ActiveRecord::Base.descendants.sort_by(&:name)
9
- expect(all_models).to eql([
10
- ActiveRecord::SchemaMigration,
11
- ApplicationRecord,
7
+ expected_models = [
12
8
  Potion,
13
9
  SpellBook,
14
10
  Wand,
15
11
  Wizard,
16
- ])
12
+ ]
13
+
14
+ Rails.application.eager_load!
15
+ # Needed for Rails 6.0
16
+ Zeitwerk::Loader.eager_load_all if defined?(Zeitwerk)
17
+ all_models = ActiveRecord::Base.descendants
18
+ expect((expected_models - all_models)).to eql([])
17
19
  end
18
20
 
19
21
  it 'does not throw an error when given an abstract class' do
@@ -7,17 +7,22 @@ require 'rake'
7
7
  require 'rspec/rails'
8
8
  require 'sorbet-rails/railtie'
9
9
  require 'rspec/expectations'
10
-
11
- load 'sorbet-rails/tasks/rails_rbi.rake'
10
+ require 'database_cleaner'
12
11
 
13
12
  rails_version = ENV["RAILS_VERSION"] || "default"
14
13
 
15
14
  rails_folder =
16
15
  case rails_version
17
- when "5.1.7"
18
- "5.1.7"
16
+ when "4.2"
17
+ "v4.2"
18
+ when "5.0"
19
+ "v5.0"
20
+ when "5.1"
21
+ "v5.1"
22
+ when "6.0"
23
+ "v6.0"
19
24
  else
20
- "5.2.3"
25
+ "v5.2"
21
26
  end
22
27
 
23
28
  TEST_DATA_FOLDER = "spec/test_data/#{rails_folder}"
@@ -26,6 +31,28 @@ require "support/#{rails_folder}/config/environment"
26
31
 
27
32
  ActiveRecord::Migration.maintain_test_schema!
28
33
 
34
+ RSpec.configure do |config|
35
+ config.before(:suite) do
36
+ next if ENV["DISABLE_DATABASE_CLEANER"] == 'true'
37
+ DatabaseCleaner.clean_with(:truncation, {pre_count: true, reset_ids: false})
38
+ end
39
+
40
+ config.around(:each) do |example|
41
+ if ENV["DISABLE_DATABASE_CLEANER"] == 'true'
42
+ example.run
43
+ next
44
+ end
45
+ if example.metadata.fetch(:transaction, true)
46
+ DatabaseCleaner.strategy = :transaction
47
+ else
48
+ DatabaseCleaner.strategy = :truncation, {pre_count: true, reset_ids: false}
49
+ end
50
+ DatabaseCleaner.start
51
+ example.run
52
+ DatabaseCleaner.clean
53
+ end
54
+ end
55
+
29
56
  def expect_match_file(content, file_path)
30
57
  # TODO make this a custom matcher that can be shared in multiple files
31
58
  relative_path = "#{TEST_DATA_FOLDER}/#{file_path}"
@@ -0,0 +1,47 @@
1
+ # For testing rake tasks
2
+ # From: https://github.com/eliotsykes/rails-testing-toolbox/blob/master/tasks.rb
3
+ # Checkout: https://www.eliotsykes.com/test-rails-rake-tasks-with-rspec
4
+
5
+ require 'rake'
6
+
7
+ # Task names should be used in the top-level describe, with an optional
8
+ # "rake "-prefix for better documentation. Both of these will work:
9
+ #
10
+ # 1) describe 'foo:bar' do ... end
11
+ #
12
+ # 2) describe 'rake foo:bar' do ... end
13
+ #
14
+ # Favor including 'rake '-prefix as in the 2nd example above as it produces
15
+ # doc output that makes it clear a rake task is under test and how it is
16
+ # invoked.
17
+ module TaskExampleGroup
18
+ extend ActiveSupport::Concern
19
+
20
+ included do
21
+ let(:task_name) { self.class.top_level_description.sub(/\Arake /, '') }
22
+ let(:tasks) { Rake::Task }
23
+ subject(:task) { tasks[task_name] }
24
+
25
+ after(:each) do
26
+ task.all_prerequisite_tasks.each { |prerequisite| tasks[prerequisite].reenable }
27
+ task.reenable
28
+
29
+ # clean up generated dir
30
+ rbi_dir = Rails.root.join("sorbet", "rails-rbi")
31
+ FileUtils.remove_dir(rbi_dir) if Dir.exists?(rbi_dir)
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ RSpec.configure do |config|
38
+ config.define_derived_metadata(:file_path => %r{/spec/tasks/}) do |metadata|
39
+ metadata[:type] = :task
40
+ end
41
+
42
+ config.include TaskExampleGroup, type: :task
43
+
44
+ config.before(:suite) do
45
+ Rails.application.load_tasks
46
+ end
47
+ end