Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm going through the Rails Tutorial Book and by Chapter 8, when running bin/rails test I got this message:

 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.

The code generating this message is on 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: "[email protected]",
                                        password:              "password",
                                        password_confirmation: "password" }
        end
        assert_template 'users/show'
      end

How do I fix it?

like image 654
Jonathan Soifer Avatar asked Mar 23 '16 10:03

Jonathan Soifer


1 Answers

Fixed Code

test "valid signup information" do
  get signup_path
  assert_difference 'User.count', 1 do
    post users_path, params: { user: { name:  "Example User",
                                        email: "[email protected]",
                                        password:              "password",
                                        password_confirmation: "password" } } 
    follow_redirect!
  end
  assert_template 'users/show'
end

NOTE: I also added the params hash as suggested by Rails 5.

like image 105
Jonathan Soifer Avatar answered Sep 19 '22 19:09

Jonathan Soifer