sorbet-rails 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +0 -2
- data/CONTRIBUTING.md +2 -4
- data/Gemfile +0 -4
- data/README.md +41 -7
- data/Rakefile +3 -14
- data/lib/bundled_rbi/parameters.rbi +4 -26
- data/lib/bundled_rbi/pluck_to_tstruct.rbi +22 -0
- data/lib/bundled_rbi/type_assert.rbi +27 -0
- data/lib/sorbet-rails/gem_plugins/elastic_search_plugin.rb +40 -0
- data/lib/sorbet-rails/gem_plugins/shrine_plugin.rb +76 -0
- data/lib/sorbet-rails/model_plugins/active_record_assoc.rb +2 -11
- data/lib/sorbet-rails/model_plugins/active_record_attribute.rb +3 -6
- data/lib/sorbet-rails/model_plugins/active_record_querying.rb +10 -2
- data/lib/sorbet-rails/model_plugins/plugins.rb +6 -0
- data/lib/sorbet-rails/rails_mixins/pluck_to_tstruct.rb +33 -0
- data/lib/sorbet-rails/railtie.rb +4 -0
- data/lib/sorbet-rails/sorbet_utils.rb +4 -1
- data/lib/sorbet-rails/tasks/rails_rbi.rake +16 -6
- data/sorbet-rails.gemspec +1 -1
- data/spec/bin/run_all_specs.sh +0 -1
- data/spec/bin/run_spec.sh +4 -6
- data/spec/generators/rails-template.rb +67 -124
- data/spec/generators/sorbet_test_cases.rb +26 -16
- data/spec/pluck_to_tstruct_spec.rb +79 -0
- data/spec/rails_helper.rb +0 -2
- data/spec/rake_rails_rbi_models_spec.rb +2 -0
- data/spec/sorbet_utils_spec.rb +37 -0
- data/spec/spec_helper.rb +1 -2
- data/spec/support/v5.0/Gemfile.lock +6 -6
- data/spec/support/v5.0/config/boot.rb +1 -1
- data/spec/support/v5.0/config/initializers/sorbet_rails.rb +1 -1
- data/spec/support/v5.0/db/migrate/20190620000004_add_more_column_types_to_wands.rb +1 -1
- data/spec/support/v5.0/sorbet_test_cases.rb +26 -16
- data/spec/support/v5.1/Gemfile.lock +6 -6
- data/spec/support/v5.1/config/boot.rb +1 -1
- data/spec/support/v5.1/config/initializers/sorbet_rails.rb +1 -1
- data/spec/support/v5.1/db/migrate/20190620000004_add_more_column_types_to_wands.rb +1 -1
- data/spec/support/v5.1/sorbet_test_cases.rb +26 -16
- data/spec/support/v5.2/Gemfile.lock +6 -6
- data/spec/support/v5.2/config/boot.rb +1 -1
- data/spec/support/v5.2/config/initializers/sorbet_rails.rb +1 -1
- data/spec/support/v5.2/db/migrate/20190620000004_add_more_column_types_to_wands.rb +1 -1
- data/spec/support/v5.2/sorbet_test_cases.rb +26 -16
- data/spec/support/v6.0/Gemfile.lock +6 -6
- data/spec/support/v6.0/config/boot.rb +1 -1
- data/spec/support/v6.0/config/initializers/sorbet_rails.rb +1 -1
- data/spec/support/v6.0/config/initializers/wrap_parameters.rb +1 -1
- data/spec/support/v6.0/db/migrate/20190620000004_add_more_column_types_to_wands.rb +1 -1
- data/spec/support/v6.0/sorbet_test_cases.rb +26 -16
- data/spec/test_data/v5.0/expected_internal_metadata.rbi +209 -197
- data/spec/test_data/v5.0/expected_potion.rbi +208 -196
- data/spec/test_data/v5.0/expected_schema_migration.rbi +209 -197
- data/spec/test_data/v5.0/expected_spell_book.rbi +208 -196
- data/spec/test_data/v5.0/expected_squib.rbi +209 -197
- data/spec/test_data/v5.0/expected_wand.rbi +208 -196
- data/spec/test_data/v5.0/expected_wizard.rbi +209 -197
- data/spec/test_data/v5.0/expected_wizard_wo_spellbook.rbi +209 -197
- data/spec/test_data/v5.1/expected_internal_metadata.rbi +213 -213
- data/spec/test_data/v5.1/expected_potion.rbi +212 -212
- data/spec/test_data/v5.1/expected_schema_migration.rbi +213 -213
- data/spec/test_data/v5.1/expected_spell_book.rbi +212 -212
- data/spec/test_data/v5.1/expected_squib.rbi +213 -213
- data/spec/test_data/v5.1/expected_wand.rbi +212 -212
- data/spec/test_data/v5.1/expected_wizard.rbi +213 -213
- data/spec/test_data/v5.1/expected_wizard_wo_spellbook.rbi +213 -213
- data/spec/test_data/v5.2/expected_attachment.rbi +212 -212
- data/spec/test_data/v5.2/expected_blob.rbi +212 -212
- data/spec/test_data/v5.2/expected_internal_metadata.rbi +213 -213
- data/spec/test_data/v5.2/expected_potion.rbi +212 -212
- data/spec/test_data/v5.2/expected_schema_migration.rbi +213 -213
- data/spec/test_data/v5.2/expected_spell_book.rbi +212 -212
- data/spec/test_data/v5.2/expected_squib.rbi +213 -213
- data/spec/test_data/v5.2/expected_wand.rbi +212 -212
- data/spec/test_data/v5.2/expected_wizard.rbi +213 -213
- data/spec/test_data/v5.2/expected_wizard_wo_spellbook.rbi +213 -213
- data/spec/test_data/v6.0/expected_attachment.rbi +244 -244
- data/spec/test_data/v6.0/expected_blob.rbi +244 -244
- data/spec/test_data/v6.0/expected_internal_metadata.rbi +245 -245
- data/spec/test_data/v6.0/expected_potion.rbi +244 -244
- data/spec/test_data/v6.0/expected_schema_migration.rbi +245 -245
- data/spec/test_data/v6.0/expected_spell_book.rbi +244 -244
- data/spec/test_data/v6.0/expected_squib.rbi +245 -245
- data/spec/test_data/v6.0/expected_wand.rbi +244 -244
- data/spec/test_data/v6.0/expected_wizard.rbi +245 -245
- data/spec/test_data/v6.0/expected_wizard_wo_spellbook.rbi +245 -245
- metadata +8 -185
- data/spec/bin/install.sh +0 -11
- data/spec/support/v4.2/.gitignore +0 -17
- data/spec/support/v4.2/Gemfile +0 -33
- data/spec/support/v4.2/Gemfile.lock +0 -128
- data/spec/support/v4.2/README.rdoc +0 -28
- data/spec/support/v4.2/Rakefile +0 -6
- data/spec/support/v4.2/app/assets/images/.keep +0 -0
- data/spec/support/v4.2/app/assets/stylesheets/application.css +0 -15
- data/spec/support/v4.2/app/controllers/application_controller.rb +0 -6
- data/spec/support/v4.2/app/controllers/concerns/.keep +0 -0
- data/spec/support/v4.2/app/helpers/application_helper.rb +0 -3
- data/spec/support/v4.2/app/helpers/bar_helper.rb +0 -3
- data/spec/support/v4.2/app/helpers/baz_helper.rb +0 -3
- data/spec/support/v4.2/app/helpers/foo_helper.rb +0 -3
- data/spec/support/v4.2/app/mailers/.keep +0 -0
- data/spec/support/v4.2/app/mailers/application_mailer.rb +0 -3
- data/spec/support/v4.2/app/mailers/daily_prophet_mailer.rb +0 -9
- data/spec/support/v4.2/app/mailers/hogwarts_acceptance_mailer.rb +0 -13
- data/spec/support/v4.2/app/models/.keep +0 -0
- data/spec/support/v4.2/app/models/application_record.rb +0 -4
- data/spec/support/v4.2/app/models/concerns/.keep +0 -0
- data/spec/support/v4.2/app/models/concerns/mythical.rb +0 -11
- data/spec/support/v4.2/app/models/potion.rb +0 -5
- data/spec/support/v4.2/app/models/spell_book.rb +0 -11
- data/spec/support/v4.2/app/models/squib.rb +0 -6
- data/spec/support/v4.2/app/models/wand.rb +0 -19
- data/spec/support/v4.2/app/models/wizard.rb +0 -29
- data/spec/support/v4.2/app/views/layouts/application.html.erb +0 -13
- data/spec/support/v4.2/bin/bundle +0 -3
- data/spec/support/v4.2/bin/rails +0 -4
- data/spec/support/v4.2/bin/rake +0 -4
- data/spec/support/v4.2/bin/setup +0 -29
- data/spec/support/v4.2/config.ru +0 -4
- data/spec/support/v4.2/config/application.rb +0 -36
- data/spec/support/v4.2/config/boot.rb +0 -4
- data/spec/support/v4.2/config/database.yml +0 -25
- data/spec/support/v4.2/config/environment.rb +0 -6
- data/spec/support/v4.2/config/environments/development.rb +0 -29
- data/spec/support/v4.2/config/environments/production.rb +0 -68
- data/spec/support/v4.2/config/environments/test.rb +0 -43
- data/spec/support/v4.2/config/initializers/backtrace_silencers.rb +0 -8
- data/spec/support/v4.2/config/initializers/cookies_serializer.rb +0 -4
- data/spec/support/v4.2/config/initializers/filter_parameter_logging.rb +0 -5
- data/spec/support/v4.2/config/initializers/inflections.rb +0 -17
- data/spec/support/v4.2/config/initializers/mime_types.rb +0 -5
- data/spec/support/v4.2/config/initializers/session_store.rb +0 -4
- data/spec/support/v4.2/config/initializers/sorbet_rails.rb +0 -3
- data/spec/support/v4.2/config/initializers/to_time_preserves_timezone.rb +0 -11
- data/spec/support/v4.2/config/initializers/wrap_parameters.rb +0 -15
- data/spec/support/v4.2/config/locales/en.yml +0 -23
- data/spec/support/v4.2/config/routes.rb +0 -58
- data/spec/support/v4.2/db/migrate/20190620000001_create_wizards.rb +0 -13
- data/spec/support/v4.2/db/migrate/20190620000002_create_wands.rb +0 -12
- data/spec/support/v4.2/db/migrate/20190620000003_create_spell_books.rb +0 -10
- data/spec/support/v4.2/db/migrate/20190620000004_add_more_column_types_to_wands.rb +0 -17
- data/spec/support/v4.2/db/migrate/20190620000005_add_broom_to_wizard.rb +0 -6
- data/spec/support/v4.2/db/migrate/20190620000007_add_type_to_wizard.rb +0 -6
- data/spec/support/v4.2/db/schema.rb +0 -49
- data/spec/support/v4.2/db/seeds.rb +0 -8
- data/spec/support/v4.2/lib/assets/.keep +0 -0
- data/spec/support/v4.2/lib/mythical_rbi_plugin.rb +0 -16
- data/spec/support/v4.2/lib/tasks/.keep +0 -0
- data/spec/support/v4.2/log/.keep +0 -0
- data/spec/support/v4.2/sorbet_test_cases.rb +0 -238
- data/spec/support/v4.2/test/controllers/.keep +0 -0
- data/spec/support/v4.2/test/fixtures/.keep +0 -0
- data/spec/support/v4.2/test/helpers/.keep +0 -0
- data/spec/support/v4.2/test/integration/.keep +0 -0
- data/spec/support/v4.2/test/mailers/.keep +0 -0
- data/spec/support/v4.2/test/models/.keep +0 -0
- data/spec/support/v4.2/test/test_helper.rb +0 -11
- data/spec/support/v4.2/typed-override.yaml +0 -2
- data/spec/support/v4.2/vendor/assets/stylesheets/.keep +0 -0
- data/spec/test_data/v4.2/expected_application_mailer.rbi +0 -5
- data/spec/test_data/v4.2/expected_daily_prophet_mailer.rbi +0 -7
- data/spec/test_data/v4.2/expected_helpers.rbi +0 -22
- data/spec/test_data/v4.2/expected_helpers_with_application_and_devise_helpers.rbi +0 -29
- data/spec/test_data/v4.2/expected_hogwarts_acceptance_mailer.rbi +0 -10
- data/spec/test_data/v4.2/expected_no_routes.rbi +0 -4
- data/spec/test_data/v4.2/expected_potion.rbi +0 -657
- data/spec/test_data/v4.2/expected_routes.rbi +0 -19
- data/spec/test_data/v4.2/expected_spell_book.rbi +0 -771
- data/spec/test_data/v4.2/expected_squib.rbi +0 -912
- data/spec/test_data/v4.2/expected_srb_tc_output.txt +0 -65
- data/spec/test_data/v4.2/expected_wand.rbi +0 -873
- data/spec/test_data/v4.2/expected_wizard.rbi +0 -912
- data/spec/test_data/v4.2/expected_wizard_wo_spellbook.rbi +0 -912
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'sorbet-rails/model_rbi_formatter'
|
3
|
+
|
4
|
+
RSpec.describe SorbetRails::PluckToTStruct do
|
5
|
+
let!(:harry) do
|
6
|
+
Wizard.create!(
|
7
|
+
name: 'Harry Potter',
|
8
|
+
house: :Gryffindor,
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
let!(:hermione) do
|
13
|
+
Wizard.create!(
|
14
|
+
name: 'Hermione Granger',
|
15
|
+
house: :Gryffindor,
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
class WizardName < T::Struct
|
20
|
+
const :name, String
|
21
|
+
|
22
|
+
def ==(other)
|
23
|
+
return false unless other.is_a?(self.class)
|
24
|
+
name == other.name
|
25
|
+
end
|
26
|
+
|
27
|
+
def eql?(other)
|
28
|
+
self == other
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class WizardT < T::Struct
|
33
|
+
const :name, String
|
34
|
+
const :house, String
|
35
|
+
|
36
|
+
def ==(other)
|
37
|
+
return false unless other.is_a?(self.class)
|
38
|
+
name == other.name && house == other.house
|
39
|
+
end
|
40
|
+
|
41
|
+
def eql?(other)
|
42
|
+
self == other
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
shared_examples 'pluck_to_tstruct' do |struct_type, expected_values|
|
47
|
+
it 'plucks correctly from ActiveRecord model' do
|
48
|
+
plucked = Wizard.pluck_to_tstruct(TA[struct_type].new)
|
49
|
+
expect(plucked).to match_array(expected_values)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'plucks correctly from ActiveRecord relation' do
|
53
|
+
plucked = Wizard.all.pluck_to_tstruct(TA[struct_type].new)
|
54
|
+
expect(plucked).to match_array(expected_values)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'pluck 1 attribute' do
|
59
|
+
it_should_behave_like 'pluck_to_tstruct', WizardName, [
|
60
|
+
WizardName.new(name: "Harry Potter"),
|
61
|
+
WizardName.new(name: "Hermione Granger"),
|
62
|
+
]
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'pluck multiple attributes' do
|
66
|
+
it_should_behave_like 'pluck_to_tstruct', WizardT, [
|
67
|
+
WizardT.new(name: "Harry Potter", house: "Gryffindor"),
|
68
|
+
WizardT.new(name: "Hermione Granger", house: "Gryffindor"),
|
69
|
+
]
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'given a wrong type' do
|
73
|
+
it 'should raise error' do
|
74
|
+
expect {
|
75
|
+
plucked = Wizard.pluck_to_tstruct(TA[String].new)
|
76
|
+
}.to raise_error(SorbetRails::PluckToTStruct::UnexpectedType)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/spec/rails_helper.rb
CHANGED
@@ -44,6 +44,7 @@ RSpec.describe 'rake rails_rbi:models', type: :task do
|
|
44
44
|
expect_files(
|
45
45
|
base_dir: generated_dir_path,
|
46
46
|
files: [
|
47
|
+
'squib.rbi',
|
47
48
|
'wizard.rbi',
|
48
49
|
]
|
49
50
|
)
|
@@ -55,6 +56,7 @@ RSpec.describe 'rake rails_rbi:models', type: :task do
|
|
55
56
|
base_dir: generated_dir_path,
|
56
57
|
files: [
|
57
58
|
'spell_book.rbi',
|
59
|
+
'squib.rbi',
|
58
60
|
'wizard.rbi',
|
59
61
|
]
|
60
62
|
)
|
data/spec/sorbet_utils_spec.rb
CHANGED
@@ -33,6 +33,13 @@ class SorbetUtilsExampleClass
|
|
33
33
|
def method_with_block_return(&p1); end
|
34
34
|
|
35
35
|
def method_without_sig(p1, p2, *p3, p4:, **p5, &p6); end
|
36
|
+
|
37
|
+
sig { params(p1: String, p2: String, p3: Integer).void }
|
38
|
+
def method_with_default(p1, p2='abc', p3: 123); end
|
39
|
+
|
40
|
+
def method_with_missing_args_name(p1, *); end
|
41
|
+
|
42
|
+
def method_with_missing_kwargs_name(p1, **); end
|
36
43
|
end
|
37
44
|
|
38
45
|
RSpec.describe SorbetRails::SorbetUtils do
|
@@ -123,4 +130,34 @@ RSpec.describe SorbetRails::SorbetUtils do
|
|
123
130
|
Parameter.new('&p6', type: 'T.untyped'),
|
124
131
|
])
|
125
132
|
end
|
133
|
+
|
134
|
+
# TODO it doesn't know how to extract default values from method yet
|
135
|
+
# Would have to rely on reading & parsing the source code :(
|
136
|
+
# it 'works when method arguments have default' do
|
137
|
+
# method_def = SorbetUtilsExampleClass.instance_method(:method_with_default)
|
138
|
+
# parameters = SorbetRails::SorbetUtils.parameters_from_method_def(method_def)
|
139
|
+
# expect(parameters).to match_array([
|
140
|
+
# Parameter.new('p1', type: 'T.untyped'),
|
141
|
+
# Parameter.new('p2', type: 'T.untyped', default: '"abc"'),
|
142
|
+
# Parameter.new('p3:', type: 'T.untyped', default: '123'),
|
143
|
+
# ])
|
144
|
+
# end
|
145
|
+
|
146
|
+
it 'works when method args doesnt have name' do
|
147
|
+
method_def = SorbetUtilsExampleClass.instance_method(:method_with_missing_args_name)
|
148
|
+
parameters = SorbetRails::SorbetUtils.parameters_from_method_def(method_def)
|
149
|
+
expect(parameters).to match_array([
|
150
|
+
Parameter.new('p1', type: 'T.untyped'),
|
151
|
+
Parameter.new('*_', type: 'T.untyped'),
|
152
|
+
])
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'works when method kwargs doesnt have name' do
|
156
|
+
method_def = SorbetUtilsExampleClass.instance_method(:method_with_missing_kwargs_name)
|
157
|
+
parameters = SorbetRails::SorbetUtils.parameters_from_method_def(method_def)
|
158
|
+
expect(parameters).to match_array([
|
159
|
+
Parameter.new('p1', type: 'T.untyped'),
|
160
|
+
Parameter.new('**_', type: 'T.untyped'),
|
161
|
+
])
|
162
|
+
end
|
126
163
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../..
|
3
3
|
specs:
|
4
|
-
sorbet-rails (0.5.
|
4
|
+
sorbet-rails (0.5.7)
|
5
5
|
parlour (~> 0.8.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -68,7 +68,7 @@ GEM
|
|
68
68
|
nio4r (2.5.1)
|
69
69
|
nokogiri (1.10.4)
|
70
70
|
mini_portile2 (~> 2.4.0)
|
71
|
-
parlour (0.8.
|
71
|
+
parlour (0.8.1)
|
72
72
|
rainbow (~> 3.0.0)
|
73
73
|
sorbet-runtime
|
74
74
|
puma (3.12.1)
|
@@ -100,10 +100,10 @@ GEM
|
|
100
100
|
thor (>= 0.18.1, < 2.0)
|
101
101
|
rainbow (3.0.0)
|
102
102
|
rake (12.3.3)
|
103
|
-
sorbet (0.4.
|
104
|
-
sorbet-static (= 0.4.
|
105
|
-
sorbet-runtime (0.4.
|
106
|
-
sorbet-static (0.4.
|
103
|
+
sorbet (0.4.4775)
|
104
|
+
sorbet-static (= 0.4.4775)
|
105
|
+
sorbet-runtime (0.4.4775)
|
106
|
+
sorbet-static (0.4.4775-universal-darwin-14)
|
107
107
|
sprockets (3.7.2)
|
108
108
|
concurrent-ruby (~> 1.0)
|
109
109
|
rack (> 1, < 3)
|
@@ -9,7 +9,7 @@ class AddMoreColumnTypesToWands < ActiveRecord::Migration[5.0]
|
|
9
9
|
add_column :wands, :chosen_at_date, :date
|
10
10
|
add_column :wands, :chosen_at_time, :time
|
11
11
|
# JSON column type is only supported on 5.2 or higher
|
12
|
-
unless ['
|
12
|
+
unless ['5.0', '5.1'].include?(ENV['RAILS_VERSION'])
|
13
13
|
add_column :wands, :spell_history, :json
|
14
14
|
add_column :wands, :maker_info, :json, null: false, default: '{}'
|
15
15
|
end
|
@@ -17,12 +17,7 @@ T.assert_type!(wand.chosen_at_date, T.nilable(Date))
|
|
17
17
|
wizard.created_at = DateTime.now
|
18
18
|
T.assert_type!(wizard.created_at, ActiveSupport::TimeWithZone)
|
19
19
|
|
20
|
-
|
21
|
-
# note: this is expected to fail in Rails 4.2, because in that version only
|
22
|
-
# `datetime` fields are made time zone aware (so this will have the type
|
23
|
-
# `T.nilable(Time)` instead)
|
24
|
-
T.assert_type!(wand.chosen_at_time, T.nilable(ActiveSupport::TimeWithZone))
|
25
|
-
end
|
20
|
+
T.assert_type!(wand.chosen_at_time, T.nilable(ActiveSupport::TimeWithZone))
|
26
21
|
|
27
22
|
# -- model associations
|
28
23
|
T.assert_type!(wizard.wand, T.nilable(Wand))
|
@@ -87,9 +82,9 @@ spell_books = wizard.spell_books
|
|
87
82
|
T.assert_type!(spell_books.exists?(name: 'Fantastic Beasts'), T::Boolean)
|
88
83
|
T.assert_type!(spell_books.find(spell_book.id), SpellBook)
|
89
84
|
T.assert_type!(spell_books.first!, SpellBook)
|
90
|
-
# T.assert_type!(spell_books.first, T.nilable(SpellBook)) # TODO fix sig for
|
85
|
+
# T.assert_type!(spell_books.first, T.nilable(SpellBook)) # TODO fix sig for 5.0
|
91
86
|
T.assert_type!(spell_books.last!, SpellBook)
|
92
|
-
# T.assert_type!(spell_books.last, T.nilable(SpellBook)) # TODO fix sig for
|
87
|
+
# T.assert_type!(spell_books.last, T.nilable(SpellBook)) # TODO fix sig for 5.0
|
93
88
|
T.assert_type!(spell_books.first_n(5), T::Array[SpellBook])
|
94
89
|
T.assert_type!(spell_books.last_n(5), T::Array[SpellBook])
|
95
90
|
T.assert_type!(spell_books.find_by(name: 'Fantastic Beasts'), T.nilable(SpellBook))
|
@@ -109,9 +104,9 @@ spell_books_query = spell_books.where(id: 1)
|
|
109
104
|
T.assert_type!(spell_books_query.exists?(name: 'Fantastic Beasts'), T::Boolean)
|
110
105
|
T.assert_type!(spell_books_query.find(spell_book.id), SpellBook)
|
111
106
|
T.assert_type!(spell_books_query.first!, SpellBook)
|
112
|
-
# T.assert_type!(spell_books_query.first, T.nilable(SpellBook)) # TODO fix sig for
|
107
|
+
# T.assert_type!(spell_books_query.first, T.nilable(SpellBook)) # TODO fix sig for 5.0
|
113
108
|
T.assert_type!(spell_books_query.last!, SpellBook)
|
114
|
-
# T.assert_type!(spell_books_query.last, T.nilable(SpellBook)) # TODO fix sig for
|
109
|
+
# T.assert_type!(spell_books_query.last, T.nilable(SpellBook)) # TODO fix sig for 5.0
|
115
110
|
T.assert_type!(spell_books_query.first_n(5), T::Array[SpellBook])
|
116
111
|
T.assert_type!(spell_books_query.last_n(5), T::Array[SpellBook])
|
117
112
|
T.assert_type!(spell_books_query.find_by(name: 'Fantastic Beasts'), T.nilable(SpellBook))
|
@@ -180,12 +175,10 @@ T.assert_type!(Wand.mythicals, T::Array[Wand])
|
|
180
175
|
|
181
176
|
T.assert_type!(HogwartsAcceptanceMailer.notify(wizard), ActionMailer::MessageDelivery)
|
182
177
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
T.assert_type!(wizard.brown_hair?, T::Boolean)
|
188
|
-
end
|
178
|
+
T.assert_type!(wizard.broom_nimbus?, T::Boolean)
|
179
|
+
T.assert_type!(wizard.color_brown_eyes?, T::Boolean)
|
180
|
+
T.assert_type!(wizard.quidditch_keeper?, T::Boolean)
|
181
|
+
T.assert_type!(wizard.brown_hair?, T::Boolean)
|
189
182
|
|
190
183
|
# -- Custom ActionController::Parameters Methods
|
191
184
|
params = ActionController::Parameters.new({
|
@@ -236,3 +229,20 @@ T.assert_type!(
|
|
236
229
|
params.fetch_typed(:nonexistence, TA[T::Array[Integer]].new, []),
|
237
230
|
T::Array[Integer],
|
238
231
|
)
|
232
|
+
|
233
|
+
|
234
|
+
# -- pluck to tstruct
|
235
|
+
class WizardStruct < T::Struct
|
236
|
+
const :name, String
|
237
|
+
const :house, T.nilable(String)
|
238
|
+
end
|
239
|
+
|
240
|
+
T.assert_type!(Wizard.pluck_to_tstruct(TA[WizardStruct].new), T::Array[WizardStruct])
|
241
|
+
T.assert_type!(Wizard.all.pluck_to_tstruct(TA[WizardStruct].new), T::Array[WizardStruct])
|
242
|
+
|
243
|
+
Wizard.pluck_to_tstruct(TA[WizardStruct].new).each do |row|
|
244
|
+
T.assert_type!(row, WizardStruct)
|
245
|
+
end
|
246
|
+
Wizard.all.pluck_to_tstruct(TA[WizardStruct].new).each do |row|
|
247
|
+
T.assert_type!(row, WizardStruct)
|
248
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../..
|
3
3
|
specs:
|
4
|
-
sorbet-rails (0.5.
|
4
|
+
sorbet-rails (0.5.7)
|
5
5
|
parlour (~> 0.8.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -69,7 +69,7 @@ GEM
|
|
69
69
|
nio4r (2.5.1)
|
70
70
|
nokogiri (1.10.4)
|
71
71
|
mini_portile2 (~> 2.4.0)
|
72
|
-
parlour (0.8.
|
72
|
+
parlour (0.8.1)
|
73
73
|
rainbow (~> 3.0.0)
|
74
74
|
sorbet-runtime
|
75
75
|
puma (3.12.1)
|
@@ -101,10 +101,10 @@ GEM
|
|
101
101
|
thor (>= 0.18.1, < 2.0)
|
102
102
|
rainbow (3.0.0)
|
103
103
|
rake (12.3.3)
|
104
|
-
sorbet (0.4.
|
105
|
-
sorbet-static (= 0.4.
|
106
|
-
sorbet-runtime (0.4.
|
107
|
-
sorbet-static (0.4.
|
104
|
+
sorbet (0.4.4775)
|
105
|
+
sorbet-static (= 0.4.4775)
|
106
|
+
sorbet-runtime (0.4.4775)
|
107
|
+
sorbet-static (0.4.4775-universal-darwin-14)
|
108
108
|
sprockets (3.7.2)
|
109
109
|
concurrent-ruby (~> 1.0)
|
110
110
|
rack (> 1, < 3)
|
@@ -9,7 +9,7 @@ class AddMoreColumnTypesToWands < ActiveRecord::Migration[5.1]
|
|
9
9
|
add_column :wands, :chosen_at_date, :date
|
10
10
|
add_column :wands, :chosen_at_time, :time
|
11
11
|
# JSON column type is only supported on 5.2 or higher
|
12
|
-
unless ['
|
12
|
+
unless ['5.0', '5.1'].include?(ENV['RAILS_VERSION'])
|
13
13
|
add_column :wands, :spell_history, :json
|
14
14
|
add_column :wands, :maker_info, :json, null: false, default: '{}'
|
15
15
|
end
|
@@ -17,12 +17,7 @@ T.assert_type!(wand.chosen_at_date, T.nilable(Date))
|
|
17
17
|
wizard.created_at = DateTime.now
|
18
18
|
T.assert_type!(wizard.created_at, ActiveSupport::TimeWithZone)
|
19
19
|
|
20
|
-
|
21
|
-
# note: this is expected to fail in Rails 4.2, because in that version only
|
22
|
-
# `datetime` fields are made time zone aware (so this will have the type
|
23
|
-
# `T.nilable(Time)` instead)
|
24
|
-
T.assert_type!(wand.chosen_at_time, T.nilable(ActiveSupport::TimeWithZone))
|
25
|
-
end
|
20
|
+
T.assert_type!(wand.chosen_at_time, T.nilable(ActiveSupport::TimeWithZone))
|
26
21
|
|
27
22
|
# -- model associations
|
28
23
|
T.assert_type!(wizard.wand, T.nilable(Wand))
|
@@ -87,9 +82,9 @@ spell_books = wizard.spell_books
|
|
87
82
|
T.assert_type!(spell_books.exists?(name: 'Fantastic Beasts'), T::Boolean)
|
88
83
|
T.assert_type!(spell_books.find(spell_book.id), SpellBook)
|
89
84
|
T.assert_type!(spell_books.first!, SpellBook)
|
90
|
-
# T.assert_type!(spell_books.first, T.nilable(SpellBook)) # TODO fix sig for
|
85
|
+
# T.assert_type!(spell_books.first, T.nilable(SpellBook)) # TODO fix sig for 5.0
|
91
86
|
T.assert_type!(spell_books.last!, SpellBook)
|
92
|
-
# T.assert_type!(spell_books.last, T.nilable(SpellBook)) # TODO fix sig for
|
87
|
+
# T.assert_type!(spell_books.last, T.nilable(SpellBook)) # TODO fix sig for 5.0
|
93
88
|
T.assert_type!(spell_books.first_n(5), T::Array[SpellBook])
|
94
89
|
T.assert_type!(spell_books.last_n(5), T::Array[SpellBook])
|
95
90
|
T.assert_type!(spell_books.find_by(name: 'Fantastic Beasts'), T.nilable(SpellBook))
|
@@ -109,9 +104,9 @@ spell_books_query = spell_books.where(id: 1)
|
|
109
104
|
T.assert_type!(spell_books_query.exists?(name: 'Fantastic Beasts'), T::Boolean)
|
110
105
|
T.assert_type!(spell_books_query.find(spell_book.id), SpellBook)
|
111
106
|
T.assert_type!(spell_books_query.first!, SpellBook)
|
112
|
-
# T.assert_type!(spell_books_query.first, T.nilable(SpellBook)) # TODO fix sig for
|
107
|
+
# T.assert_type!(spell_books_query.first, T.nilable(SpellBook)) # TODO fix sig for 5.0
|
113
108
|
T.assert_type!(spell_books_query.last!, SpellBook)
|
114
|
-
# T.assert_type!(spell_books_query.last, T.nilable(SpellBook)) # TODO fix sig for
|
109
|
+
# T.assert_type!(spell_books_query.last, T.nilable(SpellBook)) # TODO fix sig for 5.0
|
115
110
|
T.assert_type!(spell_books_query.first_n(5), T::Array[SpellBook])
|
116
111
|
T.assert_type!(spell_books_query.last_n(5), T::Array[SpellBook])
|
117
112
|
T.assert_type!(spell_books_query.find_by(name: 'Fantastic Beasts'), T.nilable(SpellBook))
|
@@ -180,12 +175,10 @@ T.assert_type!(Wand.mythicals, T::Array[Wand])
|
|
180
175
|
|
181
176
|
T.assert_type!(HogwartsAcceptanceMailer.notify(wizard), ActionMailer::MessageDelivery)
|
182
177
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
T.assert_type!(wizard.brown_hair?, T::Boolean)
|
188
|
-
end
|
178
|
+
T.assert_type!(wizard.broom_nimbus?, T::Boolean)
|
179
|
+
T.assert_type!(wizard.color_brown_eyes?, T::Boolean)
|
180
|
+
T.assert_type!(wizard.quidditch_keeper?, T::Boolean)
|
181
|
+
T.assert_type!(wizard.brown_hair?, T::Boolean)
|
189
182
|
|
190
183
|
# -- Custom ActionController::Parameters Methods
|
191
184
|
params = ActionController::Parameters.new({
|
@@ -236,3 +229,20 @@ T.assert_type!(
|
|
236
229
|
params.fetch_typed(:nonexistence, TA[T::Array[Integer]].new, []),
|
237
230
|
T::Array[Integer],
|
238
231
|
)
|
232
|
+
|
233
|
+
|
234
|
+
# -- pluck to tstruct
|
235
|
+
class WizardStruct < T::Struct
|
236
|
+
const :name, String
|
237
|
+
const :house, T.nilable(String)
|
238
|
+
end
|
239
|
+
|
240
|
+
T.assert_type!(Wizard.pluck_to_tstruct(TA[WizardStruct].new), T::Array[WizardStruct])
|
241
|
+
T.assert_type!(Wizard.all.pluck_to_tstruct(TA[WizardStruct].new), T::Array[WizardStruct])
|
242
|
+
|
243
|
+
Wizard.pluck_to_tstruct(TA[WizardStruct].new).each do |row|
|
244
|
+
T.assert_type!(row, WizardStruct)
|
245
|
+
end
|
246
|
+
Wizard.all.pluck_to_tstruct(TA[WizardStruct].new).each do |row|
|
247
|
+
T.assert_type!(row, WizardStruct)
|
248
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../../..
|
3
3
|
specs:
|
4
|
-
sorbet-rails (0.5.
|
4
|
+
sorbet-rails (0.5.7)
|
5
5
|
parlour (~> 0.8.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -76,7 +76,7 @@ GEM
|
|
76
76
|
nio4r (2.5.1)
|
77
77
|
nokogiri (1.10.4)
|
78
78
|
mini_portile2 (~> 2.4.0)
|
79
|
-
parlour (0.8.
|
79
|
+
parlour (0.8.1)
|
80
80
|
rainbow (~> 3.0.0)
|
81
81
|
sorbet-runtime
|
82
82
|
puma (3.12.1)
|
@@ -109,10 +109,10 @@ GEM
|
|
109
109
|
thor (>= 0.19.0, < 2.0)
|
110
110
|
rainbow (3.0.0)
|
111
111
|
rake (12.3.3)
|
112
|
-
sorbet (0.4.
|
113
|
-
sorbet-static (= 0.4.
|
114
|
-
sorbet-runtime (0.4.
|
115
|
-
sorbet-static (0.4.
|
112
|
+
sorbet (0.4.4775)
|
113
|
+
sorbet-static (= 0.4.4775)
|
114
|
+
sorbet-runtime (0.4.4775)
|
115
|
+
sorbet-static (0.4.4775-universal-darwin-14)
|
116
116
|
sprockets (3.7.2)
|
117
117
|
concurrent-ruby (~> 1.0)
|
118
118
|
rack (> 1, < 3)
|