Skip to content

Add a kwarg to override relationships rendered in jsonapi errors #6

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/jsonapi_errorable/validatable.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
module JsonapiErrorable
module Validatable
def render_errors_for(record)
validation = Serializers::Validation.new \
record, deserialized_params.relationships
# @param relationships: nil [ Hash or FalseClass ] list of relationships whose errors should be serialized
# Defaults to the deserialized data.relationships of Json:api Payload
# @param record [ ActiveModel ] Object that implements ActiveModel
def render_errors_for(record, relationships: {})
relationships || deserialized_params.relationships
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would never hit the right side of || since this defaults to {}. Maybe line 6 should be nil, but you can still pass a custom hash?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey thanks and sorry about that, I'm still working on it and the test, didn't mean to push that commit ^^"
Regarding the test, since it's quite a big integration test I need some more time to work on it


validation = Serializers::Validation.new(record, relationships)

render \
json: { errors: validation.errors },
Expand Down