Create a node factory, and use it for most node model tests
[rails.git] / test / models / old_way_tag_test.rb
index 07bdfbca87f4355828ceca94a0b9224ab323da3f..9a258ffb91f76fbab187dba69a71d2649b3025a0 100644 (file)
@@ -1,75 +1,54 @@
-require 'test_helper'
+require "test_helper"
 
 class OldWayTagTest < ActiveSupport::TestCase
   api_fixtures
-  
-  def test_tag_count
-    assert_equal 12, OldWayTag.count
-  end
-  
+
   def test_length_key_valid
-    key = "k"
+    tag = create(:old_way_tag)
     (0..255).each do |i|
-      tag = OldWayTag.new
-      tag.way_id = way_tags(:t1).way_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_way_tag)
     (0..255).each do |i|
-      tag = OldWayTag.new
-      tag.way_id = way_tags(:t1).way_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 = OldWayTag.new
-      tag.way_id = way_tags(:t1).way_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_way_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 = OldWayTag.new
-      tag.way_id = way_tags(:t1).way_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_way_tag)
+    tag.v = "v" * 256
+    assert !tag.valid?, "Value should be too long"
+    assert tag.errors[:v].any?
   end
-  
+
   def test_empty_tag_invalid
     tag = OldWayTag.new
     assert !tag.valid?, "Empty tag should be invalid"
     assert tag.errors[:old_way].any?
   end
-  
+
   def test_uniqueness
+    existing = create(:old_way_tag)
     tag = OldWayTag.new
-    tag.way_id = way_tags(:t1).way_id
-    tag.version = way_tags(:t1).version
-    tag.k = way_tags(:t1).k
-    tag.v = way_tags(:t1).v
+    tag.way_id = existing.way_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!}
+    assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
     assert tag.new_record?
   end
 end