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

SerializableResource handles no serializer like controller #1616

Merged

Conversation

bf4
Copy link
Member

@bf4 bf4 commented Mar 25, 2016

Fixes when passing in a resource to SerializableResource outside of a controller, a
resource without a known Serializer will no longer raise
NoMethodError: undefined method 'new' for nil:NilClass, but will behave like the
controller and just use the resource, as is.

Follows #1580 (comment)

# For compatibility with the JSON renderer: `json.to_json(options) if json.is_a?(String)`.
# Otherwise, since `serializable_resource` is not a string, the renderer would call
# `to_json` on a String and given odd results, such as `"".to_json #=> '""'`
serializable_resource.adapter.is_a?(String) ? serializable_resource.adapter : serializable_resource
Copy link
Member

Choose a reason for hiding this comment

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

Does that mean that someone would try to serialize a string directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

No... as per the comment, this handles render {foo: :bar}.to_json

@bf4
Copy link
Member Author

bf4 commented Mar 27, 2016

@groyoh I don't have these failures locally. It makes it hard for me to debug

@groyoh
Copy link
Member

groyoh commented Mar 27, 2016

@bf4 yeah, I actually tried it it out too earlier. Restarted the build too and couldn't figure out what's going on.

@bf4 bf4 force-pushed the more_controller_logic_to_serializable_resource branch from 277c5a3 to 84197e4 Compare March 29, 2016 01:04
@bf4 bf4 force-pushed the more_controller_logic_to_serializable_resource branch 2 times, most recently from c206c7c to 6a60d45 Compare March 29, 2016 02:10
@bf4
Copy link
Member Author

bf4 commented Mar 29, 2016

@groyoh I believe it's related to the notifications being passed a nil serializer since that can now happen

@bf4 bf4 force-pushed the more_controller_logic_to_serializable_resource branch from 6a60d45 to ec5dc49 Compare March 29, 2016 02:34
@bf4 bf4 merged commit 5af8536 into rails-api:master Mar 29, 2016
@bf4 bf4 deleted the more_controller_logic_to_serializable_resource branch March 29, 2016 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants