Penny Penny - 1 year ago 40
Ruby Question

Why the password key has a value of "foo" from Michael Hartl's Ruby on Rails book Chapter 7?

I'm currently following Michael Hartl's ROR book to create a web application. The following is the code from Chapter 7.

Listing 7.21: test/integration/users_signup_test.rb

require 'test_helper'

class UsersSignupTest < ActionDispatch::IntegrationTest

test "invalid signup information" do
get signup_path
assert_no_difference 'User.count' do
post users_path, user: { name: "",
email: "user@invalid",
password: "foo",
password_confirmation: "bar" }
assert_template 'users/new'

It is to test the validity of a user signup form. I'm a bit confused about why the values for name, email, password and password_confirmation are filled this way? (meaning, for example, why the value of email is user@invalid; why the password's value is foo?)

Thank you very much and I'm looking forward to your answer!


You're testing invalid signup information to make sure a user is not created. You're performing a http post request to the users create action and you're sending the data in that users hash. Foo and bar are arbitrarily chosen values mainly significant because they don't match as the password and confirmation are required to.