Replace fixtures with a factory for old_relation_tags
[rails.git] / test / models / old_relation_tag_test.rb
index 2c9638a2d809389e31ec15f6cfef7a105a4c2f55..58c70cc9c5fcba90aefe8b3316843a13c45452a0 100644 (file)
@@ -1,58 +1,34 @@
 require "test_helper"
 
 class OldRelationTagTest < ActiveSupport::TestCase
-  api_fixtures
-
-  def test_tag_count
-    assert_equal 13, OldRelationTag.count
-  end
-
   def test_length_key_valid
-    key = "k"
+    tag = create(:old_relation_tag)
     (0..255).each do |i|
-      tag = OldRelationTag.new
-      tag.relation_id = relation_tags(:t1).relation_id
-      tag.version = 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(:old_relation_tag)
     (0..255).each do |i|
-      tag = OldRelationTag.new
-      tag.relation_id = relation_tags(:t1).relation_id
-      tag.version = 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 = OldRelationTag.new
-      tag.relation_id = relation_tags(:t1).relation_id
-      tag.version = 1
-      tag.k = i
-      tag.v = "v"
-      assert !tag.valid?, "Key should be too long"
-      assert tag.errors[:k].any?
-    end
+    tag = create(:old_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
-    ["k" * 256].each do |i|
-      tag = OldRelationTag.new
-      tag.relation_id = relation_tags(:t1).relation_id
-      tag.version = 1
-      tag.k = "k"
-      tag.v = i
-      assert !tag.valid?, "Value should be too long"
-      assert tag.errors[:v].any?
-    end
+    tag = create(:old_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
@@ -62,11 +38,12 @@ class OldRelationTagTest < ActiveSupport::TestCase
   end
 
   def test_uniqueness
+    existing = create(:old_relation_tag)
     tag = OldRelationTag.new
-    tag.relation_id = relation_tags(:t1).relation_id
-    tag.version = relation_tags(:t1).version
-    tag.k = relation_tags(:t1).k
-    tag.v = relation_tags(:t1).v
+    tag.relation_id = existing.relation_id
+    tag.version = existing.version
+    tag.k = existing.k
+    tag.v = existing.v
     assert tag.new_record?
     assert !tag.valid?
     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }