]> git.openstreetmap.org Git - rails.git/blob - test/models/old_relation_tag_test.rb
21a6a1d66a90263d092e2f8959806838bc39d658
[rails.git] / test / models / old_relation_tag_test.rb
1 require 'test_helper'
2
3 class OldRelationTagTest < ActiveSupport::TestCase
4   api_fixtures
5
6   def test_tag_count
7     assert_equal 12, 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.relation_id = relation_tags(:t1).relation_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.relation_id = relation_tags(:t1).relation_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.relation_id = relation_tags(:t1).relation_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.relation_id = relation_tags(:t1).relation_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_tag_invalid
59     tag = OldRelationTag.new
60     assert !tag.valid?, "Empty tag should be invalid"
61     assert tag.errors[:old_relation].any?
62   end
63
64   def test_uniqueness
65     tag = OldRelationTag.new
66     tag.relation_id = relation_tags(:t1).relation_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