我正在阅读 Rails 教程书和第 8 章,当运行 bin/rails test 时,我收到了这条消息:
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
我该如何解决?
最佳答案
固定代码
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
散列。
关于ruby-on-rails - `post_via_redirect` 已弃用,将在 Rails 5.1 中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36175098/