-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Singularize and capitalize polymorphic types #1615
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,38 @@ class ActiveRecordTest < ActiveSupport::TestCase | |
|
||
def setup | ||
@resource = ARModels::Post.new | ||
@image = Image.create | ||
end | ||
|
||
def test_active_model_record_with_validated_polymorphic_relationship_creation | ||
picture = Picture.create!(picture_params) | ||
|
||
assert_equal(@image, picture.imageable) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks good |
||
end | ||
|
||
private | ||
|
||
def picture_params | ||
params = ActionController::Parameters.new({ | ||
data: { | ||
attributes: { | ||
title: 'Picture Title' | ||
}, | ||
relationships: { | ||
imageable: { | ||
data: { | ||
type: 'images', | ||
id: @image.id | ||
} | ||
}, | ||
}, | ||
type: 'pictures' | ||
} | ||
}) | ||
|
||
ActiveModelSerializers::Deserialization.jsonapi_parse!( | ||
params.to_unsafe_h, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol |
||
polymorphic: [:imageable] | ||
) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,7 @@ def test_polymorphic | |
src: 'http://example.com/images/productivity.png', | ||
author_id: nil, | ||
photographer_id: '9', | ||
photographer_type: 'people', | ||
photographer_type: 'Person', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, this shouldn't change, as this is the serialization There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. n/m I take that back. You're right. I misread that this was the input being changed, not the output. Rails needs this format as the deserialized attributes. |
||
comment_ids: %w(1 2) | ||
} | ||
assert_equal(expected, parsed_hash) | ||
|
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.
we probably want to encapsulate this singular.capitalize logic in a transformer cc @remear
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.
could we
camelize
instead ofcapitalize
? that would add support for snake cased multi word model names, right?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.
assoc_data.fetch('type').underscore.classify
Using [] is dangerous.