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

Error on defining an anonymous serializer class #353

Open
daniel-illi opened this issue Nov 22, 2018 · 0 comments
Open

Error on defining an anonymous serializer class #353

daniel-illi opened this issue Nov 22, 2018 · 0 comments

Comments

@daniel-illi
Copy link

We have a baseclass ApiSerializer with the shared behaviour of all subclasses.
In our testsuite we use an anonymous subclass of ApiSerializer to test some behaviour.
I.e. like this:

serializer_klass = Class.new(ApiSerializer) do
    has_one :some_thing
    has_many :many_things

    attribute :foo { 'bar' }
end

This gives me an error:

#<NoMethodError: undefined method `end_with?' for nil:NilClass>

["fast_jsonapi-1.5/lib/fast_jsonapi/object_serializer.rb:133:in `reflected_record_type'",
 "fast_jsonapi-1.5/lib/fast_jsonapi/object_serializer.rb:125:in `inherited'",
 "(irb):17:in `initialize'",
 "(irb):17:in `new'",
...
]

ObjectSerializer tries to determine the record type based on the class name, but does not take into account that the class can be unnamed:
if self.name.end_with?('Serializer')

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

No branches or pull requests

1 participant