-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.rb
43 lines (37 loc) · 1.26 KB
/
user_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require File.dirname(__FILE__) + '/../test_helper'
class UserTest < ActiveSupport::TestCase
fixtures :users
test "create valid user" do
user = User.new(:name => 'siggi',
:email => 'siggi@example.com',
:password => 'abc123',
:password_confirmation => 'abc123')
assert user.save
end
test "invalid with empty attributes" do
user = User.new
assert !user.valid?
assert user.errors.invalid?(:name)
assert user.errors.invalid?(:email)
assert user.errors.invalid?(:password)
assert user.errors.invalid?(:password_confirmation)
end
test "valid email" do
valid = %w{ dabbi@dabbi.is }
invalid = %w{ dabbi dabbi@dabbi @dabbi.is dabbi@ @.is}
valid.each do |email|
user = User.new(:name => 'siggi',
:password => 'abc123',
:password_confirmation => 'abc123',
:email => email)
assert user.valid?, user.errors.full_messages
end
invalid.each do |email|
user = User.new(:name => 'siggi',
:password => 'abc123',
:password_confirmation => 'abc123',
:email => email)
assert !user.valid?, "saving #{email}"
end
end
end