resync from rails_port 11795:12304
[rails.git] / test / unit / old_way_tag_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class WayTagTest < Test::Unit::TestCase
4   fixtures :way_tags
5   set_fixture_class :way_tags => OldWayTag
6   
7   def test_tag_count
8     assert_equal 3, OldWayTag.count
9   end
10   
11   def test_length_key_valid
12     key = "k"
13     (0..255).each do |i|
14       tag = OldWayTag.new
15       tag.id = way_tags(:t1).id
16       tag.version = 1
17       tag.k = key*i
18       tag.v = "v"
19       assert_valid tag
20     end
21   end
22   
23   def test_length_value_valid
24     val = "v"
25     (0..255).each do |i|
26       tag = OldWayTag.new
27       tag.id = way_tags(:t1).id
28       tag.version = 1
29       tag.k = "k"
30       tag.v = val*i
31       assert_valid tag
32     end
33   end
34   
35   def test_length_key_invalid
36     ["k"*256].each do |i|
37       tag = OldWayTag.new
38       tag.id = way_tags(:t1).id
39       tag.version = 1
40       tag.k = i
41       tag.v = "v"
42       assert !tag.valid?, "Key should be too long"
43       assert tag.errors.invalid?(:k)
44     end
45   end
46   
47   def test_length_value_invalid
48     ["k"*256].each do |i|
49       tag = OldWayTag.new
50       tag.id = way_tags(:t1).id
51       tag.version = 1
52       tag.k = "k"
53       tag.v = i
54       assert !tag.valid?, "Value should be too long"
55       assert tag.errors.invalid?(:v)
56     end
57   end
58   
59   def test_empty_node_tag_invalid
60     tag = OldNodeTag.new
61     assert !tag.valid?, "Empty tag should be invalid"
62     assert tag.errors.invalid?(:id)
63   end
64   
65   def test_uniqueness
66     tag = OldWayTag.new
67     tag.id = way_tags(:t1).id
68     tag.version = way_tags(:t1).version
69     tag.k = way_tags(:t1).k
70     tag.v = way_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