-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename #sorbet_type
→ #__tapioca_type
#2125
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,10 +330,10 @@ def name=(name); end | |
assert_equal(expected, rbi_for(:Post)) | ||
end | ||
|
||
it "honours types that declare sorbet_type" do | ||
it "honours types that respond to #__tapioca_type" do | ||
add_ruby_file("post.rb", <<~RUBY) | ||
class CustomType | ||
def self.sorbet_type | ||
def self.__tapioca_type | ||
"Integer" | ||
end | ||
end | ||
|
@@ -368,6 +368,73 @@ def tag_count=(tag_count); end | |
|
||
assert_equal(expected, rbi_for(:Post)) | ||
end | ||
|
||
it "prints a warning that #sorbet_type is deprecated" do | ||
add_ruby_file("post.rb", <<~RUBY) | ||
class CustomType | ||
def self.sorbet_type | ||
"Integer" | ||
end | ||
end | ||
|
||
class Post < JsonApiClient::Resource | ||
property :comment_count, type: :custom_type | ||
property :tag_count, type: :custom_type, default: 0 | ||
end | ||
RUBY | ||
|
||
expected = <<~RBI | ||
# typed: strong | ||
|
||
class Post | ||
include JsonApiClientResourceGeneratedMethods | ||
|
||
module JsonApiClientResourceGeneratedMethods | ||
sig { returns(T.nilable(Integer)) } | ||
def comment_count; end | ||
|
||
sig { params(comment_count: T.nilable(Integer)).returns(T.nilable(Integer)) } | ||
def comment_count=(comment_count); end | ||
|
||
sig { returns(Integer) } | ||
def tag_count; end | ||
|
||
sig { params(tag_count: Integer).returns(Integer) } | ||
def tag_count=(tag_count); end | ||
end | ||
end | ||
RBI | ||
|
||
assert_output(nil, /WARNING: `#sorbet_type` is deprecated./) do | ||
assert_equal(expected, rbi_for(:Post)) | ||
end | ||
end | ||
|
||
it "does not crash if the source location #sorbet_type is unknown" do | ||
add_ruby_file("post.rb", <<~RUBY) | ||
class CustomType | ||
def self.sorbet_type | ||
"Integer" | ||
end | ||
|
||
def self.method(name) | ||
m = super | ||
# Fake the source location, as if this was defined in a C extension. | ||
def m.source_location | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's surprisingly hard to make a method with no
and they all had it defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IKR? I could have sworn you needed to explicitly pass in the |
||
nil | ||
end | ||
m | ||
end | ||
end | ||
|
||
class Post < JsonApiClient::Resource | ||
property :comment_count, type: :custom_type | ||
property :tag_count, type: :custom_type, default: 0 | ||
end | ||
RUBY | ||
|
||
rbi_for(:Post) # Should not raise | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have |
||
end | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes that the
source_location
is available (i.e. this was defined in Ruby, and not in a C extension). Is that safe to assume, or should I guard against it?Doing so is a bit uglier:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also be
nil
if there's some metaprogramming involved, so let's play it safe. You could extract out the deprecation stuff so as to not pollute the conditional.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!