You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I plugged in the user model validation you used, I still had the same issue. I ended up using the factory_girl gem and setting up a User factory instead of the @attr hash. The spec passed once I changed it to:
it "should reject invalid email addresses" do
addresses = %w[user@foo,com user_at_foo.org example.user@foo.]
addresses.each do |address|
#original line
#invalid_email_user = User.new(@attr.merge(:email => address))
# changed to
invalid_email_user = Factory.build(:user, :email => address)
invalid_email_user.should_not be_valid
end
end
I've yet to figure out why it wouldn't work the first way, the code should be doing the same thing functionally, but it wasn't catching the validation. There's a config setting for devise that lets you change the regex that validates the email address, but I've had no luck so far getting it to work with Rspec testing.
I noticed one failing test in user_spec.rb when running 'rspec spec' for the first time:
Failures:
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
The text was updated successfully, but these errors were encountered: