Skip to content

Email validation in user model #7

Open
@walteryu

Description

@walteryu

I noticed one failing test in user_spec.rb when running 'rspec spec' for the first time:

Failures:

  1. User should reject invalid email addresses
    Failure/Error: invalid_email_user.should_not be_valid
    expected valid? to return false, got true

    ./spec/models/user_spec.rb:35:in `block (3 levels) in <top (required)>'

    ./spec/models/user_spec.rb:33:in`each'

    ./spec/models/user_spec.rb:33:in `block (2 levels) in <top (required)>'

Finished in 2.11 seconds
17 examples, 1 failure

I got the test to pass after adding email validation to the user model using an example from ASCIICasts found here: http://asciicasts.com/episodes/211-validations-in-rails-3:

validates :email,
:presence => true,
:uniqueness => true,
:format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i }

After which, the test passes:

.................

Finished in 1.87 seconds
17 examples, 0 failures

Not sure if anyone else ran into this issue but wanted to share.

Thanks,
Walter

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions