]> git.openstreetmap.org Git - rails.git/blob - test/unit/old_relation_tag_test.rb
f6ac38428874b229e5245b8c9a60ae9973753653
[rails.git] / test / unit / old_relation_tag_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class OldRelationTagTest < ActiveSupport::TestCase
4   api_fixtures
5   
6   def test_tag_count
7     assert_equal 7, OldRelationTag.count
8   end
9   
10   def test_length_key_valid
11     key = "k"
12     (0..255).each do |i|
13       tag = OldRelationTag.new
14       tag.id = relation_tags(:t1).id
15       tag.version = 1
16       tag.k = key*i
17       tag.v = "v"
18       assert tag.valid?
19     end
20   end
21   
22   def test_length_value_valid
23     val = "v"
24     (0..255).each do |i|
25       tag = OldRelationTag.new
26       tag.id = relation_tags(:t1).id
27       tag.version = 1
28       tag.k = "k"
29       tag.v = val*i
30       assert tag.valid?
31     end
32   end
33   
34   def test_length_key_invalid
35     ["k"*256].each do |i|
36       tag = OldRelationTag.new
37       tag.id = relation_tags(:t1).id
38       tag.version = 1
39       tag.k = i
40       tag.v = "v"
41       assert !tag.valid?, "Key should be too long"
42       assert tag.errors[:k].any?
43     end
44   end
45   
46   def test_length_value_invalid
47     ["k"*256].each do |i|
48       tag = OldRelationTag.new
49       tag.id = relation_tags(:t1).id
50       tag.version = 1
51       tag.k = "k"
52       tag.v = i
53       assert !tag.valid?, "Value should be too long"
54       assert tag.errors[:v].any?
55     end
56   end
57   
58   def test_empty_node_tag_invalid
59     tag = OldRelationTag.new
60     assert !tag.valid?, "Empty tag should be invalid"
61     assert tag.errors[:id].any?
62   end
63   
64   def test_uniqueness
65     tag = OldRelationTag.new
66     tag.id = relation_tags(:t1).id
67     tag.version = relation_tags(:t1).version
68     tag.k = relation_tags(:t1).k
69     tag.v = relation_tags(:t1).v
70     assert tag.new_record?
71     assert !tag.valid?
72     assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
73     assert tag.new_record?
74   end
75 end