From 408c883d24af1d32b60a18bc0a5b1e5fdae30d53 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 16 Jun 2021 09:53:57 +0100 Subject: [PATCH] Skip intermediate lengths when testing tag validity It's really the upper and lower boundaries that we want to check, and it's reasonable to assume all the intermediate values will work fine if the boundary values are tested. This also saves about 75% of the time taken and almost 85% of the assertions when running all the model tests. --- test/models/changeset_tag_test.rb | 4 ++-- test/models/message_test.rb | 2 +- test/models/node_tag_test.rb | 4 ++-- test/models/old_node_tag_test.rb | 4 ++-- test/models/old_relation_tag_test.rb | 4 ++-- test/models/old_way_tag_test.rb | 4 ++-- test/models/relation_tag_test.rb | 4 ++-- test/models/user_preference_test.rb | 2 +- test/models/way_tag_test.rb | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/models/changeset_tag_test.rb b/test/models/changeset_tag_test.rb index 1db2effd6..90674fbbe 100644 --- a/test/models/changeset_tag_test.rb +++ b/test/models/changeset_tag_test.rb @@ -5,7 +5,7 @@ class ChangesetTagTest < ActiveSupport::TestCase changeset = create(:changeset) key = "k" - (0..255).each do |i| + [0, 255].each do |i| tag = ChangesetTag.new tag.changeset_id = changeset.id tag.k = key * i @@ -18,7 +18,7 @@ class ChangesetTagTest < ActiveSupport::TestCase changeset = create(:changeset) val = "v" - (0..255).each do |i| + [0, 255].each do |i| tag = ChangesetTag.new tag.changeset_id = changeset.id tag.k = "k" diff --git a/test/models/message_test.rb b/test/models/message_test.rb index b1acd0805..99a471075 100644 --- a/test/models/message_test.rb +++ b/test/models/message_test.rb @@ -32,7 +32,7 @@ class MessageTest < ActiveSupport::TestCase end def test_utf8_roundtrip - (1..255).each do |i| + [1, 255].each do |i| assert_message_ok("c", i) assert_message_ok(EURO, i) end diff --git a/test/models/node_tag_test.rb b/test/models/node_tag_test.rb index 1a7125f08..47295770f 100644 --- a/test/models/node_tag_test.rb +++ b/test/models/node_tag_test.rb @@ -3,7 +3,7 @@ require "test_helper" class NodeTagTest < ActiveSupport::TestCase def test_length_key_valid tag = create(:node_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.k = "k" * i assert tag.valid? end @@ -11,7 +11,7 @@ class NodeTagTest < ActiveSupport::TestCase def test_length_value_valid tag = create(:node_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.v = "v" * i assert tag.valid? end diff --git a/test/models/old_node_tag_test.rb b/test/models/old_node_tag_test.rb index f432d04b8..62869c6ad 100644 --- a/test/models/old_node_tag_test.rb +++ b/test/models/old_node_tag_test.rb @@ -3,7 +3,7 @@ require "test_helper" class OldNodeTagTest < ActiveSupport::TestCase def test_length_key_valid tag = create(:old_node_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.k = "k" * i assert tag.valid? end @@ -11,7 +11,7 @@ class OldNodeTagTest < ActiveSupport::TestCase def test_length_value_valid tag = create(:old_node_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.v = "v" * i assert tag.valid? end diff --git a/test/models/old_relation_tag_test.rb b/test/models/old_relation_tag_test.rb index a05e67ee7..dbdbf54c5 100644 --- a/test/models/old_relation_tag_test.rb +++ b/test/models/old_relation_tag_test.rb @@ -3,7 +3,7 @@ require "test_helper" class OldRelationTagTest < ActiveSupport::TestCase def test_length_key_valid tag = create(:old_relation_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.k = "k" * i assert tag.valid? end @@ -11,7 +11,7 @@ class OldRelationTagTest < ActiveSupport::TestCase def test_length_value_valid tag = create(:old_relation_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.v = "v" * i assert tag.valid? end diff --git a/test/models/old_way_tag_test.rb b/test/models/old_way_tag_test.rb index 565633063..d794cc275 100644 --- a/test/models/old_way_tag_test.rb +++ b/test/models/old_way_tag_test.rb @@ -3,7 +3,7 @@ require "test_helper" class OldWayTagTest < ActiveSupport::TestCase def test_length_key_valid tag = create(:old_way_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.k = "k" * i assert tag.valid? end @@ -11,7 +11,7 @@ class OldWayTagTest < ActiveSupport::TestCase def test_length_value_valid tag = create(:old_way_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.v = "v" * i assert tag.valid? end diff --git a/test/models/relation_tag_test.rb b/test/models/relation_tag_test.rb index e81b8b49c..429e77a92 100644 --- a/test/models/relation_tag_test.rb +++ b/test/models/relation_tag_test.rb @@ -3,7 +3,7 @@ require "test_helper" class RelationTagTest < ActiveSupport::TestCase def test_length_key_valid tag = create(:relation_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.k = "k" * i assert tag.valid? end @@ -11,7 +11,7 @@ class RelationTagTest < ActiveSupport::TestCase def test_length_value_valid tag = create(:relation_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.v = "v" * i assert tag.valid? end diff --git a/test/models/user_preference_test.rb b/test/models/user_preference_test.rb index 952289d94..d6f1dcce5 100644 --- a/test/models/user_preference_test.rb +++ b/test/models/user_preference_test.rb @@ -15,7 +15,7 @@ class UserPreferenceTest < ActiveSupport::TestCase def test_check_valid_length key = "k" val = "v" - (1..255).each do |i| + [1, 255].each do |i| up = UserPreference.new up.user = create(:user) up.k = key * i diff --git a/test/models/way_tag_test.rb b/test/models/way_tag_test.rb index 990a43627..5860786c6 100644 --- a/test/models/way_tag_test.rb +++ b/test/models/way_tag_test.rb @@ -3,7 +3,7 @@ require "test_helper" class WayTagTest < ActiveSupport::TestCase def test_length_key_valid tag = create(:way_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.k = "k" * i assert tag.valid? end @@ -11,7 +11,7 @@ class WayTagTest < ActiveSupport::TestCase def test_length_value_valid tag = create(:way_tag) - (0..255).each do |i| + [0, 255].each do |i| tag.v = "v" * i assert tag.valid? end -- 2.39.5