-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Include type restriction on getters in JSON/mapping #5935
Changes from 3 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 |
---|---|---|
|
@@ -507,6 +507,14 @@ describe "JSON mapping" do | |
json.bar?.should be_false | ||
end | ||
|
||
it "defines query getter with class restriction" do | ||
{% begin %} | ||
{% methods = JSONWithQueryAttributes.methods %} | ||
{{methods.find(&.name.==("foo?")).return_type}}.should eq(Bool) | ||
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. Add the whitespaces, please... |
||
{{methods.find(&.name.==("bar?")).return_type}}.should eq(Bool) | ||
{% end %} | ||
end | ||
|
||
it "defines non-query setter and presence methods" do | ||
json = JSONWithQueryAttributes.from_json(%({"foo": false})) | ||
json.bar_present?.should be_false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ module JSON | |
{% end %} | ||
|
||
{% if value[:getter] == nil ? true : value[:getter] %} | ||
def {{key.id}} | ||
def {{key.id}} : {{value[:type]}} {{ (value[:nilable] ? "?" : "").id }} | ||
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.
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. This is exactly as it is in the setter above. Should both be changed? 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 parses with whitespace, but it would be better to remove it. |
||
@{{value[:key_id]}} | ||
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.
I'm not sure it makes sense to have a spec for this if there is no real reflection. The return type is optional anyway.
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.
It being optional doesn't mean we shouldn't be testing the optional case of supplying it.