请帮忙检查重定向。我有一个控制器:
但是在控制台运行之后,我收到了以下错误信息:
def create
@poll = current_user.polls.build(poll_params)
if @poll.save
flash[:success] = 'Голосование создано'
redirect_to user_polls_path(current_user)
else
flash.now[:error] = 'Голосование не создано'
@user = User.find(params[:user_id])
render 'new'
end
end
spec/requests/polls_spec.rb:
require 'rails_helper'
RSpec.describe "Polls", type: :request do
describe "return check" do
it "#create" do
@user = FactoryGirl.create(:user)
@poll = FactoryGirl.create(:poll, user: @user)
# binding.pry #@user OK, @poll OK
expect(@poll).to redirect_to(user_polls_path @user)
end
end
end
但是在控制台运行之后,我收到了以下错误信息:
$ rspec spec/requests
...F
Failures:
1) Polls return 200 status code for GET /polls #create
Failure/Error: expect(@poll.save).to redirect_to(user_polls_path @user)
NoMethodError:
undefined method `response_code' for nil:NilClass