Load api fixtures in tag model tests
[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_length_key_valid
7     tag = create(:old_relation_tag)
8     (0..255).each do |i|
9       tag.k = "k" * i
10       assert tag.valid?
11     end
12   end
13
14   def test_length_value_valid
15     tag = create(:old_relation_tag)
16     (0..255).each do |i|
17       tag.v = "v" * i
18       assert tag.valid?
19     end
20   end
21
22   def test_length_key_invalid
23     tag = create(:old_relation_tag)
24     tag.k = "k" * 256
25     assert !tag.valid?, "Key should be too long"
26     assert tag.errors[:k].any?
27   end
28
29   def test_length_value_invalid
30     tag = create(:old_relation_tag)
31     tag.v = "v" * 256
32     assert !tag.valid?, "Value should be too long"
33     assert tag.errors[:v].any?
34   end
35
36   def test_empty_tag_invalid
37     tag = OldRelationTag.new
38     assert !tag.valid?, "Empty tag should be invalid"
39     assert tag.errors[:old_relation].any?
40   end
41
42   def test_uniqueness
43     existing = create(:old_relation_tag)
44     tag = OldRelationTag.new
45     tag.relation_id = existing.relation_id
46     tag.version = existing.version
47     tag.k = existing.k
48     tag.v = existing.v
49     assert tag.new_record?
50     assert !tag.valid?
51     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
52     assert tag.new_record?
53   end
54 end