-
Notifications
You must be signed in to change notification settings - Fork 10
Fix issue #9 #10
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
Fix issue #9 #10
Conversation
Tests the current, desired behavior Also displays the current, unwanted behavior
It's the least I can do for opening it in the first place.
richmolj
left a comment
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.
Thanks for raising and addressing the issue @happycollision - had one small comment then would love to merge.
lib/jsonapi_spec_helpers/helpers.rb
Outdated
|
|
||
| def validation_errors | ||
| @validation_errors ||= {}.tap do |errors| | ||
| return if json['errors'].nil? |
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 we change this like to
errors = json['errors'] || []
errors.each do |e|That way the method always returns a hash, and something like validation_errors[:foo] won't fail
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.
The errors variable is already taken as the self of {}.tap. But yes, I have made that change by using a different variable.
I am more familiar with Javascript than Ruby, so I thought returning would still return—wait. I literally just thought of a better way as I was writing my explanation of what I did...
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.
Okay. It is fixed below.
My heart knows Ruby better than Javascript, but my brain knows Javascript better than Ruby.
This extra expectation ensures that `validation_errors[:any_key]` also won't throw an error.
b7eab66 to
9c32ac8
Compare
|
I did a fixup to the last commit when I realized I had a better solution where we didn't need a new local variable. |
|
Thanks for the help @happycollision, much appreciated ❤️ ! LGTM 👍 |
|
Released in 0.4.7 |
This will keep the
validation_errorshelper from being less-than-helpful.