]> git.openstreetmap.org Git - rails.git/blob - test/models/old_relation_tag_test.rb
a373e386df53bf839bed90ba965b6cd26221e133
[rails.git] / test / models / old_relation_tag_test.rb
1 require "test_helper"
2
3 class OldRelationTagTest < ActiveSupport::TestCase
4   def test_length_key_valid
5     tag = create(:old_relation_tag)
6     [0, 255].each do |i|
7       tag.k = "k" * i
8       assert_predicate tag, :valid?
9     end
10   end
11
12   def test_length_value_valid
13     tag = create(:old_relation_tag)
14     [0, 255].each do |i|
15       tag.v = "v" * i
16       assert_predicate tag, :valid?
17     end
18   end
19
20   def test_length_key_invalid
21     tag = create(:old_relation_tag)
22     tag.k = "k" * 256
23     assert_not tag.valid?, "Key should be too long"
24     assert_predicate tag.errors[:k], :any?
25   end
26
27   def test_length_value_invalid
28     tag = create(:old_relation_tag)
29     tag.v = "v" * 256
30     assert_not tag.valid?, "Value should be too long"
31     assert_predicate tag.errors[:v], :any?
32   end
33
34   def test_empty_tag_invalid
35     tag = OldRelationTag.new
36     assert_not tag.valid?, "Empty tag should be invalid"
37     assert_predicate tag.errors[:old_relation], :any?
38   end
39
40   def test_uniqueness
41     existing = create(:old_relation_tag)
42     tag = OldRelationTag.new
43     tag.relation_id = existing.relation_id
44     tag.version = existing.version
45     tag.k = existing.k
46     tag.v = existing.v
47     assert_predicate tag, :new_record?
48     assert_not tag.valid?
49     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
50     assert_predicate tag, :new_record?
51   end
52 end