]> git.openstreetmap.org Git - rails.git/blob - test/unit/user_test.rb
Can now run tests that use composite_primary_keys in the fixtures. Adding a new test...
[rails.git] / test / unit / user_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class UserTest < Test::Unit::TestCase
4   fixtures :users
5   
6   def test_invalid_with_empty_attributes
7     user = User.new
8     assert !user.valid?
9     assert user.errors.invalid?(:email)
10     assert user.errors.invalid?(:pass_crypt)
11     assert user.errors.invalid?(:display_name)
12     assert user.errors.invalid?(:email)
13     assert !user.errors.invalid?(:home_lat)
14     assert !user.errors.invalid?(:home_lon)
15     assert !user.errors.invalid?(:home_zoom)
16   end
17   
18   def test_unique_email
19     new_user = User.new(:email => users(:normal_user).email,
20       :active => 1, 
21       :pass_crypt => Digest::MD5.hexdigest('test'),
22       :display_name => "new user",
23       :data_public => 1,
24       :description => "desc")
25     assert !new_user.save
26     assert_equal ActiveRecord::Errors.default_error_messages[:taken], new_user.errors.on(:email)
27   end
28   
29   def test_unique_display_name
30     new_user = User.new(:email => "tester@openstreetmap.org",
31       :active => 0,
32       :pass_crypt => Digest::MD5.hexdigest('test'),
33       :display_name => users(:normal_user).display_name, 
34       :data_public => 1,
35       :description => "desc")
36     assert !new_user.save
37     assert_equal ActiveRecord::Errors.default_error_messages[:taken], new_user.errors.on(:display_name)
38   end
39 end