`post_via_redirect` 已弃用,将在 Rails 5.1 中删除

`post_via_redirect` is deprecated and will be removed in Rails 5.1

我正在阅读 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

我该如何解决?

固定代码

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 散列