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