|
@@ -4,7 +4,8 @@ class UserTest < ActiveSupport::TestCase
|
|
|
def setup
|
|
|
@user = User.new(login: "example", name: "Example User",
|
|
|
email: "user@example.com",
|
|
|
- password: "foobar", password_confirmation: "foobar")
|
|
|
+ password: "foobar", password_confirmation: "foobar",
|
|
|
+ birth_date: 30.years.ago)
|
|
|
end
|
|
|
|
|
|
test "should be valid" do
|
|
@@ -36,6 +37,11 @@ class UserTest < ActiveSupport::TestCase
|
|
|
assert_not @user.valid?
|
|
|
end
|
|
|
|
|
|
+ test "name should not be too long" do
|
|
|
+ @user.name = "a" * 256
|
|
|
+ assert_not @user.valid?
|
|
|
+ end
|
|
|
+
|
|
|
test "email validation should accept valid addresses" do
|
|
|
valid_addresses = %w[user@example.com USER@foo.COM A_US-ER@foo.bar.org
|
|
|
first.last@foo.jp alice+bob@baz.cn]
|
|
@@ -70,6 +76,24 @@ class UserTest < ActiveSupport::TestCase
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+ test "phone number validation should accept valid phone number" do
|
|
|
+ valid_numbers = [
|
|
|
+ "333-333-3333",
|
|
|
+ "(333) 333-3333",
|
|
|
+ "1-333-333-3333",
|
|
|
+ "333.333.3333",
|
|
|
+ "333-333-3333",
|
|
|
+ "333-333-3333 x3333",
|
|
|
+ "(333) 333-3333 x3333",
|
|
|
+ "1-333-333-3333 x3333",
|
|
|
+ "333.333.3333 x3333",
|
|
|
+ ]
|
|
|
+ valid_numbers.each do |valid_number|
|
|
|
+ @user.phone = valid_number
|
|
|
+ assert @user.valid?, "#{valid_number.inspect} should be valid"
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
test "login should be unique" do
|
|
|
duplicate_user = @user.dup
|
|
|
duplicate_user.email = "foo@bar.com"
|