X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/96dfe22fb006ec421f6b0bf42ca71f365b1a1e95..b7b2b502cf2b119208e3c1f79e4a4e38cc0edcc5:/test/unit/old_relation_tag_test.rb diff --git a/test/unit/old_relation_tag_test.rb b/test/unit/old_relation_tag_test.rb new file mode 100644 index 000000000..309e2fe80 --- /dev/null +++ b/test/unit/old_relation_tag_test.rb @@ -0,0 +1,76 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class RelationTagTest < Test::Unit::TestCase + fixtures :relation_tags + set_fixture_class :relation_tags => OldRelationTag + + def test_tag_count + assert_equal 3, OldRlationTag.count + end + + def test_length_key_valid + key = "k" + (0..255).each do |i| + tag = OldRelationTag.new + tag.id = relation_tags(:t1).id + tag.version = 1 + tag.k = key*i + tag.v = "v" + assert_valid tag + end + end + + def test_length_value_valid + val = "v" + (0..255).each do |i| + tag = OldRelationTag.new + tag.id = relation_tags(:t1).id + tag.version = 1 + tag.k = "k" + tag.v = val*i + assert_valid tag + end + end + + def test_length_key_invalid + ["k"*256].each do |i| + tag = OldRelationTag.new + tag.id = relation_tags(:t1).id + tag.version = 1 + tag.k = i + tag.v = "v" + assert !tag.valid?, "Key should be too long" + assert tag.errors.invalid?(:k) + end + end + + def test_length_value_invalid + ["k"*256].each do |i| + tag = OldRelationTag.new + tag.id = relation_tags(:t1).id + tag.version = 1 + tag.k = "k" + tag.v = i + assert !tag.valid?, "Value should be too long" + assert tag.errors.invalid?(:v) + end + end + + def test_empty_node_tag_invalid + tag = OldRelationTag.new + assert !tag.valid?, "Empty tag should be invalid" + assert tag.errors.invalid?(:id) + end + + def test_uniqueness + tag = OldRelationTag.new + tag.id = relation_tags(:t1).id + tag.version = relation_tags(:t1).version + tag.k = relation_tags(:t1).k + tag.v = relation_tags(:t1).v + assert tag.new_record? + assert !tag.valid? + assert_raise(ActiveRecord::RecordInvalid) {tag.save!} + assert tag.new_record? + end +end