]> git.openstreetmap.org Git - rails.git/blob - test/unit/relation_tag_test.rb
Make OAuth work again
[rails.git] / test / unit / relation_tag_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class RelationTagTest < ActiveSupport::TestCase
4   api_fixtures
5   
6   def test_relation_tag_count
7     assert_equal 7, RelationTag.count
8   end
9   
10   def test_length_key_valid
11     key = "k"
12     (0..255).each do |i|
13       tag = RelationTag.new
14       tag.relation_id = 1
15       tag.k = key*i
16       tag.v = "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 = RelationTag.new
25       tag.relation_id = 1
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 = RelationTag.new
35       tag.relation_id = 1
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 = RelationTag.new
46       tag.relation_id = 1
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 = RelationTag.new
56     assert !tag.valid?, "Empty relation tag should be invalid"
57     assert tag.errors[:relation].any?
58   end
59   
60   def test_uniquness
61     tag = RelationTag.new
62     tag.relation_id = current_relation_tags(:t1).relation_id
63     tag.k = current_relation_tags(:t1).k
64     tag.v = current_relation_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
71   ##
72   # test that tags can be updated and saved uniquely, i.e: tag.save!
73   # only affects the single tag that the activerecord object 
74   # represents. this amounts to testing that the primary key is
75   # unique.
76   #
77   # Commenting this out - I attempted to fix it, but composite primary keys
78   # wasn't playing nice with the column already called :id. Seemed to be 
79   # impossible to have validations on the :id column. If someone knows better
80   # please fix, otherwise this test is shelved.
81   #
82   # def test_update
83   #   v = "probably unique string here 3142592654"
84   #   assert_equal 0, RelationTag.count(:conditions => ['v=?', v])
85
86   #   # make sure we select a tag on a relation which has more than one tag
87   #   id = current_relations(:multi_tag_relation).relation_id
88   #   tag = RelationTag.find(:first, :conditions => ["id = ?", id])
89   #   tag.v = v
90   #   tag.save!
91
92   #   assert_equal 1, RelationTag.count(:conditions => ['v=?', v])
93   # end
94 end