]> git.openstreetmap.org Git - rails.git/blob - test/models/changeset_comment_test.rb
Rework DiaryEntry and DiaryComment model tests to use factories.
[rails.git] / test / models / changeset_comment_test.rb
1 # -*- coding: utf-8 -*-
2 require "test_helper"
3
4 class ChangesetCommentTest < ActiveSupport::TestCase
5   fixtures :changesets, :changeset_comments
6
7   def test_changeset_comment_count
8     assert_equal 4, ChangesetComment.count
9   end
10
11   # validations
12   def test_does_not_accept_invalid_author
13     comment = changeset_comments(:normal_comment_1)
14
15     comment.author = nil
16     assert !comment.valid?
17
18     comment.author_id = 999111
19     assert !comment.valid?
20   end
21
22   def test_does_not_accept_invalid_changeset
23     comment = changeset_comments(:normal_comment_1)
24
25     comment.changeset = nil
26     assert !comment.valid?
27
28     comment.changeset_id = 999111
29     assert !comment.valid?
30   end
31
32   def test_does_not_accept_empty_visible
33     comment = changeset_comments(:normal_comment_1)
34
35     comment.visible = nil
36     assert !comment.valid?
37   end
38
39   def test_comments_of_changeset_count
40     assert_equal 3, Changeset.find(changesets(:normal_user_closed_change).id).comments.count
41   end
42
43   def test_body_valid
44     ok = %W(Name vergrößern foo\nbar
45             ルシステムにも対応します 輕觸搖晃的遊戲)
46     bad = ["foo\x00bar", "foo\x08bar", "foo\x1fbar", "foo\x7fbar",
47            "foo\ufffebar", "foo\uffffbar"]
48
49     ok.each do |body|
50       changeset_comment = changeset_comments(:normal_comment_1)
51       changeset_comment.body = body
52       assert changeset_comment.valid?, "#{body} is invalid, when it should be"
53     end
54
55     bad.each do |body|
56       changeset_comment = changeset_comments(:normal_comment_1)
57       changeset_comment.body = body
58       assert !changeset_comment.valid?, "#{body} is valid when it shouldn't be"
59     end
60   end
61 end