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_orphaned_tag_invalid
53 tag = create(:changeset_tag)
55 assert_not tag.valid?, "Orphaned tag should be invalid"
56 assert_predicate tag.errors[:changeset], :any?
60 existing = create(:changeset_tag)
61 tag = ChangesetTag.new
62 tag.changeset_id = existing.changeset_id
65 assert_predicate tag, :new_record?
67 assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
68 assert_predicate tag, :new_record?