]> git.openstreetmap.org Git - rails.git/blobdiff - test/models/relation_tag_test.rb
Convert class method tests to use User factory.
[rails.git] / test / models / relation_tag_test.rb
index add453ab0813378903b368c08ccb359c7cdee7e1..f221f78cc9fac44c112b82f03f904e8503104e17 100644 (file)
@@ -3,52 +3,34 @@ require "test_helper"
 class RelationTagTest < ActiveSupport::TestCase
   api_fixtures
 
-  def test_relation_tag_count
-    assert_equal 9, RelationTag.count
-  end
-
   def test_length_key_valid
-    key = "k"
+    tag = create(:relation_tag)
     (0..255).each do |i|
-      tag = RelationTag.new
-      tag.relation_id = 1
-      tag.k = key * i
-      tag.v = "v"
+      tag.k = "k" * i
       assert tag.valid?
     end
   end
 
   def test_length_value_valid
-    val = "v"
+    tag = create(:relation_tag)
     (0..255).each do |i|
-      tag = RelationTag.new
-      tag.relation_id = 1
-      tag.k = "k"
-      tag.v = val * i
+      tag.v = "v" * i
       assert tag.valid?
     end
   end
 
   def test_length_key_invalid
-    ["k" * 256].each do |i|
-      tag = RelationTag.new
-      tag.relation_id = 1
-      tag.k = i
-      tag.v = "v"
-      assert !tag.valid?, "Key #{i} should be too long"
-      assert tag.errors[:k].any?
-    end
+    tag = create(:relation_tag)
+    tag.k = "k" * 256
+    assert !tag.valid?, "Key should be too long"
+    assert tag.errors[:k].any?
   end
 
   def test_length_value_invalid
-    ["v" * 256].each do |i|
-      tag = RelationTag.new
-      tag.relation_id = 1
-      tag.k = "k"
-      tag.v = i
-      assert !tag.valid?, "Value #{i} should be too long"
-      assert tag.errors[:v].any?
-    end
+    tag = create(:relation_tag)
+    tag.v = "v" * 256
+    assert !tag.valid?, "Value should be too long"
+    assert tag.errors[:v].any?
   end
 
   def test_empty_tag_invalid
@@ -58,10 +40,11 @@ class RelationTagTest < ActiveSupport::TestCase
   end
 
   def test_uniquness
+    existing = create(:relation_tag)
     tag = RelationTag.new
-    tag.relation_id = current_relation_tags(:t1).relation_id
-    tag.k = current_relation_tags(:t1).k
-    tag.v = current_relation_tags(:t1).v
+    tag.relation_id = existing.relation_id
+    tag.k = existing.k
+    tag.v = existing.v
     assert tag.new_record?
     assert !tag.valid?
     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }