1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserTest < Test::Unit::TestCase
6 def test_invalid_with_empty_attributes
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)
19 new_user = User.new(:email => users(:normal_user).email,
21 :pass_crypt => Digest::MD5.hexdigest('test'),
22 :display_name => "new user",
24 :description => "desc")
26 assert_equal ActiveRecord::Errors.default_error_messages[:taken], new_user.errors.on(:email)
29 def test_unique_display_name
30 new_user = User.new(:email => "tester@openstreetmap.org",
32 :pass_crypt => Digest::MD5.hexdigest('test'),
33 :display_name => users(:normal_user).display_name,
35 :description => "desc")
37 assert_equal ActiveRecord::Errors.default_error_messages[:taken], new_user.errors.on(:display_name)
41 ok = %w{ a@s.com test@shaunmcdonald.me.uk hello_local@ping-d.ng test_local@openstreetmap.org test-local@example.com }
42 bad = %w{ hi ht@ n@ @.com help@.me.uk help"hi.me.uk }
45 user = users(:normal_user)
47 assert user.valid?, user.errors.full_messages
51 user = users(:normal_user)
53 assert !user.valid?, "#{name} is valid when it shouldn't be"
57 def test_display_name_length
58 user = users(:normal_user)
59 user.display_name = "123"
60 assert user.valid?, " should allow nil display name"
61 user.display_name = "12"
62 assert !user.valid?, "should not allow 2 char name"
63 user.display_name = ""
65 user.display_name = nil
66 # Don't understand why it isn't allowing a nil value,
67 # when the validates statements specifically allow it
68 # It appears the database does not allow null values
72 def test_display_name_valid
73 # Due to sanitisation in the view some of these that you might not
75 # However, would they affect the xml planet dumps?
76 ok = [ "Name", "'me", "he\"", "#ping", "<hr>"]
77 # These need to be 3 chars in length, otherwise the length test above
79 bad = [ "<hr/>", "test@example.com", "s/f", "aa/", "aa;", "aa.", "aa,", "aa?", "/;.,?" ]
80 ok.each do |display_name|
81 user = users(:normal_user)
82 user.display_name = display_name
83 assert user.valid?, "#{display_name} is invalid, when it should be"
86 bad.each do |display_name|
87 user = users(:normal_user)
88 user.display_name = display_name
89 assert !user.valid?, "#{display_name} is valid when it shouldn't be"
90 assert_equal "is invalid", user.errors.on(:display_name)
95 assert_equal false, users(:normal_user).is_friends_with?(users(:second_user))
96 assert_equal false, users(:normal_user).is_friends_with?(users(:inactive_user))
97 assert_equal false, users(:second_user).is_friends_with?(users(:normal_user))
98 assert_equal false, users(:second_user).is_friends_with?(users(:inactive_user))
99 assert_equal false, users(:inactive_user).is_friends_with?(users(:normal_user))
100 assert_equal false, users(:inactive_user).is_friends_with?(users(:second_user))