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.
- checksums.yaml +4 -4
- data/.codecov.yml +4 -0
- data/.github/ISSUE_TEMPLATE/bug.md +26 -0
- data/.gitignore +5 -0
- data/.travis.yml +26 -7
- data/CONTRIBUTING.md +135 -0
- data/Gemfile +29 -11
- data/README.md +40 -7
- data/lib/sorbet-rails/custom_finder_methods.rb +1 -1
- data/lib/sorbet-rails/model_rbi_formatter.rb +72 -41
- data/lib/sorbet-rails/routes_rbi_formatter.rb +6 -14
- data/lib/sorbet-rails/tasks/rails_rbi.rake +13 -6
- data/rbi/activerecord.rbi +32 -7
- data/sorbet-rails.gemspec +2 -4
- data/spec/bin/install.sh +11 -0
- data/spec/bin/run_all_specs.sh +9 -5
- data/spec/bin/run_spec.sh +33 -0
- data/spec/bin/{reset_test_data.sh → update_test_data.sh} +2 -1
- data/spec/custom_finder_methods_spec.rb +75 -0
- data/spec/model_rbi_formatter_spec.rb +8 -6
- data/spec/rails_helper.rb +32 -5
- data/spec/rake_helper.rb +47 -0
- data/spec/rake_rails_rbi_models_spec.rb +64 -0
- data/spec/rake_rails_rbi_routes_spec.rb +15 -0
- data/spec/support/rails_shared/app/models/wizard.rb +4 -4
- data/spec/support/rails_shared/db/migrate/20190620001234_create_wizards.rb +1 -1
- data/spec/support/rails_shared/db/migrate/20190620003037_create_wands.rb +1 -1
- data/spec/support/rails_shared/db/migrate/20190620003739_create_spell_books.rb +1 -1
- data/spec/support/rails_shared/db/migrate/20190622000000_add_more_column_types_to_wands.rb +5 -3
- data/spec/support/rails_symlinks/app/controllers +1 -0
- data/spec/support/rails_symlinks/app/models +1 -0
- data/spec/support/rails_symlinks/config/routes.rb +5 -0
- data/spec/support/rails_symlinks/db/migrate +1 -0
- data/spec/support/v4.2/.gitignore +17 -0
- data/spec/support/v4.2/Gemfile +31 -0
- data/spec/support/v4.2/README.rdoc +28 -0
- data/spec/support/v4.2/Rakefile +6 -0
- data/spec/support/{5.1.7/lib/tasks → v4.2/app/assets/images}/.keep +0 -0
- data/spec/support/v4.2/app/assets/stylesheets/application.css +15 -0
- data/spec/support/v4.2/app/controllers/application_controller.rb +5 -0
- data/spec/support/{5.1.7/log → v4.2/app/controllers/concerns}/.keep +0 -0
- data/spec/support/v4.2/app/helpers/application_helper.rb +2 -0
- data/spec/support/{5.1.7/test/controllers → v4.2/app/mailers}/.keep +0 -0
- data/spec/support/v4.2/app/models +1 -0
- data/spec/support/v4.2/app/views/layouts/application.html.erb +13 -0
- data/spec/support/{5.1.7 → v4.2}/bin/bundle +0 -0
- data/spec/support/v4.2/bin/rails +4 -0
- data/spec/support/v4.2/bin/rake +4 -0
- data/spec/support/v4.2/bin/setup +29 -0
- data/spec/support/v4.2/config.ru +4 -0
- data/spec/support/v4.2/config/application.rb +35 -0
- data/spec/support/v4.2/config/boot.rb +3 -0
- data/spec/support/v4.2/config/database.yml +25 -0
- data/spec/support/v4.2/config/environment.rb +5 -0
- data/spec/support/v4.2/config/environments/development.rb +28 -0
- data/spec/support/v4.2/config/environments/production.rb +67 -0
- data/spec/support/v4.2/config/environments/test.rb +42 -0
- data/spec/support/{5.1.7 → v4.2}/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/support/v4.2/config/initializers/cookies_serializer.rb +3 -0
- data/spec/support/{5.1.7 → v4.2}/config/initializers/filter_parameter_logging.rb +0 -0
- data/spec/support/{5.1.7 → v4.2}/config/initializers/inflections.rb +0 -0
- data/spec/support/{5.1.7 → v4.2}/config/initializers/mime_types.rb +0 -0
- data/spec/support/v4.2/config/initializers/session_store.rb +3 -0
- data/spec/support/v4.2/config/initializers/to_time_preserves_timezone.rb +10 -0
- data/spec/support/v4.2/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/v4.2/config/locales/en.yml +23 -0
- data/spec/support/v4.2/config/routes.rb +5 -0
- data/spec/support/v4.2/config/secrets.yml +22 -0
- data/spec/support/v4.2/db/migrate/20190620001234_create_wizards.rb +12 -0
- data/spec/support/v4.2/db/migrate/20190620003037_create_wands.rb +11 -0
- data/spec/support/v4.2/db/migrate/20190620003739_create_spell_books.rb +8 -0
- data/spec/support/v4.2/db/migrate/20190622000000_add_more_column_types_to_wands.rb +10 -0
- data/spec/support/v4.2/db/schema.rb +44 -0
- data/spec/support/v4.2/db/seeds.rb +7 -0
- data/spec/support/{5.1.7/test/fixtures → v4.2/lib/assets}/.keep +0 -0
- data/spec/support/{5.1.7/test/fixtures/files → v4.2/lib/tasks}/.keep +0 -0
- data/spec/support/{5.1.7/test/integration → v4.2/log}/.keep +0 -0
- data/spec/support/v4.2/public/404.html +67 -0
- data/spec/support/v4.2/public/422.html +67 -0
- data/spec/support/v4.2/public/500.html +66 -0
- data/spec/support/{5.1.7/test/mailers/.keep → v4.2/public/favicon.ico} +0 -0
- data/spec/support/v4.2/public/robots.txt +5 -0
- data/spec/support/{5.1.7/test/models → v4.2/test/controllers}/.keep +0 -0
- data/spec/support/{5.1.7/tmp → v4.2/test/fixtures}/.keep +0 -0
- data/spec/support/{5.1.7/vendor → v4.2/test/helpers}/.keep +0 -0
- data/spec/support/{5.2.3/lib/tasks → v4.2/test/integration}/.keep +0 -0
- data/spec/support/{5.2.3/log → v4.2/test/mailers}/.keep +0 -0
- data/spec/support/{5.2.3/storage → v4.2/test/models}/.keep +0 -0
- data/spec/support/{5.1.7 → v4.2}/test/test_helper.rb +0 -0
- data/spec/support/{5.2.3/test/controllers → v4.2/vendor/assets/stylesheets}/.keep +0 -0
- data/spec/support/v5.0/.gitignore +21 -0
- data/spec/support/v5.0/Gemfile +37 -0
- data/spec/support/{5.1.7 → v5.0}/README.md +0 -0
- data/spec/support/{5.1.7 → v5.0}/Rakefile +0 -0
- data/spec/support/{5.1.7 → v5.0}/app/channels/application_cable/channel.rb +0 -0
- data/spec/support/{5.1.7 → v5.0}/app/channels/application_cable/connection.rb +0 -0
- data/spec/support/v5.0/app/controllers +1 -0
- data/spec/support/{5.1.7 → v5.0}/app/jobs/application_job.rb +0 -0
- data/spec/support/{5.1.7 → v5.0}/app/mailers/application_mailer.rb +0 -0
- data/spec/support/v5.0/app/models +1 -0
- data/spec/support/{5.1.7 → v5.0}/app/views/layouts/mailer.html.erb +0 -0
- data/spec/support/{5.1.7 → v5.0}/app/views/layouts/mailer.text.erb +0 -0
- data/spec/support/v5.0/bin/bundle +3 -0
- data/spec/support/v5.0/bin/rails +4 -0
- data/spec/support/v5.0/bin/rake +4 -0
- data/spec/support/v5.0/bin/setup +34 -0
- data/spec/support/{5.1.7 → v5.0}/bin/update +0 -0
- data/spec/support/{5.1.7 → v5.0}/config.ru +0 -0
- data/spec/support/v5.0/config/application.rb +30 -0
- data/spec/support/{5.1.7 → v5.0}/config/boot.rb +0 -0
- data/spec/support/v5.0/config/cable.yml +9 -0
- data/spec/support/v5.0/config/database.yml +25 -0
- data/spec/support/{5.1.7 → v5.0}/config/environment.rb +0 -0
- data/spec/support/v5.0/config/environments/development.rb +47 -0
- data/spec/support/v5.0/config/environments/production.rb +78 -0
- data/spec/support/v5.0/config/environments/test.rb +42 -0
- data/spec/support/{5.1.7 → v5.0}/config/initializers/application_controller_renderer.rb +0 -0
- data/spec/support/{5.2.3 → v5.0}/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/support/{5.1.7 → v5.0}/config/initializers/cors.rb +0 -0
- data/spec/support/{5.2.3 → v5.0}/config/initializers/filter_parameter_logging.rb +0 -0
- data/spec/support/{5.2.3 → v5.0}/config/initializers/inflections.rb +0 -0
- data/spec/support/{5.2.3 → v5.0}/config/initializers/mime_types.rb +0 -0
- data/spec/support/v5.0/config/initializers/new_framework_defaults.rb +18 -0
- data/spec/support/{5.1.7 → v5.0}/config/initializers/wrap_parameters.rb +0 -0
- data/spec/support/v5.0/config/locales/en.yml +23 -0
- data/spec/support/v5.0/config/puma.rb +47 -0
- data/spec/support/v5.0/config/routes.rb +5 -0
- data/spec/support/v5.0/config/secrets.yml +22 -0
- data/spec/support/v5.0/db/migrate +1 -0
- data/spec/support/v5.0/db/schema.rb +45 -0
- data/spec/support/{5.1.7 → v5.0}/db/seeds.rb +0 -0
- data/spec/support/{5.2.3/test/fixtures → v5.0/lib/tasks}/.keep +0 -0
- data/spec/support/{5.2.3/test/fixtures/files → v5.0/log}/.keep +0 -0
- data/spec/support/v5.0/public/robots.txt +5 -0
- data/spec/support/v5.0/rails_symlinks/app/controllers +1 -0
- data/spec/support/v5.0/rails_symlinks/app/models +1 -0
- data/spec/support/v5.0/rails_symlinks/config/routes.rb +5 -0
- data/spec/support/v5.0/rails_symlinks/db/migrate +1 -0
- data/spec/support/{5.2.3/test/integration → v5.0/test/controllers}/.keep +0 -0
- data/spec/support/{5.2.3/test/mailers → v5.0/test/fixtures}/.keep +0 -0
- data/spec/support/{5.2.3/test/models → v5.0/test/fixtures/files}/.keep +0 -0
- data/spec/support/{5.2.3/tmp → v5.0/test/integration}/.keep +0 -0
- data/spec/support/{5.2.3/vendor → v5.0/test/mailers}/.keep +0 -0
- data/spec/support/v5.0/test/models/.keep +0 -0
- data/spec/support/v5.0/test/test_helper.rb +10 -0
- data/spec/support/v5.0/tmp/.keep +0 -0
- data/spec/support/{5.1.7 → v5.1}/Gemfile +6 -6
- data/spec/support/{5.2.3 → v5.1}/README.md +0 -0
- data/spec/support/{5.2.3 → v5.1}/Rakefile +0 -0
- data/spec/support/{5.2.3 → v5.1}/app/channels/application_cable/channel.rb +0 -0
- data/spec/support/{5.2.3 → v5.1}/app/channels/application_cable/connection.rb +0 -0
- data/spec/support/v5.1/app/controllers +1 -0
- data/spec/support/{5.2.3 → v5.1}/app/jobs/application_job.rb +0 -0
- data/spec/support/{5.2.3 → v5.1}/app/mailers/application_mailer.rb +0 -0
- data/spec/support/v5.1/app/models +1 -0
- data/spec/support/{5.2.3 → v5.1}/app/views/layouts/mailer.html.erb +0 -0
- data/spec/support/{5.2.3 → v5.1}/app/views/layouts/mailer.text.erb +0 -0
- data/spec/support/v5.1/bin/bundle +3 -0
- data/spec/support/{5.1.7 → v5.1}/bin/rails +0 -0
- data/spec/support/{5.1.7 → v5.1}/bin/rake +0 -0
- data/spec/support/{5.1.7 → v5.1}/bin/setup +0 -0
- data/spec/support/{5.1.7 → v5.1}/bin/spring +0 -0
- data/spec/support/v5.1/bin/update +29 -0
- data/spec/support/{5.2.3 → v5.1}/config.ru +0 -0
- data/spec/support/{5.1.7 → v5.1}/config/application.rb +0 -0
- data/spec/support/{5.2.3 → v5.1}/config/boot.rb +0 -0
- data/spec/support/{5.1.7 → v5.1}/config/cable.yml +0 -0
- data/spec/support/{5.1.7 → v5.1}/config/database.yml +0 -0
- data/spec/support/{5.2.3 → v5.1}/config/environment.rb +0 -0
- data/spec/support/{5.1.7 → v5.1}/config/environments/development.rb +0 -0
- data/spec/support/{5.1.7 → v5.1}/config/environments/production.rb +0 -0
- data/spec/support/{5.1.7 → v5.1}/config/environments/test.rb +0 -0
- data/spec/support/{5.2.3 → v5.1}/config/initializers/application_controller_renderer.rb +0 -0
- data/spec/support/v5.1/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/{5.2.3 → v5.1}/config/initializers/cors.rb +0 -0
- data/spec/support/v5.1/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/support/v5.1/config/initializers/inflections.rb +16 -0
- data/spec/support/v5.1/config/initializers/mime_types.rb +4 -0
- data/spec/support/{5.2.3 → v5.1}/config/initializers/wrap_parameters.rb +0 -0
- data/spec/support/{5.1.7 → v5.1}/config/locales/en.yml +0 -0
- data/spec/support/{5.1.7 → v5.1}/config/puma.rb +0 -0
- data/spec/support/v5.1/config/routes.rb +1 -0
- data/spec/support/{5.1.7 → v5.1}/config/secrets.yml +0 -0
- data/spec/support/{5.1.7 → v5.1}/config/spring.rb +0 -0
- data/spec/support/v5.1/db/migrate +1 -0
- data/spec/support/{5.1.7 → v5.1}/db/schema.rb +0 -0
- data/spec/support/{5.2.3 → v5.1}/db/seeds.rb +0 -0
- data/spec/support/v5.1/lib/tasks/.keep +0 -0
- data/spec/support/v5.1/log/.keep +0 -0
- data/spec/support/{5.1.7 → v5.1}/public/robots.txt +0 -0
- data/spec/support/v5.1/test/controllers/.keep +0 -0
- data/spec/support/v5.1/test/fixtures/.keep +0 -0
- data/spec/support/v5.1/test/fixtures/files/.keep +0 -0
- data/spec/support/v5.1/test/integration/.keep +0 -0
- data/spec/support/v5.1/test/mailers/.keep +0 -0
- data/spec/support/v5.1/test/models/.keep +0 -0
- data/spec/support/v5.1/test/test_helper.rb +10 -0
- data/spec/support/v5.1/tmp/.keep +0 -0
- data/spec/support/v5.1/vendor/.keep +0 -0
- data/spec/support/{5.2.3 → v5.2}/Gemfile +4 -15
- data/spec/support/v5.2/README.md +24 -0
- data/spec/support/v5.2/Rakefile +6 -0
- data/spec/support/v5.2/app/channels/application_cable/channel.rb +4 -0
- data/spec/support/v5.2/app/channels/application_cable/connection.rb +4 -0
- data/spec/support/v5.2/app/controllers +1 -0
- data/spec/support/v5.2/app/jobs/application_job.rb +2 -0
- data/spec/support/v5.2/app/mailers/application_mailer.rb +4 -0
- data/spec/support/v5.2/app/models +1 -0
- data/spec/support/v5.2/app/views/layouts/mailer.html.erb +13 -0
- data/spec/support/v5.2/app/views/layouts/mailer.text.erb +1 -0
- data/spec/support/{5.2.3 → v5.2}/bin/bundle +0 -0
- data/spec/support/{5.2.3 → v5.2}/bin/rails +0 -0
- data/spec/support/{5.2.3 → v5.2}/bin/rake +0 -0
- data/spec/support/{5.2.3 → v5.2}/bin/setup +0 -0
- data/spec/support/{5.2.3 → v5.2}/bin/spring +0 -0
- data/spec/support/{5.2.3 → v5.2}/bin/update +0 -0
- data/spec/support/v5.2/config.ru +5 -0
- data/spec/support/{5.2.3 → v5.2}/config/application.rb +0 -0
- data/spec/support/v5.2/config/boot.rb +3 -0
- data/spec/support/{5.2.3 → v5.2}/config/cable.yml +0 -0
- data/spec/support/{5.2.3 → v5.2}/config/credentials.yml.enc +0 -0
- data/spec/support/{5.2.3 → v5.2}/config/database.yml +0 -0
- data/spec/support/v5.2/config/environment.rb +5 -0
- data/spec/support/{5.2.3 → v5.2}/config/environments/development.rb +1 -1
- data/spec/support/{5.2.3 → v5.2}/config/environments/production.rb +0 -0
- data/spec/support/{5.2.3 → v5.2}/config/environments/test.rb +0 -0
- data/spec/support/v5.2/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/support/v5.2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/v5.2/config/initializers/cors.rb +16 -0
- data/spec/support/v5.2/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/support/v5.2/config/initializers/inflections.rb +16 -0
- data/spec/support/v5.2/config/initializers/mime_types.rb +4 -0
- data/spec/support/v5.2/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/{5.2.3 → v5.2}/config/locales/en.yml +0 -0
- data/spec/support/{5.2.3 → v5.2}/config/puma.rb +0 -0
- data/spec/support/v5.2/config/routes.rb +1 -0
- data/spec/support/{5.2.3 → v5.2}/config/spring.rb +0 -0
- data/spec/support/{5.2.3 → v5.2}/config/storage.yml +0 -0
- data/spec/support/v5.2/db/migrate +1 -0
- data/spec/support/{5.2.3 → v5.2}/db/schema.rb +4 -4
- data/spec/support/v5.2/db/seeds.rb +7 -0
- data/spec/support/v5.2/lib/tasks/.keep +0 -0
- data/spec/support/v5.2/log/.keep +0 -0
- data/spec/support/{5.2.3 → v5.2}/public/robots.txt +0 -0
- data/spec/support/v5.2/sorbet/.keep +0 -0
- data/spec/support/v5.2/sorbet/config +2 -0
- data/spec/support/v5.2/sorbet/rbi/gems/actioncable.rbi +309 -0
- data/spec/support/v5.2/sorbet/rbi/gems/actionmailer.rbi +439 -0
- data/spec/support/v5.2/sorbet/rbi/gems/actionpack.rbi +3245 -0
- data/spec/support/v5.2/sorbet/rbi/gems/actionview.rbi +1129 -0
- data/spec/support/v5.2/sorbet/rbi/gems/activejob.rbi +281 -0
- data/spec/support/v5.2/sorbet/rbi/gems/activemodel.rbi +740 -0
- data/spec/support/v5.2/sorbet/rbi/gems/activerecord.rbi +3996 -0
- data/spec/support/v5.2/sorbet/rbi/gems/activestorage.rbi +173 -0
- data/spec/support/v5.2/sorbet/rbi/gems/activesupport.rbi +2309 -0
- data/spec/support/v5.2/sorbet/rbi/gems/arel.rbi +1248 -0
- data/spec/support/v5.2/sorbet/rbi/gems/byebug.rbi +1039 -0
- data/spec/support/v5.2/sorbet/rbi/gems/concurrent-ruby.rbi +1583 -0
- data/spec/support/v5.2/sorbet/rbi/gems/crass.rbi +92 -0
- data/spec/support/v5.2/sorbet/rbi/gems/erubi.rbi +26 -0
- data/spec/support/v5.2/sorbet/rbi/gems/globalid.rbi +98 -0
- data/spec/support/v5.2/sorbet/rbi/gems/i18n.rbi +191 -0
- data/spec/support/v5.2/sorbet/rbi/gems/loofah.rbi +129 -0
- data/spec/support/v5.2/sorbet/rbi/gems/mail.rbi +1091 -0
- data/spec/support/v5.2/sorbet/rbi/gems/marcel.rbi +12 -0
- data/spec/support/v5.2/sorbet/rbi/gems/method_source.rbi +63 -0
- data/spec/support/v5.2/sorbet/rbi/gems/mini_mime.rbi +45 -0
- data/spec/support/v5.2/sorbet/rbi/gems/minitest.rbi +276 -0
- data/spec/support/v5.2/sorbet/rbi/gems/nokogiri.rbi +1006 -0
- data/spec/support/v5.2/sorbet/rbi/gems/puma.rbi +570 -0
- data/spec/support/v5.2/sorbet/rbi/gems/rack-test.rbi +161 -0
- data/spec/support/v5.2/sorbet/rbi/gems/rack.rbi +534 -0
- data/spec/support/v5.2/sorbet/rbi/gems/rails-dom-testing.rbi +67 -0
- data/spec/support/v5.2/sorbet/rbi/gems/rails-html-sanitizer.rbi +90 -0
- data/spec/support/v5.2/sorbet/rbi/gems/railties.rbi +722 -0
- data/spec/support/v5.2/sorbet/rbi/gems/rake.rbi +251 -0
- data/spec/support/v5.2/sorbet/rbi/gems/sqlite3.rbi +353 -0
- data/spec/support/v5.2/sorbet/rbi/gems/thor.rbi +449 -0
- data/spec/support/v5.2/sorbet/rbi/gems/thread_safe.rbi +81 -0
- data/spec/support/v5.2/sorbet/rbi/gems/tzinfo.rbi +407 -0
- data/spec/support/v5.2/sorbet/rbi/hidden-definitions/errors.txt +10040 -0
- data/spec/support/v5.2/sorbet/rbi/hidden-definitions/hidden.rbi +24386 -0
- data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/actionmailer/all/actionmailer.rbi +13 -0
- data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/actionpack/all/actionpack.rbi +13 -0
- data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/activerecord/all/activerecord.rbi +51 -0
- data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/activerecord/~>5.2/activerecord.rbi +10 -0
- data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/activesupport/all/activesupport.rbi +107 -0
- data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +8547 -0
- data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/railties/all/railties.rbi +22 -0
- data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +111 -0
- data/spec/support/v5.2/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +543 -0
- data/spec/support/v5.2/sorbet/rbi/todo.rbi +11 -0
- data/spec/support/v5.2/storage/.keep +0 -0
- data/spec/support/v5.2/test/controllers/.keep +0 -0
- data/spec/support/v5.2/test/fixtures/.keep +0 -0
- data/spec/support/v5.2/test/fixtures/files/.keep +0 -0
- data/spec/support/v5.2/test/integration/.keep +0 -0
- data/spec/support/v5.2/test/mailers/.keep +0 -0
- data/spec/support/v5.2/test/models/.keep +0 -0
- data/spec/support/{5.2.3 → v5.2}/test/test_helper.rb +0 -0
- data/spec/support/v5.2/tmp/.keep +0 -0
- data/spec/support/v5.2/vendor/.keep +0 -0
- data/spec/support/v6.0/.gitignore +26 -0
- data/spec/support/v6.0/Gemfile +35 -0
- data/spec/support/v6.0/README.md +24 -0
- data/spec/support/v6.0/Rakefile +6 -0
- data/spec/support/v6.0/app/channels/application_cable/channel.rb +4 -0
- data/spec/support/v6.0/app/channels/application_cable/connection.rb +4 -0
- data/spec/support/v6.0/app/controllers +1 -0
- data/spec/support/v6.0/app/jobs/application_job.rb +7 -0
- data/spec/support/v6.0/app/mailers/application_mailer.rb +4 -0
- data/spec/support/v6.0/app/models +1 -0
- data/spec/support/v6.0/app/views/layouts/mailer.html.erb +13 -0
- data/spec/support/v6.0/app/views/layouts/mailer.text.erb +1 -0
- data/spec/support/v6.0/bin/bundle +105 -0
- data/spec/support/v6.0/bin/rails +4 -0
- data/spec/support/v6.0/bin/rake +4 -0
- data/spec/support/v6.0/bin/setup +33 -0
- data/spec/support/v6.0/config.ru +5 -0
- data/spec/support/v6.0/config/application.rb +37 -0
- data/spec/support/v6.0/config/boot.rb +3 -0
- data/spec/support/v6.0/config/cable.yml +10 -0
- data/spec/support/v6.0/config/credentials.yml.enc +1 -0
- data/spec/support/v6.0/config/database.yml +25 -0
- data/spec/support/v6.0/config/environment.rb +5 -0
- data/spec/support/v6.0/config/environments/development.rb +52 -0
- data/spec/support/v6.0/config/environments/production.rb +105 -0
- data/spec/support/v6.0/config/environments/test.rb +48 -0
- data/spec/support/v6.0/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/support/v6.0/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/v6.0/config/initializers/cors.rb +16 -0
- data/spec/support/v6.0/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/support/v6.0/config/initializers/inflections.rb +16 -0
- data/spec/support/v6.0/config/initializers/mime_types.rb +4 -0
- data/spec/support/v6.0/config/initializers/wrap_parameters.rb +14 -0
- data/spec/support/v6.0/config/locales/en.yml +33 -0
- data/spec/support/v6.0/config/puma.rb +35 -0
- data/spec/support/v6.0/config/routes.rb +5 -0
- data/spec/support/v6.0/config/storage.yml +34 -0
- data/spec/support/v6.0/db/migrate +1 -0
- data/spec/support/v6.0/db/schema.rb +47 -0
- data/spec/support/v6.0/db/seeds.rb +7 -0
- data/spec/support/v6.0/lib/tasks/.keep +0 -0
- data/spec/support/v6.0/log/.keep +0 -0
- data/spec/support/v6.0/public/robots.txt +1 -0
- data/spec/support/v6.0/storage/.keep +0 -0
- data/spec/support/v6.0/test/channels/application_cable/connection_test.rb +11 -0
- data/spec/support/v6.0/test/controllers/.keep +0 -0
- data/spec/support/v6.0/test/fixtures/.keep +0 -0
- data/spec/support/v6.0/test/fixtures/files/.keep +0 -0
- data/spec/support/v6.0/test/integration/.keep +0 -0
- data/spec/support/v6.0/test/mailers/.keep +0 -0
- data/spec/support/v6.0/test/models/.keep +0 -0
- data/spec/support/v6.0/test/test_helper.rb +13 -0
- data/spec/support/v6.0/tmp/.keep +0 -0
- data/spec/support/v6.0/vendor/.keep +0 -0
- data/spec/test_data/{5.2.3 → v4.2}/expected_no_routes.rbi +1 -1
- data/spec/test_data/v4.2/expected_potion.rbi +113 -0
- data/spec/test_data/{5.1.7 → v4.2}/expected_routes.rbi +0 -0
- data/spec/test_data/v4.2/expected_spell_book.rbi +146 -0
- data/spec/test_data/v4.2/expected_wand.rbi +278 -0
- data/spec/test_data/v4.2/expected_wizard.rbi +239 -0
- data/spec/test_data/v4.2/expected_wizard_wo_spellbook.rbi +239 -0
- data/spec/test_data/{5.1.7 → v5.0}/expected_no_routes.rbi +1 -1
- data/spec/test_data/{5.2.3 → v5.0}/expected_potion.rbi +58 -62
- data/spec/test_data/v5.0/expected_routes.rbi +13 -0
- data/spec/test_data/v5.0/expected_spell_book.rbi +155 -0
- data/spec/test_data/{5.1.7 → v5.0}/expected_wand.rbi +125 -72
- data/spec/test_data/v5.0/expected_wizard.rbi +248 -0
- data/spec/test_data/v5.0/expected_wizard_wo_spellbook.rbi +248 -0
- data/spec/test_data/v5.1/expected_no_routes.rbi +11 -0
- data/spec/test_data/{5.1.7 → v5.1}/expected_potion.rbi +62 -60
- data/spec/test_data/v5.1/expected_routes.rbi +13 -0
- data/spec/test_data/v5.1/expected_spell_book.rbi +161 -0
- data/spec/test_data/v5.1/expected_wand.rbi +293 -0
- data/spec/test_data/v5.1/expected_wizard.rbi +254 -0
- data/spec/test_data/v5.1/expected_wizard_wo_spellbook.rbi +254 -0
- data/spec/test_data/v5.2/expected_no_routes.rbi +11 -0
- data/spec/test_data/v5.2/expected_potion.rbi +128 -0
- data/spec/test_data/{5.2.3 → v5.2}/expected_routes.rbi +0 -0
- data/spec/test_data/v5.2/expected_spell_book.rbi +161 -0
- data/spec/test_data/{5.2.3 → v5.2}/expected_wand.rbi +135 -70
- data/spec/test_data/v5.2/expected_wizard.rbi +254 -0
- data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +254 -0
- data/spec/test_data/v6.0/expected_no_routes.rbi +11 -0
- data/spec/test_data/v6.0/expected_potion.rbi +140 -0
- data/spec/test_data/v6.0/expected_routes.rbi +91 -0
- data/spec/test_data/v6.0/expected_spell_book.rbi +173 -0
- data/spec/test_data/v6.0/expected_wand.rbi +335 -0
- data/spec/test_data/v6.0/expected_wizard.rbi +278 -0
- data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +278 -0
- metadata +752 -281
- data/spec/support/5.1.7/app/controllers +0 -1
- data/spec/support/5.1.7/app/models +0 -1
- data/spec/support/5.1.7/config/routes.rb +0 -1
- data/spec/support/5.1.7/db/migrate +0 -1
- data/spec/support/5.2.3/app/controllers +0 -1
- data/spec/support/5.2.3/app/models +0 -1
- data/spec/support/5.2.3/config/routes.rb +0 -1
- data/spec/support/5.2.3/db/migrate +0 -1
- data/spec/test_data/5.1.7/expected_wizard.rbi +0 -207
- data/spec/test_data/5.1.7/expected_wizard_wo_spellbook.rbi +0 -207
- data/spec/test_data/5.2.3/expected_wizard.rbi +0 -207
- 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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
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
|
data/rbi/activerecord.rbi
CHANGED
@@ -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)
|
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))
|
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))
|
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)
|
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
|
data/sorbet-rails.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{sorbet-rails}
|
3
|
-
s.version = "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 '
|
27
|
+
s.add_development_dependency 'database_cleaner', '>= 1.7.0'
|
30
28
|
end
|
data/spec/bin/install.sh
ADDED
data/spec/bin/run_all_specs.sh
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
#!/bin/bash
|
2
|
-
# A simple script to run all specs for all Rails
|
2
|
+
# A simple script to run all specs for all supported Rails branches
|
3
3
|
|
4
|
-
|
5
|
-
|
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
|
-
|
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
|
@@ -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
|
-
|
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
|
data/spec/rails_helper.rb
CHANGED
@@ -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 "
|
18
|
-
"
|
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
|
-
"
|
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}"
|
data/spec/rake_helper.rb
ADDED
@@ -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
|