1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserPreferenceTest < ActiveSupport::TestCase
5 fixtures :user_preferences
7 # This checks to make sure that there are two user preferences
8 # stored in the test database.
9 # This test needs to be updated for every addition/deletion from
12 assert_equal 2, UserPreference.count
15 # Checks that you cannot add a new preference, that is a duplicate
16 def test_add_duplicate_preference
17 up = user_preferences(:a)
18 newUP = UserPreference.new
19 newUP.user = users(:normal_user)
21 newUP.v = "some other value"
22 assert_not_equal newUP.v, up.v
23 assert_raise (ActiveRecord::RecordNotUnique) {newUP.save}
26 def test_check_valid_length
30 up = UserPreference.new
31 up.user = users(:normal_user)
36 resp = UserPreference.find(up.id)
37 assert_equal key*i, resp.k, "User preference with #{i} #{key} chars (i.e. #{key.length*i} bytes) fails"
38 assert_equal val*i, resp.v, "User preference with #{i} #{val} chars (i.e. #{val.length*i} bytes) fails"
42 def test_check_invalid_length
46 up = UserPreference.new
47 up.user = users(:normal_user)
50 assert_equal false, up.valid?
51 assert_raise(ActiveRecord::RecordInvalid) {up.save!}