source: subversion/sites/rails_port/test/unit/old_relation_tag_test.rb @ 14668

Last change on this file since 14668 was 14648, checked in by zere, 10 years ago

More test fixes after fixture changes.

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