-
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
Generator now properly detects ApplicationSerializer #462
Conversation
I am not sure about this.
|
|
Hey @fab thanks for reporting this ... |
@spastorino feel free to clone this project I've been working on: https://github.com/fab/benandjerrys_api I have created an ApplicationSerializer file and all my serializers inherit from ApplicationSerializer but when I do Using the fix I've submitted in this PR that bug doesn't occur. |
ie. use |
@fab 👍 I was asking if you could provide a test case like the ones you find here https://github.com/rails-api/active_model_serializers/blob/master/test/integration/generators/scaffold_controller_generator_test.rb but no worries I will do it :) |
@spastorino whoops sorry, misunderstood you. Interestingly enough there were already test cases for this behaviour that must have been broken. I changed the method in which the presence of ApplicationSerializer is checked (not using Will go ahead and modify the docs too so people know that using ApplicationSerializer is an option. |
@spastorino updated the docs. Let me know if you'd like anything done differently but otherwise I think this PR is finally good to go. |
@fab I'd go back to the rescue nil approach. It sucks but due to Rails code reloading there's nothing else we can do. |
@spastorino sorry I have been MIA for a while. Back on top of this now. Good point about Rails code reloading. I've reverted the changes to use the rescue nil approach. The specs didn't need to be altered since they already work with this method. Fingers crossed that we can finally merge this. |
Generator now properly detects ApplicationSerializer
Today I discovered that the gem supports the use of an ApplicationSerializer file that the other serializers can inherit from.
However, using the generator to create new serializers didn't have them inheriting from ApplicationSerializer like desired. It looks like the #defined? method isn't working like intended. (It returned nil unless I had already typed ::ApplicationSerializer into the console).
What I've proposed might not be the best way to do this but I can confirm that it works for both Ruby 1.9.3 and 2.0.0.
There isn't an issue filed for this because I thought it would be a better use of resources to just provide a fix.
Thoughts?
I'm also happy to edit the docs to point out the use of ApplicationSerializer. It's a great place to extract a method that appears in all your serializers. (Had this exact use case today)