I am trying to write a RSpec before filter to log a user in. I have a products controller. In order to view products, a user must be logged in. I added a login method to spec/support/utilities like so:
def login(user)
post login_path, email: user.email, password: "password"
end
Then I called the method in a before filter in my spec/controllers/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?
If this is a controller spec, then the problem is that Routes are not available when unit testing controllers. The point is to test in isolation, which means no routes