source: subversion/sites/rails_port/test/unit/node_tag_test.rb @ 15838

Last change on this file since 15838 was 15588, checked in by tomhughes, 10 years ago

Move to version 2.3.2 of rails.

File size: 1.8 KB
Line 
1require File.dirname(__FILE__) + '/../test_helper'
2
3class NodeTagTest < ActiveSupport::TestCase
4  api_fixtures
5 
6  def test_tag_count
7    assert_equal 7, NodeTag.count
8    node_tag_count(:visible_node, 1)
9    node_tag_count(:invisible_node, 1)
10    node_tag_count(:used_node_1, 1)
11    node_tag_count(:used_node_2, 1)
12    node_tag_count(:node_with_versions, 2)
13  end
14 
15  def node_tag_count (node, count)
16    nod = current_nodes(node)
17    assert_equal count, nod.node_tags.count
18  end
19 
20  def test_length_key_valid
21    key = "k"
22    (0..255).each do |i|
23      tag = NodeTag.new
24      tag.id = current_node_tags(:t1).id
25      tag.k = key*i
26      tag.v = "v"
27      assert tag.valid?
28    end
29  end
30 
31  def test_length_value_valid
32    val = "v"
33    (0..255).each do |i|
34      tag = NodeTag.new
35      tag.id = current_node_tags(:t1).id
36      tag.k = "k"
37      tag.v = val*i
38      assert tag.valid?
39    end
40  end
41 
42  def test_length_key_invalid
43    ["k"*256].each do |i|
44      tag = NodeTag.new
45      tag.id = current_node_tags(:t1).id
46      tag.k = i
47      tag.v = "v"
48      assert !tag.valid?, "Key should be too long"
49      assert tag.errors.invalid?(:k)
50    end
51  end
52 
53  def test_length_value_invalid
54    ["k"*256].each do |i|
55      tag = NodeTag.new
56      tag.id = current_node_tags(:t1).id
57      tag.k = "k"
58      tag.v = i
59      assert !tag.valid?, "Value should be too long"
60      assert tag.errors.invalid?(:v)
61    end
62  end
63 
64  def test_empty_node_tag_invalid
65    tag = NodeTag.new
66    assert !tag.valid?, "Empty tag should be invalid"
67    assert tag.errors.invalid?(:id)
68  end
69 
70  def test_uniqueness
71    tag = NodeTag.new
72    tag.id = current_node_tags(:t1).id
73    tag.k = current_node_tags(:t1).k
74    tag.v = current_node_tags(:t1).v
75    assert tag.new_record?
76    assert !tag.valid?
77    assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
78    assert tag.new_record?
79  end
80end
Note: See TracBrowser for help on using the repository browser.