summaryrefslogtreecommitdiff
blob: 582ccee7506999a0aecb42ba2d81951fde2dacf8 (plain)
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
44
45
46
47
# GLSAMaker v2
# Copyright (C) 2009-2011 Alex Legler <a3li@gentoo.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# For more information, see the LICENSE file.

require 'test_helper'

class UserTest < ActiveSupport::TestCase
  fixtures :users
  
  test "invalid user name" do
    user = User.new
    assert !user.valid?
    assert user.errors.invalid?(:login)
  end
  
  test "unique user name" do
    user = User.new(:login => users(:test_user).login,
                    :name  => "Mr. T",
                    :email => "foo@gentoo.org")

    assert !user.save
    assert_equal "User name must be unique", user.errors.on(:login)
  end
  
  test "invalid email" do
    user = User.new(:login => 'notyetthere',
                    :name => 'doesntmatteranyway',
                    :email => 'THIScouldNEVERbeAvalidEMAIL@ADDRESS')

    assert !user.valid?
    assert user.errors.invalid?(:email)
  end
  
  test "successful creation" do
    user = User.new(:login => 'not_yet_taken_login',
                    :name => 'doesntmatteranyway',
                    :email => 'foo@bar.org',
                    :access => 0)

    assert user.save
  end
end