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

Root option with empty array support #1013

Merged
merged 3 commits into from
Jul 17, 2015
Merged

Conversation

vyrak
Copy link
Contributor

@vyrak vyrak commented Jul 16, 2015

based off #987
support for :root option along with empty array fix

@@ -39,15 +45,52 @@ def test_meta_and_meta_key_attr_readers
assert_equal @serializer.meta_key, "the meta key"
end

def test_json_key_when_resource_is_empty
Copy link
Member

Choose a reason for hiding this comment

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

@vyrak I would like to keep this test, it's testing a totaly different thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't that a duplicated by https://github.com/rails-api/active_model_serializers/pull/1013/files#diff-4511bb323b8555a8103c7964418e0e40R69? I favored that version because it doesn't modify the Array class itself.

Copy link
Member

Choose a reason for hiding this comment

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

Nops, it was introduced on #1007

The json_key will become 'postcomments' rather than 'post_comments'.
Using 'underscore' instead of 'downcase' fixes the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I'm being slow and missing your point, in the build_named_collection helper method, it's returning an instance with a name of "MeResource" which gets underscored & pluralized to "me_resources".

If I understand #1007 correctly, it was a problem with an empty collection object with a name not getting transformed properly. I believe that test_json_key_with_resource_with_name_and_no_serializers is effectively testing that case, right?

Copy link
Member

Choose a reason for hiding this comment

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

Oh you are right, I didn't realized that, sorry 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, all good. The test name might've been what was confusing. Maybe it makes more sense to say test_json_key_with_empty_resource_with_name instead of test_json_key_with_resource_with_name_and_no_serializers. Though it looks like you already merged.

@joaomdmoura
Copy link
Member

@vyrak great work! I was about to pick that up, but I'm glad you made it!
I've left a comment on a specific test for you to check it 😄

@joaomdmoura
Copy link
Member

LGTM, I'm merging it and root is finally back.

joaomdmoura added a commit that referenced this pull request Jul 17, 2015
Root option with empty array support
@joaomdmoura joaomdmoura merged commit 7066b1f into rails-api:master Jul 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants