]> git.openstreetmap.org Git - rails.git/blobdiff - test/unit/relation_tag_test.rb
Give a nice error message when parsing the nwr tags and they are missing the k and...
[rails.git] / test / unit / relation_tag_test.rb
index f93e689ca59b9fb103b2121dd8d8b59e40e28203..81bcd60acf549f452d5cad3265add0e1df48b0fc 100644 (file)
@@ -1,11 +1,10 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
-class RelationTagTest < Test::Unit::TestCase
-  fixtures :current_relation_tags
-  set_fixture_class :current_relation_tags => RelationTag
+class RelationTagTest < ActiveSupport::TestCase
+  api_fixtures
   
   def test_relation_tag_count
-    assert_equal 3, RelationTag.count
+    assert_equal 7, RelationTag.count
   end
   
   def test_length_key_valid
@@ -15,7 +14,7 @@ class RelationTagTest < Test::Unit::TestCase
       tag.id = 1
       tag.k = key*i
       tag.v = "v"
-      assert_valid tag
+      assert tag.valid?
     end
   end
   
@@ -26,7 +25,7 @@ class RelationTagTest < Test::Unit::TestCase
       tag.id = 1
       tag.k = "k"
       tag.v = val*i
-      assert_valid tag
+      assert tag.valid?
     end
   end
   
@@ -68,4 +67,28 @@ class RelationTagTest < Test::Unit::TestCase
     assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
     assert tag.new_record?
   end
+
+  ##
+  # test that tags can be updated and saved uniquely, i.e: tag.save!
+  # only affects the single tag that the activerecord object 
+  # represents. this amounts to testing that the primary key is
+  # unique.
+  #
+  # Commenting this out - I attempted to fix it, but composite primary keys
+  # wasn't playing nice with the column already called :id. Seemed to be 
+  # impossible to have validations on the :id column. If someone knows better
+  # please fix, otherwise this test is shelved.
+  #
+  # def test_update
+  #   v = "probably unique string here 3142592654"
+  #   assert_equal 0, RelationTag.count(:conditions => ['v=?', v])
+
+  #   # make sure we select a tag on a relation which has more than one tag
+  #   id = current_relations(:multi_tag_relation).id
+  #   tag = RelationTag.find(:first, :conditions => ["id = ?", id])
+  #   tag.v = v
+  #   tag.save!
+
+  #   assert_equal 1, RelationTag.count(:conditions => ['v=?', v])
+  # end
 end