sorbet-rails 0.7.33 → 0.7.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci-master.yml +1 -1
  3. data/.github/workflows/ci.yml +1 -1
  4. data/CONTRIBUTING.md +1 -0
  5. data/Gemfile +4 -0
  6. data/README.md +1 -1
  7. data/Rakefile +27 -1
  8. data/lib/sorbet-rails/active_record_rbi_formatter.rb +1 -1
  9. data/lib/sorbet-rails/model_plugins/active_record_querying.rb +14 -0
  10. data/lib/sorbet-rails/rails_mixins/active_record_overrides.rb +1 -1
  11. data/lib/sorbet-rails/tasks/rails_rbi.rake +15 -0
  12. data/sorbet-rails.gemspec +1 -1
  13. data/spec/bin/run_all_specs.sh +1 -0
  14. data/spec/generators/rails-template.rb +2 -7
  15. data/spec/rails_helper.rb +2 -0
  16. data/spec/rake_rails_rbi_models_spec.rb +1 -1
  17. data/spec/support/v5.2/sorbet_test_cases.rb +8 -0
  18. data/spec/support/v6.0/sorbet_test_cases.rb +8 -0
  19. data/spec/support/v6.1/sorbet_test_cases.rb +8 -0
  20. data/spec/support/v7.0/.gitattributes +7 -0
  21. data/spec/support/v7.0/.gitignore +35 -0
  22. data/spec/support/v7.0/Gemfile +48 -0
  23. data/spec/support/v7.0/Gemfile.lock +218 -0
  24. data/spec/support/v7.0/README.md +24 -0
  25. data/spec/support/v7.0/Rakefile +6 -0
  26. data/spec/support/v7.0/app/assets/images/.keep +0 -0
  27. data/spec/support/v7.0/app/assets/stylesheets/application.css +1 -0
  28. data/spec/support/v7.0/app/controllers/application_controller.rb +3 -0
  29. data/spec/support/v7.0/app/controllers/concerns/.keep +0 -0
  30. data/spec/support/v7.0/app/helpers/application_helper.rb +3 -0
  31. data/spec/support/v7.0/app/helpers/bar_helper.rb +3 -0
  32. data/spec/support/v7.0/app/helpers/baz_helper.rb +3 -0
  33. data/spec/support/v7.0/app/helpers/foo_helper.rb +3 -0
  34. data/spec/support/v7.0/app/jobs/application_job.rb +8 -0
  35. data/spec/support/v7.0/app/jobs/award_house_point_hourglasses.rb +12 -0
  36. data/spec/support/v7.0/app/mailers/application_mailer.rb +5 -0
  37. data/spec/support/v7.0/app/mailers/daily_prophet_mailer.rb +9 -0
  38. data/spec/support/v7.0/app/mailers/hogwarts_acceptance_mailer.rb +29 -0
  39. data/spec/support/v7.0/app/models/application_record.rb +4 -0
  40. data/spec/support/v7.0/app/models/concerns/.keep +0 -0
  41. data/spec/support/v7.0/app/models/concerns/mythical.rb +11 -0
  42. data/spec/support/v7.0/app/models/headmaster.rb +8 -0
  43. data/spec/support/v7.0/app/models/potion.rb +6 -0
  44. data/spec/support/v7.0/app/models/robe.rb +4 -0
  45. data/spec/support/v7.0/app/models/school.rb +5 -0
  46. data/spec/support/v7.0/app/models/spell.rb +5 -0
  47. data/spec/support/v7.0/app/models/spell_book.rb +18 -0
  48. data/spec/support/v7.0/app/models/squib.rb +6 -0
  49. data/spec/support/v7.0/app/models/subject.rb +5 -0
  50. data/spec/support/v7.0/app/models/wand.rb +19 -0
  51. data/spec/support/v7.0/app/models/wizard.rb +65 -0
  52. data/spec/support/v7.0/app/views/layouts/application.html.erb +15 -0
  53. data/spec/support/v7.0/app/views/layouts/mailer.html.erb +13 -0
  54. data/spec/support/v7.0/app/views/layouts/mailer.text.erb +1 -0
  55. data/spec/support/v7.0/bin/bundle +114 -0
  56. data/spec/support/v7.0/bin/rails +4 -0
  57. data/spec/support/v7.0/bin/rake +4 -0
  58. data/spec/support/v7.0/bin/setup +33 -0
  59. data/spec/support/v7.0/config/application.rb +38 -0
  60. data/spec/support/v7.0/config/boot.rb +4 -0
  61. data/spec/support/v7.0/config/database.yml +25 -0
  62. data/spec/support/v7.0/config/environment.rb +6 -0
  63. data/spec/support/v7.0/config/environments/development.rb +69 -0
  64. data/spec/support/v7.0/config/environments/production.rb +83 -0
  65. data/spec/support/v7.0/config/environments/test.rb +61 -0
  66. data/spec/support/v7.0/config/initializers/content_security_policy.rb +26 -0
  67. data/spec/support/v7.0/config/initializers/filter_parameter_logging.rb +9 -0
  68. data/spec/support/v7.0/config/initializers/inflections.rb +17 -0
  69. data/spec/support/v7.0/config/initializers/permissions_policy.rb +12 -0
  70. data/spec/support/v7.0/config/initializers/sorbet_rails.rb +3 -0
  71. data/spec/support/v7.0/config/locales/en.yml +33 -0
  72. data/spec/support/v7.0/config/puma.rb +44 -0
  73. data/spec/support/v7.0/config/routes.rb +8 -0
  74. data/spec/support/v7.0/config/storage.yml +34 -0
  75. data/spec/support/v7.0/config.ru +6 -0
  76. data/spec/support/v7.0/db/migrate/20190620000001_create_wizards.rb +14 -0
  77. data/spec/support/v7.0/db/migrate/20190620000002_create_wands.rb +12 -0
  78. data/spec/support/v7.0/db/migrate/20190620000003_create_spell_books.rb +10 -0
  79. data/spec/support/v7.0/db/migrate/20190620000004_add_more_column_types_to_wands.rb +14 -0
  80. data/spec/support/v7.0/db/migrate/20190620000005_add_broom_to_wizard.rb +6 -0
  81. data/spec/support/v7.0/db/migrate/20190620000006_add_more_enums_to_wizard.rb +9 -0
  82. data/spec/support/v7.0/db/migrate/20190620000007_add_type_to_wizard.rb +6 -0
  83. data/spec/support/v7.0/db/migrate/20190620000008_add_robe_to_wizard.rb +8 -0
  84. data/spec/support/v7.0/db/migrate/20190620000009_add_school.rb +10 -0
  85. data/spec/support/v7.0/db/migrate/20190620000010_add_subject.rb +8 -0
  86. data/spec/support/v7.0/db/migrate/20190620000011_add_subjects_wizards.rb +8 -0
  87. data/spec/support/v7.0/db/migrate/20190620000012_add_spell.rb +8 -0
  88. data/spec/support/v7.0/db/migrate/20190620000013_add_spells_spell_books.rb +8 -0
  89. data/spec/support/v7.0/db/migrate/20190620000014_create_headmasters.rb +9 -0
  90. data/spec/support/v7.0/db/migrate/20190620000015_add_serialized_to_wizards.rb +9 -0
  91. data/spec/support/v7.0/db/schema.rb +98 -0
  92. data/spec/support/v7.0/db/seeds.rb +8 -0
  93. data/spec/support/v7.0/lib/assets/.keep +0 -0
  94. data/spec/support/v7.0/lib/mythical_rbi_plugin.rb +16 -0
  95. data/spec/support/v7.0/lib/tasks/.keep +0 -0
  96. data/spec/support/v7.0/log/.keep +0 -0
  97. data/spec/support/v7.0/sorbet_test_cases.rb +439 -0
  98. data/spec/support/v7.0/storage/.keep +0 -0
  99. data/spec/support/v7.0/tmp/.keep +0 -0
  100. data/spec/support/v7.0/tmp/pids/.keep +0 -0
  101. data/spec/support/v7.0/tmp/storage/.keep +0 -0
  102. data/spec/support/v7.0/vendor/.keep +0 -0
  103. data/spec/test_data/v5.2/expected_active_record_base.rbi +6 -0
  104. data/spec/test_data/v5.2/expected_active_record_relation.rbi +6 -0
  105. data/spec/test_data/v6.0/expected_active_record_base.rbi +6 -0
  106. data/spec/test_data/v6.0/expected_active_record_relation.rbi +6 -0
  107. data/spec/test_data/v6.1/expected_active_record_base.rbi +6 -0
  108. data/spec/test_data/v6.1/expected_active_record_relation.rbi +6 -0
  109. data/spec/test_data/v7.0/expected_active_record_base.rbi +119 -0
  110. data/spec/test_data/v7.0/expected_active_record_relation.rbi +180 -0
  111. data/spec/test_data/v7.0/expected_application_job.rbi +20 -0
  112. data/spec/test_data/v7.0/expected_application_mailer.rbi +5 -0
  113. data/spec/test_data/v7.0/expected_attachment.rbi +358 -0
  114. data/spec/test_data/v7.0/expected_award_house_point_hourglasses.rbi +20 -0
  115. data/spec/test_data/v7.0/expected_blob.rbi +394 -0
  116. data/spec/test_data/v7.0/expected_custom_application_job.rbi +21 -0
  117. data/spec/test_data/v7.0/expected_custom_application_mailer.rbi +6 -0
  118. data/spec/test_data/v7.0/expected_custom_award_house_point_hourglasses.rbi +21 -0
  119. data/spec/test_data/v7.0/expected_custom_daily_prophet_mailer.rbi +8 -0
  120. data/spec/test_data/v7.0/expected_custom_hogwarts_acceptance_mailer.rbi +21 -0
  121. data/spec/test_data/v7.0/expected_daily_prophet_mailer.rbi +7 -0
  122. data/spec/test_data/v7.0/expected_headmaster.rbi +376 -0
  123. data/spec/test_data/v7.0/expected_helpers.rbi +27 -0
  124. data/spec/test_data/v7.0/expected_helpers_with_application_and_devise_helpers.rbi +34 -0
  125. data/spec/test_data/v7.0/expected_hogwarts_acceptance_mailer.rbi +20 -0
  126. data/spec/test_data/v7.0/expected_internal_metadata.rbi +346 -0
  127. data/spec/test_data/v7.0/expected_no_routes.rbi +4 -0
  128. data/spec/test_data/v7.0/expected_potion.rbi +328 -0
  129. data/spec/test_data/v7.0/expected_record.rbi +307 -0
  130. data/spec/test_data/v7.0/expected_robe.rbi +349 -0
  131. data/spec/test_data/v7.0/expected_routes.rbi +182 -0
  132. data/spec/test_data/v7.0/expected_schema_migration.rbi +319 -0
  133. data/spec/test_data/v7.0/expected_school.rbi +349 -0
  134. data/spec/test_data/v7.0/expected_spell/habtm_spell_books.rbi +367 -0
  135. data/spec/test_data/v7.0/expected_spell.rbi +340 -0
  136. data/spec/test_data/v7.0/expected_spell_book/habtm_spells.rbi +367 -0
  137. data/spec/test_data/v7.0/expected_spell_book.rbi +499 -0
  138. data/spec/test_data/v7.0/expected_squib.rbi +1204 -0
  139. data/spec/test_data/v7.0/expected_srb_tc_output.txt +1 -0
  140. data/spec/test_data/v7.0/expected_subject/habtm_wizards.rbi +367 -0
  141. data/spec/test_data/v7.0/expected_subject.rbi +340 -0
  142. data/spec/test_data/v7.0/expected_variant_record.rbi +382 -0
  143. data/spec/test_data/v7.0/expected_wand.rbi +611 -0
  144. data/spec/test_data/v7.0/expected_wizard/habtm_subjects.rbi +367 -0
  145. data/spec/test_data/v7.0/expected_wizard.rbi +1280 -0
  146. data/spec/test_data/v7.0/expected_wizard_wo_spellbook.rbi +1274 -0
  147. metadata +243 -1
@@ -0,0 +1,8 @@
1
+ # typed: true
2
+ class AddSpell < ActiveRecord::Migration[7.0]
3
+ def change
4
+ create_table :spells do |t|
5
+ t.string :name
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # typed: true
2
+ class AddSpellsSpellBooks < ActiveRecord::Migration[7.0]
3
+ def change
4
+ create_join_table :spells, :spell_books do |t|
5
+ t.index [:spell_id, :spell_book_id]
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ # typed: true
2
+ class CreateHeadmasters < ActiveRecord::Migration[7.0]
3
+ def change
4
+ create_table :headmasters do |t|
5
+ t.references :school
6
+ t.references :wizard
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # typed: true
2
+ class AddSerializedToWizards < ActiveRecord::Migration[7.0]
3
+ def change
4
+ add_column :wizards, :owl_results, :text # Hash
5
+ add_column :wizards, :newt_subjects, :text # generic
6
+ add_column :wizards, :pets, :text # Array
7
+ add_column :wizards, :patronus_characteristics, :text # serialized as JSON, but not a JSON column type
8
+ end
9
+ end
@@ -0,0 +1,98 @@
1
+ # typed: false
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # This file is the source Rails uses to define your schema when running `bin/rails
7
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
8
+ # be faster and is potentially less error prone than running all of your
9
+ # migrations from scratch. Old migrations may fail to apply correctly if those
10
+ # migrations use external dependencies or application code.
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema[7.0].define(version: 2019_06_20_000015) do
15
+ create_table "headmasters", force: :cascade do |t|
16
+ t.integer "school_id"
17
+ t.integer "wizard_id"
18
+ t.index ["school_id"], name: "index_headmasters_on_school_id"
19
+ t.index ["wizard_id"], name: "index_headmasters_on_wizard_id"
20
+ end
21
+
22
+ create_table "robes", force: :cascade do |t|
23
+ t.integer "wizard_id"
24
+ t.index ["wizard_id"], name: "index_robes_on_wizard_id"
25
+ end
26
+
27
+ create_table "schools", force: :cascade do |t|
28
+ t.string "name"
29
+ end
30
+
31
+ create_table "spell_books", force: :cascade do |t|
32
+ t.string "name"
33
+ t.integer "wizard_id", null: false
34
+ t.integer "book_type", default: 0, null: false
35
+ t.index ["wizard_id"], name: "index_spell_books_on_wizard_id"
36
+ end
37
+
38
+ create_table "spell_books_spells", id: false, force: :cascade do |t|
39
+ t.integer "spell_id", null: false
40
+ t.integer "spell_book_id", null: false
41
+ t.index ["spell_id", "spell_book_id"], name: "index_spell_books_spells_on_spell_id_and_spell_book_id"
42
+ end
43
+
44
+ create_table "spells", force: :cascade do |t|
45
+ t.string "name"
46
+ end
47
+
48
+ create_table "subjects", force: :cascade do |t|
49
+ t.string "name"
50
+ end
51
+
52
+ create_table "subjects_wizards", id: false, force: :cascade do |t|
53
+ t.integer "subject_id"
54
+ t.integer "wizard_id"
55
+ t.index ["subject_id", "wizard_id"], name: "index_subjects_wizards_on_subject_id_and_wizard_id"
56
+ end
57
+
58
+ create_table "wands", force: :cascade do |t|
59
+ t.integer "wizard_id", null: false
60
+ t.string "wood_type"
61
+ t.integer "core_type"
62
+ t.datetime "created_at", null: false
63
+ t.datetime "updated_at", null: false
64
+ t.float "flexibility", default: 0.5, null: false
65
+ t.decimal "hardness", precision: 10, scale: 10, default: "5.0", null: false
66
+ t.decimal "reflectance", precision: 10, default: "0", null: false
67
+ t.boolean "broken", default: false, null: false
68
+ t.datetime "broken_at"
69
+ t.date "chosen_at_date"
70
+ t.time "chosen_at_time"
71
+ t.json "spell_history"
72
+ t.json "maker_info", default: "{}", null: false
73
+ t.index ["wizard_id"], name: "index_wands_on_wizard_id"
74
+ end
75
+
76
+ create_table "wizards", force: :cascade do |t|
77
+ t.string "name"
78
+ t.integer "house"
79
+ t.integer "professor"
80
+ t.string "parent_email"
81
+ t.text "notes"
82
+ t.datetime "created_at", null: false
83
+ t.datetime "updated_at", null: false
84
+ t.string "broom"
85
+ t.integer "quidditch_position"
86
+ t.integer "hair_color"
87
+ t.integer "eye_color"
88
+ t.integer "hair_length"
89
+ t.string "type", default: "Wizard", null: false
90
+ t.integer "school_id"
91
+ t.text "owl_results"
92
+ t.text "newt_subjects"
93
+ t.text "pets"
94
+ t.text "patronus_characteristics"
95
+ end
96
+
97
+ add_foreign_key "wizards", "schools"
98
+ end
@@ -0,0 +1,8 @@
1
+ # typed: strict
2
+ # This file should contain all the record creation needed to seed the database with its default values.
3
+ # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
4
+ #
5
+ # Examples:
6
+ #
7
+ # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
8
+ # Character.create(name: "Luke", movie: movies.first)
File without changes
@@ -0,0 +1,16 @@
1
+ # typed: true
2
+ class MythicalRbiPlugin < SorbetRails::ModelPlugins::Base
3
+ def generate(root)
4
+ return unless @model_class.include?(Mythical)
5
+
6
+ model_class_rbi = root.create_class(self.model_class_name)
7
+
8
+ # ActiveSupport::Concern class method will be inserted to the class
9
+ # directly. We need to also put the sig in the model class rbi directly
10
+ model_class_rbi.create_method(
11
+ 'mythicals',
12
+ class_method: true,
13
+ return_type: "T::Array[#{model_class_name}]",
14
+ )
15
+ end
16
+ end
File without changes
File without changes
@@ -0,0 +1,439 @@
1
+ # typed: true
2
+ require 'sorbet-runtime'
3
+
4
+ wand = Wand.first!
5
+ wizard = Wizard.first!
6
+ T.assert_type!(wizard, Wizard)
7
+
8
+ # -- model columns
9
+ T.assert_type!(wizard.name, T.nilable(String))
10
+
11
+ # -- time/date columns
12
+ T.assert_type!(wizard.created_at, ActiveSupport::TimeWithZone)
13
+ T.assert_type!(wand.broken_at, T.nilable(Time))
14
+ T.assert_type!(wand.chosen_at_date, T.nilable(Date))
15
+
16
+ # assert that TZ aware attributes are casted to TimeWithZone after assigning
17
+ wizard.created_at = DateTime.now
18
+ T.assert_type!(wizard.created_at, ActiveSupport::TimeWithZone)
19
+
20
+ T.assert_type!(wand.chosen_at_time, T.nilable(ActiveSupport::TimeWithZone))
21
+
22
+ # -- model associations
23
+ T.assert_type!(wizard.wand, T.nilable(Wand))
24
+ T.assert_type!(T.must(wizard.wand).wizard, Wizard)
25
+
26
+ # need the exact type to works! they aren't subclass of each other
27
+ # T.assert_type!(wizard.spell_books, SpellBook::ActiveRecord_Relation)
28
+ # T.assert_type!(wizard.spell_books, SpellBook::ActiveRecord_AssociationRelation)
29
+ T.assert_type!(wizard.spell_books, SpellBook::ActiveRecord_Associations_CollectionProxy)
30
+ T.assert_type!(wizard.spell_book_ids, T::Array[Integer])
31
+
32
+ # Finder methods -- Model
33
+ T.assert_type!(Wizard.exists?(name: 'Test'), T::Boolean)
34
+ T.assert_type!(Wizard.find(wizard.id), Wizard)
35
+ T.assert_type!(Wizard.first!, Wizard)
36
+ T.assert_type!(Wizard.first, T.nilable(Wizard))
37
+ T.assert_type!(Wizard.second!, Wizard)
38
+ T.assert_type!(Wizard.second, T.nilable(Wizard))
39
+ T.assert_type!(Wizard.third!, Wizard)
40
+ T.assert_type!(Wizard.third, T.nilable(Wizard))
41
+ T.assert_type!(Wizard.third_to_last!, Wizard)
42
+ T.assert_type!(Wizard.third_to_last, T.nilable(Wizard))
43
+ T.assert_type!(Wizard.second_to_last!, Wizard)
44
+ T.assert_type!(Wizard.second_to_last, T.nilable(Wizard))
45
+ T.assert_type!(Wizard.last!, Wizard)
46
+ T.assert_type!(Wizard.last, T.nilable(Wizard))
47
+ T.assert_type!(Wizard.first_n(5), T::Array[Wizard])
48
+ T.assert_type!(Wizard.last_n(5), T::Array[Wizard])
49
+ T.assert_type!(Wizard.find_by(name: 'Harry Potter'), T.nilable(Wizard))
50
+ T.assert_type!(Wizard.find_by!(name: 'Harry Potter'), Wizard)
51
+ T.assert_type!(Wizard.find_by_id(wizard.id), T.nilable(Wizard))
52
+ T.assert_type!(Wizard.find_by_id!(wizard.id), Wizard)
53
+ T.assert_type!(Wizard.find_or_initialize_by(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
54
+ T.assert_type!(Wizard.find_or_create_by(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
55
+ T.assert_type!(Wizard.find_or_create_by!(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
56
+ T.assert_type!(Wizard.new { |w| T.assert_type!(w, Wizard) }, Wizard)
57
+ T.assert_type!(Wizard.create(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
58
+ T.assert_type!(Wizard.create!(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
59
+ T.assert_type!(Wizard.first_or_create(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
60
+ T.assert_type!(Wizard.first_or_create!(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
61
+ T.assert_type!(Wizard.first_or_initialize { |w| T.assert_type!(w, Wizard) }, Wizard)
62
+ Wizard.find_each { |w| T.assert_type!(w, Wizard) }
63
+ T.assert_type!(Wizard.find_each, T::Enumerator[Wizard])
64
+ Wizard.find_in_batches { |w| T.assert_type!(w, T::Array[Wizard]) }
65
+ T.assert_type!(Wizard.find_in_batches, T::Enumerator[T::Array[Wizard]])
66
+ Wizard.in_batches { |w| T.assert_type!(w, Wizard::ActiveRecord_Relation) }
67
+ T.assert_type!(Wizard.in_batches, ActiveRecord::Batches::BatchEnumerator)
68
+ # T.assert_type!(Wizard.destroy_all, T::Array[Wizard]) # Ignored until we add support
69
+ T.assert_type!(Wizard.any?, T::Boolean)
70
+ T.assert_type!(Wizard.many?, T::Boolean)
71
+ T.assert_type!(Wizard.none?, T::Boolean)
72
+ T.assert_type!(Wizard.one?, T::Boolean)
73
+ # T.assert_type!(Wizard.update_all(name: 'Harry Potter'), Integer) # Ignored until we add support
74
+ # T.assert_type!(Wizard.delete_all, Integer) # Ignored until we add support
75
+ # Query methods
76
+ T.assert_type!(Wizard.all, Wizard::ActiveRecord_Relation)
77
+ T.assert_type!(Wizard.recent, Wizard::ActiveRecord_Relation) # Named scope
78
+ T.assert_type!(Wizard.Gryffindor, Wizard::ActiveRecord_Relation) # Enum scope
79
+ T.assert_type!(Wizard.Gryffindor.recent, Wizard::ActiveRecord_Relation)
80
+ T.assert_type!(Wizard.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
81
+ T.assert_type!(Wizard.where(id: 1), Wizard::ActiveRecord_Relation)
82
+ T.assert_type!(Wizard.where(id: 1).recent, Wizard::ActiveRecord_Relation)
83
+ T.assert_type!(Wizard.where.not(id: 1), Wizard::ActiveRecord_Relation)
84
+ T.assert_type!(Wizard.preload(:spell_books), Wizard::ActiveRecord_Relation)
85
+ T.assert_type!(Wizard.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
86
+ T.assert_type!(Wizard.order(:id), Wizard::ActiveRecord_Relation)
87
+ T.assert_type!(Wizard.select { |r| r.id == 1 }, T::Array[Wizard])
88
+ T.assert_type!(Wizard.select_columns(:id, :name), Wizard::ActiveRecord_Relation)
89
+ T.assert_type!(Wizard.where_missing(:wand), Wizard::ActiveRecord_Relation)
90
+ T.assert_type!(Wizard.in_order_of(:id, [1, 2, 3]), Wizard::ActiveRecord_Relation)
91
+
92
+ # Finder methods -- ActiveRecord::Relation
93
+ T.assert_type!(Wizard.all.exists?(name: 'Harry Potter'), T::Boolean)
94
+ T.assert_type!(Wizard.all.find(wizard.id), Wizard)
95
+ T.assert_type!(Wizard.all.first!, Wizard)
96
+ T.assert_type!(Wizard.all.first, T.nilable(Wizard))
97
+ T.assert_type!(Wizard.all.second!, Wizard)
98
+ T.assert_type!(Wizard.all.second, T.nilable(Wizard))
99
+ T.assert_type!(Wizard.all.third!, Wizard)
100
+ T.assert_type!(Wizard.all.third, T.nilable(Wizard))
101
+ T.assert_type!(Wizard.all.third_to_last!, Wizard)
102
+ T.assert_type!(Wizard.all.third_to_last, T.nilable(Wizard))
103
+ T.assert_type!(Wizard.all.second_to_last!, Wizard)
104
+ T.assert_type!(Wizard.all.second_to_last, T.nilable(Wizard))
105
+ T.assert_type!(Wizard.all.last!, Wizard)
106
+ T.assert_type!(Wizard.all.last, T.nilable(Wizard))
107
+ T.assert_type!(Wizard.all.first_n(5), T::Array[Wizard])
108
+ T.assert_type!(Wizard.all.last_n(5), T::Array[Wizard])
109
+ T.assert_type!(Wizard.all.find_by(name: 'Harry Potter'), T.nilable(Wizard))
110
+ T.assert_type!(Wizard.all.find_by!(name: 'Harry Potter'), Wizard)
111
+ T.assert_type!(Wizard.all.find_by_id(wizard.id), T.nilable(Wizard))
112
+ T.assert_type!(Wizard.all.find_by_id!(wizard.id), Wizard)
113
+ T.assert_type!(Wizard.all.find_or_initialize_by(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
114
+ T.assert_type!(Wizard.all.find_or_create_by(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
115
+ T.assert_type!(Wizard.all.find_or_create_by!(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
116
+ T.assert_type!(Wizard.all.new { |w| T.assert_type!(w, Wizard) }, Wizard)
117
+ T.assert_type!(Wizard.all.build { |w| T.assert_type!(w, Wizard) }, Wizard)
118
+ T.assert_type!(Wizard.all.create(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
119
+ T.assert_type!(Wizard.all.create!(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
120
+ T.assert_type!(Wizard.all.first_or_create(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
121
+ T.assert_type!(Wizard.all.first_or_create!(name: 'Harry Potter') { |w| T.assert_type!(w, Wizard) }, Wizard)
122
+ T.assert_type!(Wizard.all.first_or_initialize { |w| T.assert_type!(w, Wizard) }, Wizard)
123
+ Wizard.all.find_each { |w| T.assert_type!(w, Wizard) }
124
+ T.assert_type!(Wizard.all.find_each, T::Enumerator[Wizard])
125
+ Wizard.all.find_in_batches { |w| T.assert_type!(w, T::Array[Wizard]) }
126
+ T.assert_type!(Wizard.all.find_in_batches, T::Enumerator[T::Array[Wizard]])
127
+ Wizard.all.in_batches { |w| T.assert_type!(w, Wizard::ActiveRecord_Relation) }
128
+ T.assert_type!(Wizard.all.in_batches, ActiveRecord::Batches::BatchEnumerator)
129
+ # T.assert_type!(Wizard.all.destroy_all, T::Array[Wizard]) # Ignored until we add support
130
+ T.assert_type!(Wizard.all.any?, T::Boolean)
131
+ T.assert_type!(Wizard.all.many?, T::Boolean)
132
+ T.assert_type!(Wizard.all.none?, T::Boolean)
133
+ T.assert_type!(Wizard.all.one?, T::Boolean)
134
+ T.assert_type!(Wizard.all.any? { |r| r.id > 1 }, T::Boolean)
135
+ T.assert_type!(Wizard.all.many? { |r| r.id > 1 }, T::Boolean)
136
+ T.assert_type!(Wizard.all.none? { |r| r.id > 1 }, T::Boolean)
137
+ T.assert_type!(Wizard.all.one? { |r| r.id > 1 }, T::Boolean)
138
+
139
+ # T.assert_type!(Wizard.all.update_all(name: 'Harry Potter'), Integer) # Ignored until we add support
140
+ # T.assert_type!(Wizard.all.delete_all, Integer) # Ignored until we add support
141
+ # Query methods
142
+ T.assert_type!(Wizard.all.all, Wizard::ActiveRecord_Relation)
143
+ T.assert_type!(Wizard.all.recent, Wizard::ActiveRecord_Relation) # Named scope
144
+ T.assert_type!(Wizard.all.Gryffindor, Wizard::ActiveRecord_Relation) # Enum scope
145
+ T.assert_type!(Wizard.all.Gryffindor.recent, Wizard::ActiveRecord_Relation)
146
+ T.assert_type!(Wizard.all.Gryffindor.recent.unscoped, Wizard::ActiveRecord_Relation)
147
+ T.assert_type!(Wizard.all.where(id: 1), Wizard::ActiveRecord_Relation)
148
+ T.assert_type!(Wizard.all.where(id: 1).recent, Wizard::ActiveRecord_Relation)
149
+ T.assert_type!(Wizard.all.where.not(id: 1), Wizard::ActiveRecord_Relation)
150
+ T.assert_type!(Wizard.all.preload(:spell_books), Wizard::ActiveRecord_Relation)
151
+ T.assert_type!(Wizard.all.eager_load(:spell_books), Wizard::ActiveRecord_Relation)
152
+ T.assert_type!(Wizard.all.order(:id), Wizard::ActiveRecord_Relation)
153
+ T.assert_type!(Wizard.all.select { |r| r.id == 1 }, T::Array[Wizard])
154
+ T.assert_type!(Wizard.all.select_columns(:id, :name), Wizard::ActiveRecord_Relation)
155
+ T.assert_type!(Wizard.all.where_missing(:wand), Wizard::ActiveRecord_Relation)
156
+ T.assert_type!(Wizard.all.in_order_of(:id, [1, 2, 3]), Wizard::ActiveRecord_Relation)
157
+
158
+ # Enumerable methods
159
+ Wizard.all.each { |w| T.assert_type!(w, Wizard) }
160
+ Wizard.all.map { |w| T.assert_type!(w, Wizard) }
161
+ T.assert_type!(Wizard.all.to_a, T::Array[Wizard])
162
+ T.assert_type!(Wizard.all.empty?, T::Boolean)
163
+
164
+ # Finder methods -- CollectionProxy
165
+ spell_book = wizard.spell_books.first!
166
+ spell_books = wizard.spell_books
167
+ T.assert_type!(spell_books.exists?(name: 'Fantastic Beasts'), T::Boolean)
168
+ T.assert_type!(spell_books.find(spell_book.id), SpellBook)
169
+ T.assert_type!(spell_books.first!, SpellBook)
170
+ T.assert_type!(spell_books.first, T.nilable(SpellBook))
171
+ T.assert_type!(spell_books.second!, SpellBook)
172
+ T.assert_type!(spell_books.second, T.nilable(SpellBook))
173
+ T.assert_type!(spell_books.third!, SpellBook)
174
+ T.assert_type!(spell_books.third, T.nilable(SpellBook))
175
+ T.assert_type!(spell_books.third_to_last!, SpellBook)
176
+ T.assert_type!(spell_books.third_to_last, T.nilable(SpellBook))
177
+ T.assert_type!(spell_books.second_to_last!, SpellBook)
178
+ T.assert_type!(spell_books.second_to_last, T.nilable(SpellBook))
179
+ T.assert_type!(spell_books.last!, SpellBook)
180
+ T.assert_type!(spell_books.last, T.nilable(SpellBook))
181
+ T.assert_type!(spell_books.first_n(5), T::Array[SpellBook])
182
+ T.assert_type!(spell_books.last_n(5), T::Array[SpellBook])
183
+ T.assert_type!(spell_books.find_by(name: 'Fantastic Beasts'), T.nilable(SpellBook))
184
+ T.assert_type!(spell_books.find_by!(name: 'Fantastic Beasts'), SpellBook)
185
+ T.assert_type!(spell_books.find_by_id(spell_book.id), T.nilable(SpellBook))
186
+ T.assert_type!(spell_books.find_by_id!(spell_book.id), SpellBook)
187
+ T.assert_type!(spell_books.find_or_initialize_by(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
188
+ T.assert_type!(spell_books.find_or_create_by(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
189
+ T.assert_type!(spell_books.find_or_create_by!(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
190
+ T.assert_type!(spell_books.new { |s| T.assert_type!(s, SpellBook) }, SpellBook)
191
+ T.assert_type!(spell_books.build { |s| T.assert_type!(s, SpellBook) }, SpellBook)
192
+ T.assert_type!(spell_books.create(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
193
+ T.assert_type!(spell_books.create!(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
194
+ T.assert_type!(spell_books.first_or_create(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
195
+ T.assert_type!(spell_books.first_or_create!(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
196
+ T.assert_type!(spell_books.first_or_initialize { |s| T.assert_type!(s, SpellBook) }, SpellBook)
197
+ spell_books.find_each { |s| T.assert_type!(s, SpellBook) }
198
+ T.assert_type!(spell_books.find_each, T::Enumerator[SpellBook])
199
+ spell_books.find_in_batches { |s| T.assert_type!(s, T::Array[SpellBook]) }
200
+ T.assert_type!(spell_books.find_in_batches, T::Enumerator[T::Array[SpellBook]])
201
+ spell_books.in_batches { |s| T.assert_type!(s, SpellBook::ActiveRecord_AssociationRelation) }
202
+ T.assert_type!(spell_books.in_batches, ActiveRecord::Batches::BatchEnumerator)
203
+ # T.assert_type!(spell_books.destroy_all, T::Array[SpellBook]) # Ignored until we add support
204
+ T.assert_type!(spell_books.any?, T::Boolean)
205
+ T.assert_type!(spell_books.many?, T::Boolean)
206
+ T.assert_type!(spell_books.none?, T::Boolean)
207
+ T.assert_type!(spell_books.one?, T::Boolean)
208
+ T.assert_type!(spell_books.any? { |r| r.id > 1 }, T::Boolean)
209
+ T.assert_type!(spell_books.many? { |r| r.id > 1 }, T::Boolean)
210
+ T.assert_type!(spell_books.none? { |r| r.id > 1 }, T::Boolean)
211
+ T.assert_type!(spell_books.one? { |r| r.id > 1 }, T::Boolean)
212
+ # T.assert_type!(spell_books.update_all(name: 'Fantastic Beasts'), Integer) # Ignored until we add support
213
+ # T.assert_type!(spell_books.delete_all, Integer) # Ignored until we add support
214
+
215
+ # Query methods
216
+ T.assert_type!(spell_books.all, SpellBook::ActiveRecord_AssociationRelation)
217
+ T.assert_type!(spell_books.recent, SpellBook::ActiveRecord_AssociationRelation) # Named scope
218
+ T.assert_type!(spell_books.unclassified, SpellBook::ActiveRecord_AssociationRelation) # Enum scope
219
+ T.assert_type!(spell_books.unclassified.recent, SpellBook::ActiveRecord_AssociationRelation)
220
+ T.assert_type!(spell_books.unclassified.recent.unscoped, SpellBook::ActiveRecord_Relation) # Turns back into relation
221
+ T.assert_type!(spell_books.where(id: 1), SpellBook::ActiveRecord_AssociationRelation)
222
+ T.assert_type!(spell_books.where(id: 1).recent, SpellBook::ActiveRecord_AssociationRelation)
223
+ T.assert_type!(spell_books.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
224
+ T.assert_type!(spell_books.preload(:wizard), SpellBook::ActiveRecord_AssociationRelation)
225
+ T.assert_type!(spell_books.eager_load(:wizard), SpellBook::ActiveRecord_AssociationRelation)
226
+ T.assert_type!(spell_books.order(:id), SpellBook::ActiveRecord_AssociationRelation)
227
+ T.assert_type!(spell_books.select { |r| r.id == 1 }, T::Array[SpellBook])
228
+ T.assert_type!(spell_books.select_columns(:id, :name), SpellBook::ActiveRecord_AssociationRelation)
229
+ T.assert_type!(spell_books.where_missing(:wizard), SpellBook::ActiveRecord_AssociationRelation)
230
+ T.assert_type!(spell_books.in_order_of(:id, [1, 2, 3]), SpellBook::ActiveRecord_AssociationRelation)
231
+
232
+ # Enumerable methods
233
+ spell_books.each { |s| T.assert_type!(s, SpellBook) }
234
+ spell_books.map { |s| T.assert_type!(s, SpellBook) }
235
+ T.assert_type!(spell_books.to_a, T::Array[SpellBook])
236
+ T.assert_type!(spell_books.empty?, T::Boolean)
237
+ # Push methods
238
+ T.assert_type!(spell_books << spell_book, SpellBook::ActiveRecord_Associations_CollectionProxy)
239
+ T.assert_type!(spell_books << [spell_book], SpellBook::ActiveRecord_Associations_CollectionProxy)
240
+ T.assert_type!(spell_books.append(spell_book), SpellBook::ActiveRecord_Associations_CollectionProxy)
241
+ T.assert_type!(spell_books.append([spell_book]), SpellBook::ActiveRecord_Associations_CollectionProxy)
242
+ T.assert_type!(spell_books.push(spell_book), SpellBook::ActiveRecord_Associations_CollectionProxy)
243
+ T.assert_type!(spell_books.push([spell_book]), SpellBook::ActiveRecord_Associations_CollectionProxy)
244
+ # T.assert_type!(spell_books.concat(spell_book), SpellBook::ActiveRecord_Associations_CollectionProxy) # TODO: In Rails 5.0 and 5.1 this actually returns T::Array
245
+ # T.assert_type!(spell_books.concat([spell_book]), SpellBook::ActiveRecord_Associations_CollectionProxy) # TODO: In Rails 5.0 and 5.1 this actually returns T::Array
246
+
247
+ # finder methods -- AssociationRelation
248
+ spell_books_query = spell_books.where(wizard_id: wizard.id)
249
+ T.assert_type!(spell_books_query.exists?(name: 'Fantastic Beasts'), T::Boolean)
250
+ T.assert_type!(spell_books_query.find(spell_book.id), SpellBook)
251
+ T.assert_type!(spell_books_query.first!, SpellBook)
252
+ T.assert_type!(spell_books_query.first, T.nilable(SpellBook))
253
+ T.assert_type!(spell_books_query.second!, SpellBook)
254
+ T.assert_type!(spell_books_query.second, T.nilable(SpellBook))
255
+ T.assert_type!(spell_books_query.third!, SpellBook)
256
+ T.assert_type!(spell_books_query.third, T.nilable(SpellBook))
257
+ T.assert_type!(spell_books_query.third_to_last!, SpellBook)
258
+ T.assert_type!(spell_books_query.third_to_last, T.nilable(SpellBook))
259
+ T.assert_type!(spell_books_query.second_to_last!, SpellBook)
260
+ T.assert_type!(spell_books_query.second_to_last, T.nilable(SpellBook))
261
+ T.assert_type!(spell_books_query.last!, SpellBook)
262
+ T.assert_type!(spell_books_query.last, T.nilable(SpellBook))
263
+ T.assert_type!(spell_books_query.first_n(5), T::Array[SpellBook])
264
+ T.assert_type!(spell_books_query.last_n(5), T::Array[SpellBook])
265
+ T.assert_type!(spell_books_query.find_by(name: 'Fantastic Beasts'), T.nilable(SpellBook))
266
+ T.assert_type!(spell_books_query.find_by!(name: 'Fantastic Beasts'), SpellBook)
267
+ T.assert_type!(spell_books_query.find_by_id(spell_book.id), T.nilable(SpellBook))
268
+ T.assert_type!(spell_books_query.find_by_id!(spell_book.id), SpellBook)
269
+ T.assert_type!(spell_books_query.find_or_initialize_by(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
270
+ T.assert_type!(spell_books_query.find_or_create_by(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
271
+ T.assert_type!(spell_books_query.find_or_create_by!(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook)
272
+ T.assert_type!(spell_books_query.new { |s| T.assert_type!(s, SpellBook) }, SpellBook) # Ignored until we add support
273
+ T.assert_type!(spell_books_query.build { |s| T.assert_type!(s, SpellBook) }, SpellBook) # Ignored until we add support # Ignored until we add support
274
+ T.assert_type!(spell_books_query.create(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook) # Ignored until we add support
275
+ T.assert_type!(spell_books_query.create!(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook) # Ignored until we add support
276
+ T.assert_type!(spell_books_query.first_or_create(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook) # Ignored until we add support
277
+ T.assert_type!(spell_books_query.first_or_create!(name: 'Fantastic Beasts') { |s| T.assert_type!(s, SpellBook) }, SpellBook) # Ignored until we add support
278
+ T.assert_type!(spell_books_query.first_or_initialize { |s| T.assert_type!(s, SpellBook) }, SpellBook) # Ignored until we add support
279
+ spell_books_query.find_each { |s| T.assert_type!(s, SpellBook) }
280
+ T.assert_type!(spell_books_query.find_each, T::Enumerator[SpellBook])
281
+ spell_books_query.find_in_batches { |s| T.assert_type!(s, T::Array[SpellBook]) }
282
+ T.assert_type!(spell_books_query.find_in_batches, T::Enumerator[T::Array[SpellBook]])
283
+ spell_books_query.in_batches { |s| T.assert_type!(s, SpellBook::ActiveRecord_AssociationRelation) }
284
+ T.assert_type!(spell_books_query.in_batches, ActiveRecord::Batches::BatchEnumerator)
285
+ # T.assert_type!(spell_books_query.destroy_all, T::Array[SpellBook]) # Ignored until we add support
286
+ T.assert_type!(spell_books_query.any?, T::Boolean)
287
+ T.assert_type!(spell_books_query.many?, T::Boolean)
288
+ T.assert_type!(spell_books_query.none?, T::Boolean)
289
+ T.assert_type!(spell_books_query.one?, T::Boolean)
290
+ T.assert_type!(spell_books_query.any? { |r| r.id > 1 }, T::Boolean)
291
+ T.assert_type!(spell_books_query.many? { |r| r.id > 1 }, T::Boolean)
292
+ T.assert_type!(spell_books_query.none? { |r| r.id > 1 }, T::Boolean)
293
+ T.assert_type!(spell_books_query.one? { |r| r.id > 1 }, T::Boolean)
294
+ # T.assert_type!(spell_books_query.update_all(name: 'Fantastic Beasts'), Integer) # Ignored until we add support
295
+ # T.assert_type!(spell_books_query.delete_all, Integer) # Ignored until we add support
296
+ # Query methods
297
+ T.assert_type!(spell_books_query.all, SpellBook::ActiveRecord_AssociationRelation)
298
+ T.assert_type!(spell_books_query.recent, SpellBook::ActiveRecord_AssociationRelation) # Named scope
299
+ T.assert_type!(spell_books_query.unclassified, SpellBook::ActiveRecord_AssociationRelation) # Enum scope
300
+ T.assert_type!(spell_books_query.unclassified.recent, SpellBook::ActiveRecord_AssociationRelation)
301
+ T.assert_type!(spell_books_query.unclassified.recent.unscoped, SpellBook::ActiveRecord_Relation) # Turns back into relation
302
+ T.assert_type!(spell_books_query.where(id: 1), SpellBook::ActiveRecord_AssociationRelation)
303
+ T.assert_type!(spell_books_query.where(id: 1).recent, SpellBook::ActiveRecord_AssociationRelation)
304
+ T.assert_type!(spell_books_query.where.not(id: 1), SpellBook::ActiveRecord_AssociationRelation)
305
+ T.assert_type!(spell_books_query.preload(:wizard), SpellBook::ActiveRecord_AssociationRelation)
306
+ T.assert_type!(spell_books_query.eager_load(:wizard), SpellBook::ActiveRecord_AssociationRelation)
307
+ T.assert_type!(spell_books_query.order(:id), SpellBook::ActiveRecord_AssociationRelation)
308
+ T.assert_type!(spell_books.select { |r| r.id == 1 }, T::Array[SpellBook])
309
+ T.assert_type!(spell_books.select_columns(:id, :name), SpellBook::ActiveRecord_AssociationRelation)
310
+ # Enumerable methods
311
+ spell_books_query.each { |s| T.assert_type!(s, SpellBook) }
312
+ spell_books_query.map { |s| T.assert_type!(s, SpellBook) }
313
+ T.assert_type!(spell_books_query.to_a, T::Array[SpellBook])
314
+ T.assert_type!(spell_books_query.empty?, T::Boolean)
315
+
316
+ # Model columns
317
+ T.assert_type!(wizard.id, Integer)
318
+ T.assert_type!(wizard.id?, T::Boolean)
319
+ T.assert_type!(wizard.notes, T.nilable(String))
320
+
321
+ # Model enum
322
+ T.assert_type!(wizard.Gryffindor?, T::Boolean)
323
+ T.assert_type!(Wizard.houses, T::Hash[T.any(String, Symbol), Integer])
324
+ T.assert_type!(Wizard.brooms, T::Hash[T.any(String, Symbol), String])
325
+ T.assert_type!(spell_book.biology?, T::Boolean)
326
+ T.assert_type!(spell_book.book_type, String)
327
+ T.assert_type!(SpellBook.book_types, T::Hash[T.any(String, Symbol), Integer])
328
+ # Model T::Enum
329
+ T.assert_type!(wizard.typed_house, T.nilable(Wizard::House))
330
+ T.assert_type!(wizard.typed_broom, T.nilable(Wizard::Broom))
331
+ T.assert_type!(wizard.typed_quidditch_position, T.nilable(Wizard::QuidditchPosition))
332
+ T.assert_type!(Wizard::House, T.class_of(T::Enum))
333
+ T.assert_type!(Wizard::House::Gryffindor, Wizard::House)
334
+ T.assert_type!(Wizard::House::Hufflepuff, Wizard::House)
335
+ T.assert_type!(Wizard::House::Ravenclaw, Wizard::House)
336
+ T.assert_type!(Wizard::House::Slytherin, Wizard::House)
337
+
338
+ # Serialization
339
+ T.assert_type!(
340
+ wizard.owl_results,
341
+ T.nilable(T::Hash[T.untyped, T.untyped])
342
+ )
343
+ T.assert_type!(
344
+ wizard.newt_subjects,
345
+ T.nilable(T.any(T::Array[T.untyped], T::Boolean, Float, T::Hash[T.untyped, T.untyped], Integer, String))
346
+ )
347
+ T.assert_type!(
348
+ wizard.patronus_characteristics,
349
+ T.nilable(ActiveRecord::Coders::JSON),
350
+ )
351
+ T.assert_type!(wizard.pets, T.nilable(T::Array[T.untyped]))
352
+
353
+ # Mythical plugin
354
+ T.assert_type!(Wand.mythicals, T::Array[Wand])
355
+
356
+ # Mailers
357
+ T.assert_type!(HogwartsAcceptanceMailer.notify(wizard), ActionMailer::MessageDelivery)
358
+
359
+ # Jobs
360
+ T.assert_type!(
361
+ AwardHousePointHourglasses.perform_later(student: wizard, point: 10),
362
+ AwardHousePointHourglasses
363
+ )
364
+ AwardHousePointHourglasses.perform_now(student: wizard, point: 10)
365
+ AwardHousePointHourglasses.
366
+ set(queue: :daily, wait: 5.minutes).
367
+ perform_later(student: wizard, point: 10)
368
+ AwardHousePointHourglasses.
369
+ set(priority: 10, wait_until: Time.now.tomorrow).
370
+ perform_later(student: wizard, point: 10)
371
+
372
+ T.assert_type!(wizard.broom_nimbus?, T::Boolean)
373
+ T.assert_type!(wizard.color_brown_eyes?, T::Boolean)
374
+ T.assert_type!(wizard.quidditch_keeper?, T::Boolean)
375
+ T.assert_type!(wizard.brown_hair?, T::Boolean)
376
+
377
+ # Relations
378
+ T.assert_type!(wizard.spell_books.any?, T::Boolean)
379
+ T.assert_type!(wizard.spell_books.none?, T::Boolean)
380
+ T.assert_type!(wizard.spell_books.one?, T::Boolean)
381
+
382
+ # -- Custom ActionController::Parameters Methods
383
+ class MyActionParams < T::Struct
384
+ class Info < T::Struct
385
+ const :birthday, Date
386
+ const :friends, T::Array[String]
387
+ const :grandson, T.nilable(String)
388
+ end
389
+
390
+ const :age, Integer
391
+ const :name, String
392
+ const :info, Info
393
+ end
394
+
395
+ params = ActionController::Parameters.new({
396
+ age: 11,
397
+ name: 'Harry Potter',
398
+ info: {
399
+ birthday: Date.parse('1980-07-31'),
400
+ friends: [
401
+ 'Hermione',
402
+ 'Ron',
403
+ ],
404
+ grandson: nil,
405
+ },
406
+ })
407
+
408
+ typed_params = TypedParams[MyActionParams].new.extract!(params)
409
+ T.assert_type!(typed_params, MyActionParams)
410
+
411
+ # -- pluck to tstruct
412
+ class WizardStruct < T::Struct
413
+ const :name, String
414
+ const :house, T.nilable(String)
415
+ end
416
+
417
+ T.assert_type!(Wizard.pluck_to_tstruct(TA[WizardStruct].new), T::Array[WizardStruct])
418
+ T.assert_type!(Wizard.all.pluck_to_tstruct(TA[WizardStruct].new), T::Array[WizardStruct])
419
+
420
+ Wizard.pluck_to_tstruct(TA[WizardStruct].new).each do |row|
421
+ T.assert_type!(row, WizardStruct)
422
+ end
423
+ Wizard.all.pluck_to_tstruct(TA[WizardStruct].new).each do |row|
424
+ T.assert_type!(row, WizardStruct)
425
+ end
426
+
427
+ # -- GeneratedUrlHelpers
428
+ class TestHelper
429
+ include GeneratedUrlHelpers
430
+ end
431
+
432
+ T.assert_type!(TestHelper.new.test_index_path, String)
433
+ # need to set this config for _url methods
434
+ Rails.application.routes.default_url_options = {
435
+ protocol: 'http',
436
+ host: 'localhost',
437
+ port: 3000,
438
+ }
439
+ T.assert_type!(TestHelper.new.test_index_url, String)
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -56,6 +56,12 @@ class ActiveRecord::Base
56
56
  sig { returns(T.attached_class) }
57
57
  def self.last!; end
58
58
 
59
+ sig { returns(T.nilable(T.attached_class)) }
60
+ def self.take; end
61
+
62
+ sig { returns(T.attached_class) }
63
+ def self.take!; end
64
+
59
65
  sig { params(attributes: T.untyped, block: T.nilable(T.proc.params(object: T.attached_class).void)).returns(T.attached_class) }
60
66
  def self.create(attributes = nil, &block); end
61
67
 
@@ -58,6 +58,12 @@ class ActiveRecord::Relation
58
58
  sig { returns(Elem) }
59
59
  def last!; end
60
60
 
61
+ sig { returns(T.nilable(Elem)) }
62
+ def take; end
63
+
64
+ sig { returns(Elem) }
65
+ def take!; end
66
+
61
67
  sig { params(attributes: T.untyped, block: T.nilable(T.proc.params(object: Elem).void)).returns(Elem) }
62
68
  def create(attributes = nil, &block); end
63
69
 
@@ -56,6 +56,12 @@ class ActiveRecord::Base
56
56
  sig { returns(T.attached_class) }
57
57
  def self.last!; end
58
58
 
59
+ sig { returns(T.nilable(T.attached_class)) }
60
+ def self.take; end
61
+
62
+ sig { returns(T.attached_class) }
63
+ def self.take!; end
64
+
59
65
  sig { params(attributes: T.untyped, block: T.nilable(T.proc.params(object: T.attached_class).void)).returns(T.attached_class) }
60
66
  def self.create(attributes = nil, &block); end
61
67