3 class ChangesetTagTest < ActiveSupport::TestCase
4 def test_length_key_valid
5 changeset = create(:changeset)
10 tag.changeset_id = changeset.id
13 assert_predicate tag, :valid?
17 def test_length_value_valid
18 changeset = create(:changeset)
22 tag = ChangesetTag.new
23 tag.changeset_id = changeset.id
26 assert_predicate tag, :valid?
30 def test_length_key_invalid
31 ["k" * 256].each do |k|
32 tag = ChangesetTag.new
36 assert_not tag.valid?, "Key #{k} should be too long"
37 assert_predicate tag.errors[:k], :any?
41 def test_length_value_invalid
42 ["v" * 256].each do |v|
43 tag = ChangesetTag.new
47 assert_not tag.valid?, "Value #{v} should be too long"
48 assert_predicate tag.errors[:v], :any?
52 def test_empty_tag_invalid
53 tag = ChangesetTag.new
54 assert_not tag.valid?, "Empty tag should be invalid"
55 assert_predicate tag.errors[:changeset], :any?
59 existing = create(:changeset_tag)
60 tag = ChangesetTag.new
61 tag.changeset_id = existing.changeset_id
64 assert_predicate tag, :new_record?
66 assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
67 assert_predicate tag, :new_record?