More Node.from_xml unit tests
[rails.git] / test / unit / node_tag_test.rb
index 9d3da03b1ea40ffb9b6d97ce6e6fd05605732fdf..cfe0b57f22b26ae8a5d90402c2fd4d9deecbec5f 100644 (file)
@@ -1,12 +1,10 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
-class NodeTagTest < Test::Unit::TestCase
-  fixtures :current_node_tags, :current_nodes
-  set_fixture_class :current_nodes => Node
-  set_fixture_class :current_node_tags => NodeTag
+class NodeTagTest < ActiveSupport::TestCase
+  api_fixtures
   
   def test_tag_count
-    assert_equal 6, NodeTag.count
+    assert_equal 7, NodeTag.count
     node_tag_count(:visible_node, 1)
     node_tag_count(:invisible_node, 1)
     node_tag_count(:used_node_1, 1)
@@ -26,7 +24,7 @@ class NodeTagTest < Test::Unit::TestCase
       tag.id = current_node_tags(:t1).id
       tag.k = key*i
       tag.v = "v"
-      assert_valid tag
+      assert tag.valid?
     end
   end
   
@@ -37,7 +35,7 @@ class NodeTagTest < Test::Unit::TestCase
       tag.id = current_node_tags(:t1).id
       tag.k = "k"
       tag.v = val*i
-      assert_valid tag
+      assert tag.valid?
     end
   end
   
@@ -68,4 +66,15 @@ class NodeTagTest < Test::Unit::TestCase
     assert !tag.valid?, "Empty tag should be invalid"
     assert tag.errors.invalid?(:id)
   end
+  
+  def test_uniqueness
+    tag = NodeTag.new
+    tag.id = current_node_tags(:t1).id
+    tag.k = current_node_tags(:t1).k
+    tag.v = current_node_tags(:t1).v
+    assert tag.new_record?
+    assert !tag.valid?
+    assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
+    assert tag.new_record?
+  end
 end