Merge 12304:14009 from trunk.
[rails.git] / test / unit / way_tag_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class WayTagTest < Test::Unit::TestCase
4   fixtures :current_way_tags
5   set_fixture_class :current_way_tags => WayTag
6   
7   def test_way_tag_count
8     assert_equal 3, WayTag.count
9   end
10   
11   def test_length_key_valid
12     key = "k"
13     (0..255).each do |i|
14       tag = WayTag.new
15       tag.id = current_way_tags(:t1).id
16       tag.k = key*i
17       tag.v = current_way_tags(:t1).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 = WayTag.new
26       tag.id = current_way_tags(:t1).id
27       tag.k = "k"
28       tag.v = val*i
29       assert_valid tag
30     end
31   end
32   
33   def test_length_key_invalid
34     ["k"*256].each do |i|
35       tag = WayTag.new
36       tag.id = current_way_tags(:t1).id
37       tag.k = i
38       tag.v = "v"
39       assert !tag.valid?, "Key #{i} should be too long"
40       assert tag.errors.invalid?(:k)
41     end
42   end
43   
44   def test_length_value_invalid
45     ["v"*256].each do |i|
46       tag = WayTag.new
47       tag.id = current_way_tags(:t1).id
48       tag.k = "k"
49       tag.v = i
50       assert !tag.valid?, "Value #{i} should be too long"
51       assert tag.errors.invalid?(:v)
52     end
53   end
54   
55   def test_empty_tag_invalid
56     tag = WayTag.new
57     assert !tag.valid?, "Empty way tag should be invalid"
58     assert tag.errors.invalid?(:id)
59   end
60   
61   def test_uniqueness
62     tag = WayTag.new
63     tag.id = current_way_tags(:t1).id
64     tag.k = current_way_tags(:t1).k
65     tag.v = current_way_tags(:t1).v
66     assert tag.new_record?
67     assert !tag.valid?
68     assert_raise(ActiveRecord::RecordInvalid) {tag.save!}
69     assert tag.new_record?
70   end
71 end