From 034db6820f622f2039c0423880ed1083cf57e3e5 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 23 Feb 2022 11:44:56 +0000 Subject: [PATCH 1/1] Simplify changeset tag tests by using factories This saves lots of boilerplate in creating a valid test object --- test/models/changeset_tag_test.rb | 42 +++++++++---------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/test/models/changeset_tag_test.rb b/test/models/changeset_tag_test.rb index 6846f90b4..4ac372416 100644 --- a/test/models/changeset_tag_test.rb +++ b/test/models/changeset_tag_test.rb @@ -2,51 +2,33 @@ require "test_helper" 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 -- 2.39.5