【问题标题】:`post_via_redirect` is deprecated and will be removed in Rails 5.1`post_via_redirect` 已弃用,将在 Rails 5.1 中删除
【发布时间】:2016-03-23 10:06:49
【问题描述】:

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

我该如何解决?

【问题讨论】:

    标签: ruby-on-rails testing rspec-rails railstutorial.org ruby-on-rails-5


    【解决方案1】:

    固定代码

    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 哈希。

    【讨论】:

      猜你喜欢
      • 2017-05-25
      • 2017-08-02
      • 2017-03-08
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      相关资源
      最近更新 更多