3 class UserPreferenceTest < ActiveSupport::TestCase
6 # Checks that you cannot add a new preference, that is a duplicate
7 def test_add_duplicate_preference
8 up = create(:user_preference)
9 new_up = UserPreference.new
12 new_up.v = "some other value"
13 assert_not_equal new_up.v, up.v
14 assert_raise(ActiveRecord::RecordNotUnique) { new_up.save }
17 def test_check_valid_length
21 up = UserPreference.new
22 up.user = users(:normal_user)
27 resp = UserPreference.find(up.id)
28 assert_equal key * i, resp.k, "User preference with #{i} #{key} chars (i.e. #{key.length * i} bytes) fails"
29 assert_equal val * i, resp.v, "User preference with #{i} #{val} chars (i.e. #{val.length * i} bytes) fails"
33 def test_check_invalid_length
37 up = UserPreference.new
38 up.user = users(:normal_user)
41 assert_equal false, up.valid?
42 assert_raise(ActiveRecord::RecordInvalid) { up.save! }