Standardise on double quoted strings
[rails.git] / test / models / old_way_tag_test.rb
1 require "test_helper"
2
3 class OldWayTagTest < ActiveSupport::TestCase
4   api_fixtures
5
6   def test_tag_count
7     assert_equal 12, OldWayTag.count
8   end
9
10   def test_length_key_valid
11     key = "k"
12     (0..255).each do |i|
13       tag = OldWayTag.new
14       tag.way_id = way_tags(:t1).way_id
15       tag.version = 1
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 = OldWayTag.new
26       tag.way_id = way_tags(:t1).way_id
27       tag.version = 1
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 = OldWayTag.new
37       tag.way_id = way_tags(:t1).way_id
38       tag.version = 1
39       tag.k = i
40       tag.v = "v"
41       assert !tag.valid?, "Key should be too long"
42       assert tag.errors[:k].any?
43     end
44   end
45
46   def test_length_value_invalid
47     ["k" * 256].each do |i|
48       tag = OldWayTag.new
49       tag.way_id = way_tags(:t1).way_id
50       tag.version = 1
51       tag.k = "k"
52       tag.v = i
53       assert !tag.valid?, "Value should be too long"
54       assert tag.errors[:v].any?
55     end
56   end
57
58   def test_empty_tag_invalid
59     tag = OldWayTag.new
60     assert !tag.valid?, "Empty tag should be invalid"
61     assert tag.errors[:old_way].any?
62   end
63
64   def test_uniqueness
65     tag = OldWayTag.new
66     tag.way_id = way_tags(:t1).way_id
67     tag.version = way_tags(:t1).version
68     tag.k = way_tags(:t1).k
69     tag.v = way_tags(:t1).v
70     assert tag.new_record?
71     assert !tag.valid?
72     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
73     assert tag.new_record?
74   end
75 end