redirect_to 在使用 Rspec 测试我的操作时不起作用
redirect_to is not working when testing my action using Rspec
我正在测试一个动作,但无法通过。
我的规格:
it 'redirects to the datatables page for authenticated users' do
user = User.create(name: 'fer', email: 'fer@fer.fer', password: 'fer')
session[:user_id] = user.id
get :new
expect(response).to redirect_to datatables_lists_path
end
我的代码:
def create
user = User.where(email: params[:email]).first
if user && user.authenticate(params[:password] )
session[:user_id] = user.id
redirect_to datatables_lists_path, notice: 'you are in!! :)'
else
flash[:error] = 'it's not working'
redirect_to sign_in_path
end
end
我收到的消息是:
1) SessionsController redirects to the datatables page for authenticated users
Failure/Error: expect(response).to redirect_to datatables_lists_path
Expected response to be a <redirect>, but was <200>
您正在发出 get :new
,但您向我们展示了来自控制器的 create
操作。您的测试未测试创建操作。
我正在测试一个动作,但无法通过。
我的规格:
it 'redirects to the datatables page for authenticated users' do
user = User.create(name: 'fer', email: 'fer@fer.fer', password: 'fer')
session[:user_id] = user.id
get :new
expect(response).to redirect_to datatables_lists_path
end
我的代码:
def create
user = User.where(email: params[:email]).first
if user && user.authenticate(params[:password] )
session[:user_id] = user.id
redirect_to datatables_lists_path, notice: 'you are in!! :)'
else
flash[:error] = 'it's not working'
redirect_to sign_in_path
end
end
我收到的消息是:
1) SessionsController redirects to the datatables page for authenticated users
Failure/Error: expect(response).to redirect_to datatables_lists_path
Expected response to be a <redirect>, but was <200>
您正在发出 get :new
,但您向我们展示了来自控制器的 create
操作。您的测试未测试创建操作。