]> git.openstreetmap.org Git - rails.git/blob - test/models/way_tag_test.rb
Exclude files in the vendor directory from erb-lint rubocop checks
[rails.git] / test / models / way_tag_test.rb
1 require "test_helper"
2
3 class WayTagTest < ActiveSupport::TestCase
4   def test_length_key_valid
5     tag = create(:way_tag)
6     (0..255).each do |i|
7       tag.k = "k" * i
8       assert tag.valid?
9     end
10   end
11
12   def test_length_value_valid
13     tag = create(:way_tag)
14     (0..255).each do |i|
15       tag.v = "v" * i
16       assert tag.valid?
17     end
18   end
19
20   def test_length_key_invalid
21     tag = create(:way_tag)
22     tag.k = "k" * 256
23     assert_not tag.valid?, "Key should be too long"
24     assert tag.errors[:k].any?
25   end
26
27   def test_length_value_invalid
28     tag = create(:way_tag)
29     tag.v = "v" * 256
30     assert_not tag.valid?, "Value should be too long"
31     assert tag.errors[:v].any?
32   end
33
34   def test_empty_tag_invalid
35     tag = WayTag.new
36     assert_not tag.valid?, "Empty way tag should be invalid"
37     assert tag.errors[:way].any?
38   end
39
40   def test_uniqueness
41     existing = create(:way_tag)
42     tag = WayTag.new
43     tag.way_id = existing.way_id
44     tag.k = existing.k
45     tag.v = existing.v
46     assert tag.new_record?
47     assert_not tag.valid?
48     assert_raise(ActiveRecord::RecordInvalid) { tag.save! }
49     assert tag.new_record?
50   end
51 end