]> git.openstreetmap.org Git - rails.git/blob - test/models/changeset_tag_test.rb
More cleanup after tests.
[rails.git] / test / models / changeset_tag_test.rb
1 require "test_helper"
2
3 class ChangesetTagTest < ActiveSupport::TestCase
4   api_fixtures
5
6   def test_changeset_tag_count
7     assert_equal 2, ChangesetTag.count
8   end
9
10   def test_length_key_valid
11     key = "k"
12     (0..255).each do |i|
13       tag = ChangesetTag.new
14       tag.changeset_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 = ChangesetTag.new
25       tag.changeset_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 |k|
34       tag = ChangesetTag.new
35       tag.changeset_id = 1
36       tag.k = k
37       tag.v = "v"
38       assert !tag.valid?, "Key #{k} 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 |v|
45       tag = ChangesetTag.new
46       tag.changeset_id = 1
47       tag.k = "k"
48       tag.v = v
49       assert !tag.valid?, "Value #{v} should be too long"
50       assert tag.errors[:v].any?
51     end
52   end
53
54   def test_empty_tag_invalid
55     tag = ChangesetTag.new
56     assert !tag.valid?, "Empty tag should be invalid"
57     assert tag.errors[:changeset].any?
58   end
59
60   def test_uniqueness
61     tag = ChangesetTag.new
62     tag.changeset_id = changeset_tags(:changeset_1_tag_1).changeset_id
63     tag.k = changeset_tags(:changeset_1_tag_1).k
64     tag.v = changeset_tags(:changeset_1_tag_1).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