dimanche 22 février 2015

How can I explicitly choose a controller for a 'post' or 'get' function call?

I can see the definition of these functions here: http://ift.tt/1zYYr3s


But how can I choose the controller explicitly? For example, suppose I must log in first before proceeding with certain tests. I would like to call post in an RSpec test:



require 'rails_helper'

RSpec.describe API::V1::BooksController, :type => :controller do
def login!
post "/sessions", { email: "xyz@abc.com", password: "pw" }
...
end
describe "my test" do
login!
...
end
end


But I get



ActionController::UrlGenerationError:
No route matches {:action=>"/sessions", :controller=>"api/v1/books", :email=>"xyz@abc.com", :password=>"pw"}


I've tried variations like post 'sessions#create' or post :controller => "sessions", :action => "create" ... but none work and I don't like the idea of just guessing the right way to call it.


Advice appreciated, thanks.


Aucun commentaire:

Enregistrer un commentaire