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

After chapter 7, 12 tests fail #19

Open
enilsen16 opened this issue Apr 28, 2015 · 20 comments
Open

After chapter 7, 12 tests fail #19

enilsen16 opened this issue Apr 28, 2015 · 20 comments

Comments

@enilsen16
Copy link

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?

screen shot 2015-04-27 at 11 44 25 pm

@kurenn
Copy link
Owner

kurenn commented Apr 28, 2015

@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.

@enilsen16
Copy link
Author

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?

@kurenn
Copy link
Owner

kurenn commented May 1, 2015

I cannot reproduce the error, I cloned your repo and ran all the tests, and they all work. What are you doing exactly?

screen shot 2015-05-01 at 4 30 25 pm

@enilsen16
Copy link
Author

@kurenn Hmm... ok

git pull for the lastest code and then try. There should be 72 examples...

I really appreciate your help troubleshooting 😄

@kurenn
Copy link
Owner

kurenn commented May 5, 2015

Did it worked?

@enilsen16
Copy link
Author

No I still have these errors. I'll run through chapter 7 again, just to make sure I did everything right.

@florentferry
Copy link

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'

@kurenn
Copy link
Owner

kurenn commented May 6, 2015

@enilsen16 try @florentferry solution and let me know how it goes!

@enilsen16
Copy link
Author

@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.

@florentferry
Copy link

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.

@pedrovcenteno
Copy link

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.

@pedrovcenteno
Copy link

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:

  1. 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)>'

  2. 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)>'

  3. 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)>'

  4. 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)>'

  5. 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)>'

  6. 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)>'

  7. 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)>'

  8. 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)>'

  9. 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)>'

  10. 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)>'

  11. 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

@RobinCaroff
Copy link

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 ?

@kurenn
Copy link
Owner

kurenn commented Sep 30, 2015

@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.

@AdamYang121
Copy link

AdamYang121 commented Mar 23, 2018

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.

@kurenn
Copy link
Owner

kurenn commented Mar 23, 2018

@RobinCaroff can you try with @AdamYang121's solution?

@shogmar
Copy link

shogmar commented Jun 2, 2020

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.

12
123

@kurenn
Copy link
Owner

kurenn commented Jun 12, 2020

@shogmar Were you able to keep moving forward?

@shogmar
Copy link

shogmar commented Jun 15, 2020

@shogmar Were you able to keep moving forward?

Yes, I changed the version to 0.8.3

@kurenn
Copy link
Owner

kurenn commented Jun 17, 2020

Glad to read it!

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

7 participants