kurenn / market_place_api

The API on Rails tutorial application
142 stars 70 forks source link

Chapter 10 Pagination issue: Meta object in render json: products, meta: is not rendered in ActiveModelSerializer 0.10.2 #78

Closed ghost closed 7 years ago

ghost commented 7 years ago

The json_response from the newer version of ActiveModelSerializer is

expected [{:id=>2184, :title=>"GPS Receiver", :price=>"48.2190411765297", :published=>false, :user=>{:id=>3520, :email=>"frankie@dare.co.uk", :auth_token=>"aqDpo9eRQd18CgVZJhNu"}}, {:id=>2185, :title=>"Gel Compressor", :price=>"46.5630253827439", :published=>false, :user=>{:id=>3521, :email=>"zita@kuhlman.biz", :auth_token=>"_AT51pnv4iTQ5M6UkYhp"}}, {:id=>2186, :title=>"Output Side Amplifier", :price=>"38.7696783474247", :published=>false, :user=>{:id=>3522, :email=>"madisen.quitzon@becker.ca", :auth_token=>"rx6F6hei_tHNCE6LNpzV"}}, {:id=>2187, :title=>"Tag Component", :price=>"117.246549157407", :published=>false, :user=>{:id=>3523, :email=>"maybell_dibbert@ruecker.ca", :auth_token=>"GD-W7Pnje6JjEdsoMvF-"}}] to respond tohas_key?``

The meta object is not included. Just an array of products even without [:products] key.

Maybe I need to learn http://jsonapi.org/ first and come back to this tutorial to conform to the new standards.

Can anybody give a hint on how to make these tests pass under the new gem or implement http://jsonapi.org/format/#fetching-pagination ?

Thank you!

kurenn commented 7 years ago

If you are using version 0.10.X of active model serializers I recommend you change the adapter to json, something like:

https://github.com/IcaliaLabs/pager-api#a-note-on-active-model-serializers-010