我正在浏览Rails教程书,在第8章中,当运行bin / rails测试时,我收到了这条消息:
DEPRECATION WARNING: `post_via_redirect` is deprecated and will be removed in Rails 5.1. Please use follow_redirect! manually after the request call for the same behavior.
生成此消息的代码位于test/integration/user_signup_test.rb
:
test "valid signup information" do
get signup_path
assert_difference 'User.count', 1 do
post_via_redirect users_path, user: { name: "Example User",
email: "user@example.com",
password: "password",
password_confirmation: "password" }
end
assert_template 'users/show'
end
我该如何解决?
答案 0 :(得分:15)
固定代码
test "valid signup information" do
get signup_path
assert_difference 'User.count', 1 do
post users_path, params: { user: { name: "Example User",
email: "user@example.com",
password: "password",
password_confirmation: "password" } }
follow_redirect!
end
assert_template 'users/show'
end
注意:我还按照Rails 5的建议添加了params
哈希。