3 class UserPreferenceTest < ActiveSupport::TestCase
4 # Checks that you cannot add a new preference, that is a duplicate
5 def test_add_duplicate_preference
6 up = create(:user_preference)
7 new_up = build(:user_preference)
10 new_up.v = "some other value"
11 assert_not_equal new_up.v, up.v
12 assert_raise(ActiveRecord::RecordNotUnique) { new_up.save }
15 def test_check_valid_length
19 up = build(:user_preference)
20 up.user = create(:user)
23 assert_predicate up, :valid?
25 resp = UserPreference.find(up.id)
26 assert_equal key * i, resp.k, "User preference with #{i} #{key} chars (i.e. #{key.length * i} bytes) fails"
27 assert_equal val * i, resp.v, "User preference with #{i} #{val} chars (i.e. #{val.length * i} bytes) fails"
31 def test_check_invalid_length
35 up = build(:user_preference)
36 up.user = create(:user)
40 assert_raise(ActiveRecord::RecordInvalid) { up.save! }