Skip to content
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 a bug with has-one relationship authorizers #124

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion lib/jsonapi/authorization/authorizing_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def related_models_with_context
when Hash # polymorphic relationship
resource_class = @resource_klass.resource_for(assoc_value[:type].to_s)
resource_class.find_by_key(assoc_value[:id], context: context)._model
else
when Array
resource_class = resource_class_for_relationship(assoc_name)
resources = resource_class.find_by_keys(assoc_value, context: context)
resources.map(&:_model).tap do |scoped_records|
Expand All @@ -324,6 +324,9 @@ def related_models_with_context
fail JSONAPI::Exceptions::RecordNotFound, related_ids
end
end
else
resource_class = resource_class_for_relationship(assoc_name)
resource_class.find_by_key(assoc_value, context: context)._model
end

{
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/included_resources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@
{
relation_type: :to_one,
relation_name: :author,
records: [existing_author]
records: existing_author
},
{
relation_type: :to_many,
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/tricky_operations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
[{
relation_name: :article,
relation_type: :to_one,
records: [article]
records: article
}]
end

Expand Down