Give a nice error message when parsing the nwr tags and they are missing the k and...
[rails.git] / test / unit / old_node_tag_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class OldNodeTest < ActiveSupport::TestCase
4   api_fixtures
5
6   def test_old_node_tag_count
7     assert_equal 9, OldNodeTag.count, "Unexpected number of fixtures loaded."
8   end
9   
10   def test_length_key_valid
11     key = "k"
12     (0..255).each do |i|
13       tag = OldNodeTag.new
14       tag.id = node_tags(:t1).id
15       tag.version = node_tags(:t1).version
16       tag.k = key*i
17       tag.v = "v"
18       assert tag.valid?
19     end
20   end
21   
22   def test_length_value_valid
23     val = "v"
24     (0..255).each do |i|
25       tag = OldNodeTag.new
26       tag.id = node_tags(:t1).id
27       tag.version = node_tags(:t1).version
28       tag.k = "k"
29       tag.v = val*i
30       assert tag.valid?
31     end
32   end
33   
34   def test_length_key_invalid
35     ["k"*256].each do |i|
36       tag = OldNodeTag.new
37       tag.id = node_tags(:t1).id
38       tag.version = node_tags(:t1).version
39       tag.k = i
40       tag.v = "v", "Key should be too long"
41       assert !tag.valid?
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 = OldNodeTag.new
49       tag.id = node_tags(:t1).id
50       tag.version = node_tags(:t1).version
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_old_node_tag_invalid
59     tag = OldNodeTag.new
60     assert !tag.valid?, "Empty tag should be invalid"
61     assert tag.errors.invalid?(:id)
62     assert tag.errors.invalid?(:version)
63   end
64   
65   def test_uniqueness
66     tag = OldNodeTag.new
67     tag.id = node_tags(:t1).id
68     tag.version = node_tags(:t1).version
69     tag.k = node_tags(:t1).k
70     tag.v = node_tags(:t1).v
71     assert tag.new_record?
72     assert !tag.valid?
73     assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
74     assert tag.new_record?
75   end
76 end