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

serializable_hash and as_json should take options = nil #965

Merged
merged 1 commit into from
Jun 25, 2015

Conversation

bf4
Copy link
Member

@bf4 bf4 commented Jun 24, 2015

per ActiveModel::Serialization#serializable_hash
https://github.com/rails/rails/blob/96bb004fc6e67cdf1b873f11ad5f8efd06949797/activemodel/lib/active_model/serialization.rb

   def serializable_hash(options = nil)
       options ||= {}

Otherwise, passing in nil to as_json or serializable_hash makes things
blow up when passing nil into attributes

Extracted from #954

per ActiveModel::Serialization#serializable_hash
https://github.com/rails/rails/blob/96bb004fc6e67cdf1b873f11ad5f8efd06949797/activemodel/lib/active_model/serialization.rb
    def serializable_hash(options = nil)
          options ||= {}

Otherwise, passing in nil to `as_json` or `serializable_hash`
makes things blow up when passing nil into attributes
@@ -27,7 +28,7 @@ def serializable_hash(options = {})
end
end
else
@hash[:data] = attributes_for_serializer(serializer, @options)
@hash[:data] = attributes_for_serializer(serializer, options)
add_resource_relationships(@hash[:data], serializer)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note there is some confusion in the method here between the options to the serializable_hash and the @options to the adapter, which I have resolved.

bf4 added a commit to bf4/active_model_serializers that referenced this pull request Jun 24, 2015
@bf4
Copy link
Member Author

bf4 commented Jun 24, 2015

Failure seems transient, related to global state issues present in master https://travis-ci.org/rails-api/active_model_serializers/jobs/68187470 Possibly related to #961

joaomdmoura added a commit that referenced this pull request Jun 25, 2015
options fedault valueserializable_hash and as_json
@joaomdmoura joaomdmoura merged commit 1bb1724 into rails-api:master Jun 25, 2015
@joaomdmoura
Copy link
Member

LGTM I'm merging it.

@@ -15,10 +15,11 @@ def initialize(serializer, options = {})
end
end

def serializable_hash(options = {})
def serializable_hash(options = nil)
options = {}
Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @bacarini for finding this bug in #1041, should be options ||= {}
:person_frowning: on me

bf4 added a commit to bf4/active_model_serializers that referenced this pull request Aug 11, 2015
@bf4 bf4 deleted the serialization_options_default_nil branch August 4, 2016 20:54
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.

2 participants