title: Railstutotal (Michael Hartl): Error with Listing 6.25
body: <p>So I followed the Rails Tutorial so far and it's all been working fine until I get to Listing 6.25. The tutorial says that "rails test" should be green here but I am getting red. </p>
  
  <p>Error 
  <p>
  Failure:
  UserTest#test_email_addresses_should_be_unique [location]
  expected to be nil or false</p>
  
  <p>I'm 99% sure that I followed the book exactly and can't figure out what's wrong. </p>
  
  <p>Here's user.rb</p>
  
  <pre><code>class User &lt; ApplicationRecord
      attr_accessor :name, :email
  
      validates :name, presence: true, length: { maximum: 50 }
      VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
      validates :email, presence: true, length: {maximum: 255}, 
          format: {with: VALID_EMAIL_REGEX}, 
          uniqueness: true
  end
  </code></pre>
  
  <p>and user_test.rb</p>
  
  <pre><code>require 'test_helper'
  
  class UserTest &lt; ActiveSupport::TestCase
    def setup
      @user = User.new(name: "Example User", email: "user@example.com")
    end
  
    test "should be valid" do
      assert @user.valid?
    end
  
    test "name should be present" do
      @user.name = "     "
      assert_not @user.valid?
    end
  
    test "email should be present" do
      @user.email = "     "
      assert_not @user.valid?
    end
  
    test "name should not be too long" do
      @user.name = "a" * 51
      assert_not @user.valid?
    end
  
    test "email should not be too long" do
      @user.email = "a" * 244 + "@example.com"
      assert_not @user.valid?
    end
  
    test "email validation should reject invalid addresses" do
      invalid_addresses = %w[user@example,com user_at_foo.org user.name@example.
                         foo@bar_baz.com foo@bar+baz.com]
      invalid_addresses.each do |invalid_address|
        @user.email = invalid_address
        assert_not @user.valid?, "#{invalid_address.inspect} should be invalid"
      end
    end
  
    test "email addresses should be unique" do
      duplicate_user = @user.dup
      @user.save
      assert_not duplicate_user.valid?
    end
  
  end
  </code></pre>