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