Rails 4 + Rails-API + RSpec + Devise - Trouble testing controllers with custom devise routes -


I am currently building an API and trying to test my controller. I am getting errors related to this issue that I can not solve. API :: V1 :: Session Controller Description to describe "Post / Session":

  # /spec/requests/api/v1/sessions_spec.rb requires 'spec_helper' is. It gives "user authentication token, on success" user = factorial Create (user: user_params = {"user" => {"email" => User.email, "password" => user.password}} .to_json post "/ API / V1 / session" , User_param is expected (feedback stats). Aec (200) jsn = jsan prs (feedback). Hope (jsn ['authentication_token']). End of end (user.authentication_token) end # / app / controllers /api/v1/sessions_controller.rb class API :: V1 :: session controller & lt; Devise :: SessionsController response_to: json def end end # routes.rb MyApplication :: Application.routes.draw namespace: API, default: { named format: json} : V1 do devise_scope: users post a 'session' = & gt; 'create session #', like: & gt; 'login' end end ending   

error I currently Receiving:

  1) API :: V1 :: Sessions session on controller post / success, user authentication token failure / error: post "/ api / v1 / sessions" , user_params AbstractController :: ActionNotFound: could not find devise mapping for path "/ api / v1 / sessions". This could be due to two reasons: 1) You forgot to wrap your passage through the scope block, for example: devise_scope: User "/ some / route" = & gt; get receive. "Some_devise_controller" end 2) You are testing a device controller bypassing the router, if so, you can explicitly tell the Devise which mapping is to use: @ request.env ["devise. mapping "] = Devise.mappings [: User] # ./spec/requests/api/v1/sessions_spec.rb:21:in` In Block (Level 3) & lt; Top (required) & gt; 'I have searched around to solve this issue, and have tried a bunch of different questions. The solution to the question here () has given the code below in a block first Put in the block.  
  Before: Make each request. ANV ['devise.mapping'] = Devise.mappings [: user] end   

But when I add my controller, I get another error which says:

  1) API :: V1 :: Session Controller posts success time / session, user authentication token failure / error returns: request.env ['devise.mapping'] = Devise.mappings [ : User] NoMethodError: For the undefined method `NV 'zero: NilClass # ./spec/requests/ API / V1 / session_spCRB: 7:` Block (level 2) & lt; Top (required) & gt;   

The solution to another question here () is to say that include: test helper tries to add to space, but when I do this , Then the same error is returned.

Using the current gems:

Rail (4.0.2)

Rail-API (0.2.0)

Rspec-rails (2.14.1)

devise (3.2.2)

Using these two tutorials as a guide guide:

< / p>

Any thanks will be appreciated, thanks!

I think I may have solved this issue. It seems that I have blocked the API namespace block Was to add to devise_:

  MyApplication :: Application.routes.draw Please devise_for: users, skip: [: session,: password ,: registration] namespace: API, default: {Format: : JSON} Name: v1 do devise_scope: User 'Session' = & gt; Post. 'Create session #,': like = & gt; 'Login' and end and end   

I keep the questions open for a while while I run on another issue while doing the test.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -