source: subversion/sites/rails_port/test/unit/user_preference_test.rb @ 15534

Last change on this file since 15534 was 14586, checked in by tomhughes, 10 years ago

Merge api06 branch to trunk.

File size: 1.5 KB
Line 
1require File.dirname(__FILE__) + '/../test_helper'
2
3class UserPreferenceTest < ActiveSupport::TestCase
4  api_fixtures
5  fixtures :user_preferences
6
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
10  # the fixture file
11  def test_check_count
12    assert_equal 2, UserPreference.count
13  end
14
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)
20    newUP.k = up.k
21    newUP.v = "some other value"
22    assert_not_equal newUP.v, up.v
23    assert_raise (ActiveRecord::StatementInvalid) {newUP.save}
24  end
25 
26  def test_check_valid_length
27    key = "k"
28    val = "v"
29    (1..255).each do |i|
30      up = UserPreference.new
31      up.user = users(:normal_user)
32      up.k = key*i
33      up.v = val*i
34      assert up.valid?
35      assert up.save!
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"
39    end
40  end
41 
42  def test_check_invalid_length
43    key = "k"
44    val = "v"
45    [0,256].each do |i|
46      up = UserPreference.new
47      up.user = users(:normal_user)
48      up.k = key*i
49      up.v = val*i
50      assert_equal false, up.valid?
51      assert_raise(ActiveRecord::RecordInvalid) {up.save!}
52    end
53  end
54
55end
Note: See TracBrowser for help on using the repository browser.