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

Namespace separator fix for type field in jsonapi adapter #1216

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 2 additions & 5 deletions lib/active_model/serializer/adapter/json_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ def serializable_hash_for_single_resource(options)
end

def resource_identifier_type_for(serializer)
if ActiveModel::Serializer.config.jsonapi_resource_type == :singular
serializer.object.class.model_name.singular
else
serializer.object.class.model_name.plural
end
type = serializer.object.class.name.demodulize.underscore
Copy link
Member

Choose a reason for hiding this comment

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

For the moment, I would argue this is incorrect. e.g User::Mailer, Admin::Mailer would both resolve to mailer. and see #1029 (comment)

ActiveModel::Serializer.config.jsonapi_resource_type == :singular ? type : type.pluralize
end

def resource_identifier_id_for(serializer)
Expand Down
4 changes: 2 additions & 2 deletions test/adapter/json_api/linked_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_include_multiple_posts_and_linked
assert_equal expected, alt_adapter.serializable_hash[:included]
end

def test_underscore_model_namespace_for_linked_resource_type
def test_remove_model_namespace_for_linked_resource_type
spammy_post = Post.new(id: 123)
spammy_post.related = [Spam::UnrelatedLink.new(id: 456)]
serializer = SpammyPostSerializer.new(spammy_post)
Expand All @@ -212,7 +212,7 @@ def test_underscore_model_namespace_for_linked_resource_type
expected = {
related: {
data: [{
type: 'spam_unrelated_links',
type: 'unrelated_links',
Copy link
Member

Choose a reason for hiding this comment

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

why did the expectation change here?

aside, the type should probably be spam:unrelated_links' orspam-unrelated_links`

json-api/json-api#850 (the issue I made that the jsonapi forum references )

(aside, why is there a related= writer on Post that is important? just confusing naming)

id: '456'
}]
}
Expand Down