How to sign a user using RSpec

I am trying to write RSpec in front of a filter for user login. I have a product controller. To view products, the user must be logged in. I added a login method to spec / support / utilities, for example:

def login(user)
  post login_path, email: user.email, password: "password"
end

Then I called the method in the front filter in the spec / controller / products test:

before :each do
  user = FactoryGirl.create(:user)
  login(user)
end

When I run the test, I get the following error:

The action '/login' could not be found for ProductsController

I have a route for /login, and my user authentication is simple - just like Railscasts # 250 Authentication from Scratch . What am I missing?

+3
source share
2 answers

, , , . , ,

+3

Login ProductController, . , , . , , . :

def login(user)
  session[:user_id] = user.id
end
+1

All Articles