]> git.openstreetmap.org Git - rails.git/blobdiff - test/models/way_tag_test.rb
Localisation updates from https://translatewiki.net.
[rails.git] / test / models / way_tag_test.rb
index 46be06c9417c03b887de63b4fd12c74459223a4d..5860786c6147d5c4a7e66b32310c40ef5775269e 100644 (file)
@@ -1,69 +1,50 @@
 require "test_helper"
 
 class WayTagTest < ActiveSupport::TestCase
-  api_fixtures
-
-  def test_way_tag_count
-    assert_equal 6, WayTag.count
-  end
-
   def test_length_key_valid
-    key = "k"
-    (0..255).each do |i|
-      tag = WayTag.new
-      tag.way_id = current_way_tags(:t1).way_id
-      tag.k = key * i
-      tag.v = current_way_tags(:t1).v
+    tag = create(:way_tag)
+    [0, 255].each do |i|
+      tag.k = "k" * i
       assert tag.valid?
     end
   end
 
   def test_length_value_valid
-    val = "v"
-    (0..255).each do |i|
-      tag = WayTag.new
-      tag.way_id = current_way_tags(:t1).way_id
-      tag.k = "k"
-      tag.v = val * i
+    tag = create(:way_tag)
+    [0, 255].each do |i|
+      tag.v = "v" * i
       assert tag.valid?
     end
   end
 
   def test_length_key_invalid
-    ["k" * 256].each do |i|
-      tag = WayTag.new
-      tag.way_id = current_way_tags(:t1).way_id
-      tag.k = i
-      tag.v = "v"
-      assert !tag.valid?, "Key #{i} should be too long"
-      assert tag.errors[:k].any?
-    end
+    tag = create(:way_tag)
+    tag.k = "k" * 256
+    assert_not tag.valid?, "Key should be too long"
+    assert tag.errors[:k].any?
   end
 
   def test_length_value_invalid
-    ["v" * 256].each do |i|
-      tag = WayTag.new
-      tag.way_id = current_way_tags(:t1).way_id
-      tag.k = "k"
-      tag.v = i
-      assert !tag.valid?, "Value #{i} should be too long"
-      assert tag.errors[:v].any?
-    end
+    tag = create(:way_tag)
+    tag.v = "v" * 256
+    assert_not tag.valid?, "Value should be too long"
+    assert tag.errors[:v].any?
   end
 
   def test_empty_tag_invalid
     tag = WayTag.new
-    assert !tag.valid?, "Empty way tag should be invalid"
+    assert_not tag.valid?, "Empty way tag should be invalid"
     assert tag.errors[:way].any?
   end
 
   def test_uniqueness
+    existing = create(:way_tag)
     tag = WayTag.new
-    tag.way_id = current_way_tags(:t1).way_id
-    tag.k = current_way_tags(:t1).k
-    tag.v = current_way_tags(:t1).v
+    tag.way_id = existing.way_id
+    tag.k = existing.k
+    tag.v = existing.v
     assert tag.new_record?
-    assert !tag.valid?
+    assert_not tag.valid?
     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
     assert tag.new_record?
   end