不推荐使用`post_via_redirect`,它将在Rails 5.1中删除

Jon*_*fer 5 testing ruby-on-rails rspec-rails railstutorial.org ruby-on-rails-5

我正在阅读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.
Run Code Online (Sandbox Code Playgroud)

生成此消息的代码是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
Run Code Online (Sandbox Code Playgroud)

我如何解决它?

Jon*_*fer 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
Run Code Online (Sandbox Code Playgroud)

注意:我还params按照Rails 5的建议添加了哈希.