-
Notifications
You must be signed in to change notification settings - Fork 60
Do not throw not found error when resource relationship is null #69
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
Do not throw not found error when resource relationship is null #69
Conversation
|
Ok, now I see what's happening. Thanks for the PR! Do you think it would be better if it were somehow possible to tell the authorizer that the relationship is about to get emptied? What if the expected authorizer call would look like this instead? allow_operation(
'replace_fields',
article,
[{
relation_name: :author,
relation_type: :to_one,
records: nil
}]
)These kind of relationship specs currently reside in a slightly badly named file describe 'PATCH /articles/:id (nullifying to-one relationship)' do
# spec code that is similar to the
# 'PATCH /articles/:id (mass-modifying relationships)' spec code
# ...
endWould you also be open to change the behavior to match that? Thanks for your contribution! If you want me to open up something more, feel free to ask me anything |
|
@valscion
For this one I had error, so I left as it is for now: #<InstanceDouble(JSONAPI::Authorization::DefaultPunditAuthorizer) (anonymous)> received :replace_fields with unexpected arguments
expected: (#<Article id: 1012824740, external_id: "3", author_id: 676971205, blank_value: nil>, [{:relation_name=>:author, :relation_type=>:to_one, :records=>nil}])
got: (#<Article id: 1012824740, external_id: "3", author_id: 676971205, blank_value: nil>, []) |
Ah, but actually that error highlights the behavior that we would actually want to have. We would want to allow the authorizer to have a way of handling this situation. However, in the Do you want to go ahead and do these changes? That would mean these changes:
Does this sound reasonable to you? |
| data[rel_type].flat_map do |assoc_name, assoc_value| | ||
| case assoc_value | ||
| when nil | ||
| next |
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 don't think we need to change the def related_models method at all. Your bug fix should only be necessary to touch the related_models_with_context method.
|
|
||
| before do | ||
| allow_any_instance_of(UserPolicy::Scope).to receive(:resolve) | ||
| .and_return(user_policy_scope) |
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 spec would actually pass even if we didn't handle UserPolicy::Scope at all, so I guess these user_policy_scope things could be removed.
|
@valscion Fixed 😉 |
|
Wow, looking great! Thanks for the fast turn-around 💞 Are you OK with me adding you to the list of contributors in the README? |
valscion
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!
|
Sure, cheers ! 😉 |
|
I'll release alpha4 version after I've had lunch. Thanks for your contributions! |
|
Thanks! |
|
Released v1.0.0.alpha4 with this change :) |
|
Perfect! thanks for the release 🚀 |
This PR extends #54 with added tests.