market_place_api
market_place_api copied to clipboard
After chapter 7, 12 tests fail
After spending a few hours troubleshooting, I'm stuck. I followed along with the book except to change the class level embed: :ids to embed on association. I even tried cloning this repo down and I still have these errors. Am I missing something @kurenn?

@enilsen16 can you give me more details about the rspec version you are running, I'm running specs from chapter 8 and they are running fine.
I'm using rspec 3.2.1. rspec 2.x.x was giving me errors and depreciations with rails 4.2.1.
I had similar issues using active_model_serializers 0.8.0 and rails 4.2.1.
my entire gemfile:
source 'https://rubygems.org'
gem 'active_model_serializers', git: 'https://github.com/rails-api/active_model_serializers.git'
gem 'coffee-rails', '~> 4.1.0'
gem 'compass-rails'
gem 'devise'
gem 'font-awesome-rails'
gem 'furatto'
gem 'jquery-rails'
gem 'rails', '4.2.1'
gem 'sabisu_rails', github: 'IcaliaLabs/sabisu-rails', branch: 'master'
gem 'sass-rails', '~> 5.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'simple_form'
gem 'uglifier', '>= 1.3.0'
group :development do
gem 'sqlite3'
end
group :development, :test do
gem 'byebug'
gem 'factory_girl_rails'
gem 'ffaker'
gem 'spring'
gem 'web-console', '~> 2.0'
end
group :test do
gem 'rspec-collection_matchers'
gem 'rspec-rails'
gem 'shoulda-matchers'
end
The repository can be found here: https://github.com/enilsen16/rails-devise-api
Any idea what's up?
I cannot reproduce the error, I cloned your repo and ran all the tests, and they all work. What are you doing exactly?

@kurenn Hmm... ok
git pull for the lastest code and then try. There should be 72 examples...
I really appreciate your help troubleshooting :smile:
Did it worked?
No I still have these errors. I'll run through chapter 7 again, just to make sure I did everything right.
I reproduce the error with your cloned repo, and I have similar issue. If you change your active_model_serializers to 0.8.3, all tests are passing.
gem 'active_model_serializers', '0.8.3'
@enilsen16 try @florentferry solution and let me know how it goes!
@florentferry @kurenn Is it a syntax issue then with 'active_model_serializers', '0.10.0'?
Now that I am using an older version everything passes.
No, the problem comes from the gem itself and/or dependencies with Rails 4.2 and RSpec 3. I check in active_model_serializers and find 0.8.3 works well with this stack.
Hi, I'm not an expert but at GitHub's page for active_model_serializers says:
This [version 0.10.0] is not backward compatible with 0.9.0 or 0.8.0.
I was having the same problems and after having changed active_model_serializers to 0.8.3, as your suggestion, solved them.
I has caused problems on PRAX too: its Linux process was crashing. It's ok now.
Having read the console RSpec's output of the tests, it seems the version of active_model_serializers I had before caused some infinite loop and crashed. The output, may it be important:
~/projects/marketplaceapi$ bundle exec rspec spec/controllers/api/v1/products_controller_spec.rb
DEPRECATION WARNING: ** Notice: embed is deprecated. **
The use of .embed method on a Serializer will be soon removed, as this should have a global scope and not a class scope.
Please use the global .setup method instead:
ActiveModel::Serializer.setup do |config|
config.embed = :ids
config.embed_in_root = false
end
(called from class:UserSerializer at /home/pvc/projects/marketplaceapi/app/serializers/user_serializer.rb:2)
FFDEPRECATION WARNING: named_routes.helpers is deprecated, please use route_defined?(route_name) to see if a named route was defined. (called from block (4 levels) in <top (required)> at /home/pvc/projects/marketplaceapi/spec/controllers/api/v1/products_controller_spec.rb:116)
...FFDEPRECATION WARNING: named_routes.helpers is deprecated, please use route_defined?(route_name) to see if a named route was defined. (called from block (4 levels) in <top (required)> at /home/pvc/projects/marketplaceapi/spec/controllers/api/v1/products_controller_spec.rb:161)
...FFFFFFF.
Failures:
-
Api::V1::ProductsController POST #create when is successfully created renders the json representation for the product record just created Failure/Error: post :create, { user_id: user.id, product: @product_attributes } SystemStackError: stack level too deep
./app/controllers/api/v1/products_controller.rb:24:in `create'
./spec/controllers/api/v1/products_controller_spec.rb:94:in`block (4 levels) in <top (required)>'
-
Api::V1::ProductsController POST #create when is successfully created Failure/Error: post :create, { user_id: user.id, product: @product_attributes } SystemStackError: stack level too deep
./app/controllers/api/v1/products_controller.rb:24:in `create'
./spec/controllers/api/v1/products_controller_spec.rb:94:in`block (4 levels) in <top (required)>'
-
Api::V1::ProductsController PUT/PATCH #update when is successfully updated renders the json representation for the updated product Failure/Error: patch :update, { user_id: @user.id, id: @product.id, SystemStackError: stack level too deep
./app/controllers/api/v1/products_controller.rb:35:in `update'
./spec/controllers/api/v1/products_controller_spec.rb:141:in`block (4 levels) in <top (required)>'
-
Api::V1::ProductsController PUT/PATCH #update when is successfully updated Failure/Error: patch :update, { user_id: @user.id, id: @product.id, SystemStackError: stack level too deep
./app/controllers/api/v1/products_controller.rb:35:in `update'
./spec/controllers/api/v1/products_controller_spec.rb:141:in`block (4 levels) in <top (required)>'
-
Api::V1::ProductsController GET #show returns the information about a reporter on a hash Failure/Error: get :show, id: @product.id SystemStackError: stack level too deep
./app/controllers/api/v1/products_controller.rb:16:in `show'
./spec/controllers/api/v1/products_controller_spec.rb:9:in`block (3 levels) in <top (required)>'
-
Api::V1::ProductsController GET #show has the user as an embedded object Failure/Error: get :show, id: @product.id SystemStackError: stack level too deep
./app/controllers/api/v1/products_controller.rb:16:in `show'
./spec/controllers/api/v1/products_controller_spec.rb:9:in`block (3 levels) in <top (required)>'
-
Api::V1::ProductsController GET #show Failure/Error: get :show, id: @product.id SystemStackError: stack level too deep
./app/controllers/api/v1/products_controller.rb:16:in `show'
./spec/controllers/api/v1/products_controller_spec.rb:9:in`block (3 levels) in <top (required)>'
-
Api::V1::ProductsController GET #index when is not receiving any product_ids parameter returns 4 records from the database Failure/Error: get :index SystemStackError: stack level too deep
./app/controllers/api/v1/products_controller.rb:12:in `index'
./spec/controllers/api/v1/products_controller_spec.rb:41:in`block (4 levels) in <top (required)>'
-
Api::V1::ProductsController GET #index when is not receiving any product_ids parameter returns the user object into each product Failure/Error: get :index SystemStackError: stack level too deep
./app/controllers/api/v1/products_controller.rb:12:in `index'
./spec/controllers/api/v1/products_controller_spec.rb:41:in`block (4 levels) in <top (required)>'
-
Api::V1::ProductsController GET #index when is not receiving any product_ids parameter Failure/Error: get :index SystemStackError: stack level too deep # ./app/controllers/api/v1/products_controller.rb:12:in
index' # ./spec/controllers/api/v1/products_controller_spec.rb:41:inblock (4 levels) in <top (required)>' -
Api::V1::ProductsController GET #index when product_ids parameter is sent returns just the products that belong to the user Failure/Error: get :index, product_ids: @user.product_ids SystemStackError: stack level too deep # ./app/controllers/api/v1/products_controller.rb:12:in
index' # ./spec/controllers/api/v1/products_controller_spec.rb:67:inblock (4 levels) in <top (required)>'
Finished in 2.33 seconds 18 examples, 11 failures
Failed examples:
rspec ./spec/controllers/api/v1/products_controller_spec.rb:97 # Api::V1::ProductsController POST #create when is successfully created renders the json representation for the product record just created rspec ./spec/controllers/api/v1/products_controller_spec.rb:102 # Api::V1::ProductsController POST #create when is successfully created rspec ./spec/controllers/api/v1/products_controller_spec.rb:145 # Api::V1::ProductsController PUT/PATCH #update when is successfully updated renders the json representation for the updated product rspec ./spec/controllers/api/v1/products_controller_spec.rb:150 # Api::V1::ProductsController PUT/PATCH #update when is successfully updated rspec ./spec/controllers/api/v1/products_controller_spec.rb:12 # Api::V1::ProductsController GET #show returns the information about a reporter on a hash rspec ./spec/controllers/api/v1/products_controller_spec.rb:17 # Api::V1::ProductsController GET #show has the user as an embedded object rspec ./spec/controllers/api/v1/products_controller_spec.rb:22 # Api::V1::ProductsController GET #show rspec ./spec/controllers/api/v1/products_controller_spec.rb:44 # Api::V1::ProductsController GET #index when is not receiving any product_ids parameter returns 4 records from the database rspec ./spec/controllers/api/v1/products_controller_spec.rb:49 # Api::V1::ProductsController GET #index when is not receiving any product_ids parameter returns the user object into each product rspec ./spec/controllers/api/v1/products_controller_spec.rb:57 # Api::V1::ProductsController GET #index when is not receiving any product_ids parameter rspec ./spec/controllers/api/v1/products_controller_spec.rb:70 # Api::V1::ProductsController GET #index when product_ids parameter is sent returns just the products that belong to the user
Randomized with seed 55815
I have exactly the same thing as @pedrovcenteno . Reading the DEPRECATION WARNING: "The use of .embed method on a Serializer will be soon removed, as this should have a global scope and not a class scope."
I wonder then : does it still a good solution to use the embed ids and the old version of the gem or should we use something different such as the 'meta attribute' solution suggested by @kurenn in Box 7.2 ?
@RobinCaroff I would say it's fine as long you don't update to version 0.10, otherwise it will cause problems.
It is a good solution, the only thing with version 0.10 is that uses the new JSON API standard http://jsonapi.org/ but at the end of the day you choose how you want to structure the JSON response.
Hi, I just solve the problem, it's just the change of GET request syntax. You don't need rollback to old version active_model_serializers. Try this: get :show, params: { id: @product.id } instead of get :show, id: @product.id
Hope it is helpful. Good luck.
@RobinCaroff can you try with @AdamYang121's solution?
I was having the same problems and after having changed active_model_serializers to 0.8.3, as your suggestion, solved them. But I have a version of rails 6, ruby 2.6.5.

@shogmar Were you able to keep moving forward?
@shogmar Were you able to keep moving forward?
Yes, I changed the version to 0.8.3
Glad to read it!