]> git.openstreetmap.org Git - rails.git/blobdiff - test/models/relation_tag_test.rb
Merge remote-tracking branch 'upstream/pull/3736'
[rails.git] / test / models / relation_tag_test.rb
index 9db80f0bf1f4f9f784c34d5e7904d354c4b4719f..69a491890101b0f8e5122198066f11300e2230e6 100644 (file)
@@ -1,71 +1,50 @@
-require 'test_helper'
+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"
-    (0..255).each do |i|
-      tag = RelationTag.new
-      tag.relation_id = 1
-      tag.k = key * i
-      tag.v = "v"
-      assert tag.valid?
+    tag = create(:relation_tag)
+    [0, 255].each do |i|
+      tag.k = "k" * i
+      assert_predicate tag, :valid?
     end
   end
 
   def test_length_value_valid
-    val = "v"
-    (0..255).each do |i|
-      tag = RelationTag.new
-      tag.relation_id = 1
-      tag.k = "k"
-      tag.v = val * i
-      assert tag.valid?
+    tag = create(:relation_tag)
+    [0, 255].each do |i|
+      tag.v = "v" * i
+      assert_predicate 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_not tag.valid?, "Key should be too long"
+    assert_predicate 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_not tag.valid?, "Value should be too long"
+    assert_predicate tag.errors[:v], :any?
   end
 
-  def test_empty_tag_invalid
-    tag = RelationTag.new
-    assert !tag.valid?, "Empty relation tag should be invalid"
-    assert tag.errors[:relation].any?
+  def test_orphaned_tag_invalid
+    tag = create(:relation_tag)
+    tag.relation = nil
+    assert_not tag.valid?, "Orphaned tag should be invalid"
+    assert_predicate tag.errors[:relation], :any?
   end
 
-  def test_uniquness
-    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
-    assert tag.new_record?
-    assert !tag.valid?
+  def test_uniqueness
+    existing = create(:relation_tag)
+    tag = build(:relation_tag, :relation => existing.relation, :k => existing.k, :v => existing.v)
+    assert_predicate tag, :new_record?
+    assert_not tag.valid?
     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
-    assert tag.new_record?
+    assert_predicate tag, :new_record?
   end
 
   ##