我正在尝试在UsersController中测试创建操作,其中用户是使用配置文件创建的; 然后用户被重定向到用户的个人资料页面,但我收到错误Expected response to be a <redirect>, but was <200>.
在用户控制器中创建操作
def create
@user = User.new(user_params)
if @user.save
log_in @user
flash[:success] = "Welcome to the Mini Olympics"
redirect_to user_profile_path(current_user, @profile)
else
render 'new'
end
end
Run Code Online (Sandbox Code Playgroud)
使用有效信息进行注册测试
test "valid signup information" do
get signup_path
assert_difference 'User.count', 1 do
post users_path, user: @user.attributes
@user.build_profile(name: "Micheal Example", street: "24 Martins St.", city: "Waterloo", state: "AW", zipcode: "22456")
@user.save
#assert_redirected_to user_profile_path(@user)
assert_redirected_to @user.profile
end
assert_template 'profiles/show'
assert is_logged_in?
end
Run Code Online (Sandbox Code Playgroud)