]> git.openstreetmap.org Git - rails.git/blob - test/unit/relation_tag_test.rb
Relation Tag testing. Also sort the belong_to/has_many for user/changeset/old_way.
[rails.git] / test / unit / relation_tag_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class RelationTagTest < Test::Unit::TestCase
4   fixtures :current_relation_tags
5   set_fixture_class :current_relation_tags => RelationTag
6   
7   def test_relation_tag_count
8     assert_equal 3, RelationTag.count
9   end
10   
11   def test_length_key_valid
12     key = "k"
13     (0..255).each do |i|
14       tag = RelationTag.new
15       tag.id = 1
16       tag.k = key*i
17       tag.v = "v"
18       assert_valid tag
19     end
20   end
21   
22   def test_length_value_valid
23     val = "v"
24     (0..255).each do |i|
25       tag = RelationTag.new
26       tag.id = 1
27       tag.k = "k"
28       tag.v = val*i
29       assert_valid tag
30     end
31   end
32   
33   def test_length_key_invalid
34     ["k"*256].each do |i|
35       tag = RelationTag.new
36       tag.id = 1
37       tag.k = i
38       tag.v = "v"
39       assert !tag.valid?, "Key #{i} should be too long"
40       assert tag.errors.invalid?(:k)
41     end
42   end
43   
44   def test_length_value_invalid
45     ["v"*256].each do |i|
46       tag = RelationTag.new
47       tag.id = 1
48       tag.k = "k"
49       tag.v = i
50       assert !tag.valid?, "Value #{i} should be too long"
51       assert tag.errors.invalid?(:v)
52     end
53   end
54   
55   def test_empty_tag_invalid
56     tag = RelationTag.new
57     assert !tag.valid?, "Empty relation tag should be invalid"
58     assert tag.errors.invalid?(:id)
59   end
60   
61   def test_uniquness
62     tag = RelationTag.new
63     tag.id = current_relation_tags(:t1).id
64     tag.k = current_relation_tags(:t1).k
65     tag.v = current_relation_tags(:t1).v
66     assert tag.new_record?
67     assert !tag.valid?
68     assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
69     assert tag.new_record?
70   end
71 end