]> git.openstreetmap.org Git - rails.git/blobdiff - test/models/changeset_tag_test.rb
Use jquery interface for enabling/disabling tooltips
[rails.git] / test / models / changeset_tag_test.rb
index e62808b6eb38ef7ea1ea0283bb886182e54721b9..5832b8a706523674aeb96cc6ca21d8e770a9dcc8 100644 (file)
@@ -1,70 +1,49 @@
 require "test_helper"
 
 class ChangesetTagTest < ActiveSupport::TestCase
-  api_fixtures
-
-  def test_changeset_tag_count
-    assert_equal 2, ChangesetTag.count
-  end
-
   def test_length_key_valid
-    key = "k"
-    (0..255).each do |i|
-      tag = ChangesetTag.new
-      tag.changeset_id = 1
-      tag.k = key * i
-      tag.v = "v"
-      assert tag.valid?
+    tag = create(:changeset_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 = ChangesetTag.new
-      tag.changeset_id = 1
-      tag.k = "k"
-      tag.v = val * i
-      assert tag.valid?
+    tag = create(:changeset_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 |k|
-      tag = ChangesetTag.new
-      tag.changeset_id = 1
-      tag.k = k
-      tag.v = "v"
-      assert !tag.valid?, "Key #{k} should be too long"
-      assert tag.errors[:k].any?
-    end
+    tag = create(:changeset_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 |v|
-      tag = ChangesetTag.new
-      tag.changeset_id = 1
-      tag.k = "k"
-      tag.v = v
-      assert !tag.valid?, "Value #{v} should be too long"
-      assert tag.errors[:v].any?
-    end
+    tag = create(:changeset_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 = ChangesetTag.new
-    assert !tag.valid?, "Empty tag should be invalid"
-    assert tag.errors[:changeset].any?
+  def test_orphaned_tag_invalid
+    tag = create(:changeset_tag)
+    tag.changeset = nil
+    assert_not tag.valid?, "Orphaned tag should be invalid"
+    assert_predicate tag.errors[:changeset], :any?
   end
 
   def test_uniqueness
-    tag = ChangesetTag.new
-    tag.changeset_id = changeset_tags(:changeset_1_tag_1).changeset_id
-    tag.k = changeset_tags(:changeset_1_tag_1).k
-    tag.v = changeset_tags(:changeset_1_tag_1).v
-    assert tag.new_record?
-    assert !tag.valid?
+    existing = create(:changeset_tag)
+    tag = build(:changeset_tag, :changeset => existing.changeset, :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
 end