class ChangesetTagTest < ActiveSupport::TestCase
def test_length_key_valid
- changeset = create(:changeset)
-
- key = "k"
+ tag = create(:changeset_tag)
[0, 255].each do |i|
- tag = ChangesetTag.new
- tag.changeset_id = changeset.id
- tag.k = key * i
- tag.v = "v"
+ tag.k = "k" * i
assert_predicate tag, :valid?
end
end
def test_length_value_valid
- changeset = create(:changeset)
-
- val = "v"
+ tag = create(:changeset_tag)
[0, 255].each do |i|
- tag = ChangesetTag.new
- tag.changeset_id = changeset.id
- tag.k = "k"
- tag.v = val * i
+ tag.v = "v" * i
assert_predicate tag, :valid?
end
end
def test_length_key_invalid
- ["k" * 256].each do |k|
- tag = ChangesetTag.new
- tag.changeset_id = 1
- tag.k = k
- tag.v = "v"
- assert_not tag.valid?, "Key #{k} should be too long"
- assert_predicate tag.errors[:k], :any?
- end
+ tag = create(:changeset_tag)
+ tag.k = "k" * 256
+ assert_not tag.valid?, "Key should be too long"
+ assert_predicate tag.errors[:k], :any?
end
def test_length_value_invalid
- ["v" * 256].each do |v|
- tag = ChangesetTag.new
- tag.changeset_id = 1
- tag.k = "k"
- tag.v = v
- assert_not tag.valid?, "Value #{v} should be too long"
- assert_predicate tag.errors[:v], :any?
- end
+ tag = create(:changeset_tag)
+ tag.v = "v" * 256
+ assert_not tag.valid?, "Value should be too long"
+ assert_predicate tag.errors[:v], :any?
end
def test_orphaned_tag_invalid