本付きのフォームでテスト送信する方法についての第7章を読んでいる <The ruby on rails tutorial 6th 2021>, 以下に2つのテストケースがあり、混乱する部分はいつfollow_redirectを使用する必要があるかです! なぜ最初のケースではこの行が必要なく、2 番目のケースでは必要なのですか? 最初のケースでは URL は常に「users/new」ですが、2 番目のケースは後で「users/show」になるため (新しいユーザーのサインアップが成功した後)、私の仮定は URL 自体に関するものです。
助けてくれてありがとう。
require 'test_helper'
class UsersSignupTest < ActionDispatch::IntegrationTest
test 'invalid signup information' do
get signup_path
assert_no_difference 'User.count' do
post users_path, params: { user: { name: '',
email: 'user@invalid',
password: 'foo',
password_confirmation: 'bar' } }
end
assert_template 'users/new'
assert_select 'div#error_explanation'
assert_select 'div.alert.alert-danger'
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' } }
end
follow_redirect! #It's all about This line!
assert_template 'users/show'
end
end