What is follow_redirect! Following ?: Rails Tutorial Memorandum-Chapter 7

I am writing a test when creating a user registration

/sample_app/test/integration/users_signup_test.rb


require 'test_helper'

class UsersSignupTest < ActionDispatch::IntegrationTest
.
.
.

  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" } }
    end
    follow_redirect!
    assert_template 'users/show'
  end

What is follow_redirect!!

This method looks at the result of sending a POST request and moves to the specified redirect destination. (Rails tutorial)

I can imagine the behavior somehow

What i don't understand

What is the specified redirect destination?

Verification

If you run the test as it is rails test > Green

If you refer to the behavior of the controller corresponding to post users_path

/sample_app/app/controllers/users_controller.rb


.
.
.
  def create
    @user = User.new(user_params)
    if @user.save
      flash[:success] = "Welcome to the Sample App!"
      redirect_to @user
    else
      render 'new'
    end
  end

If you change it to redirect_to @user> redirect_to root_path

rails test > Red

 FAIL["test_valid_signup_information", #<Minitest::Reporters::Suite:0x000055e3f2c61b10 @name="UsersSignupTest">, 1.4677946789997804]
 test_valid_signup_information#UsersSignupTest (1.47s)
        expecting <"users/show"> but rendering with <["static_pages/home", 
...

The redirect destination is "static_pages / home"

Conclusion

follow_redirect! Is "Look at the result of sending a POST request", So it seems to follow the explicit redirect behavior in the corresponding controller

Recommended Posts

What is follow_redirect! Following ?: Rails Tutorial Memorandum-Chapter 7
What is Rails gem devise?
What is Rails Active Record?
[Ruby on Rails] What is Bcrypt?
rails tutorial
rails tutorial
rails tutorial
rails tutorial
What to do if Cloud9 is full in the Rails tutorial
rails tutorial
rails tutorial
rails tutorial
[Rails] What is a dot (.) Or a colon (:)?
What is Cubby
What is Docker?
What is null? ]
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapter 6
What is Keycloak
What is maven?
What is Jackson?
Cloud9 is out of memory: Rails tutorial memorandum
What is Docker
What is self
rails tutorial Chapter 1
What is Jenkins
What is ArgumentMatcher?
Rails tutorial memorandum 1
What is IM-Juggling?
Rails tutorial memorandum 2
What is params
What is SLF4J?
rails tutorial Chapter 7
What is Facade? ??
What is Java <>?
rails tutorial Chapter 5
What is Gradle?
What is POJO
rails tutorial Chapter 10
What is Java
After all, what is [rails db: migrate] doing?
What is centOS
rails tutorial Chapter 9
What is RubyGem?
What is programming?
What is before_action?
What is Docker
rails tutorial Chapter 8
What is Byte?
Start Rails Tutorial
[Beginner] Rails Tutorial
What is Tomcat
Understanding ruby's "|| =" specification and what is Rails presence method?
[Rails] What is the difference between redirect and render?
[Rails Struggle/Rails Tutorial] What you learned in Rails Tutorial Chapters 4 and 5
What is Maven Assembly?
What is `docker-compose up`?
What is a constructor?
What is vue cli
Rails Tutorial Chapter 5 Notes
Rails Tutorial Chapter 10 Notes
What is an interface?