]> git.openstreetmap.org Git - rails.git/blob - test/models/note_test.rb
Add frozen_string_literal comments to ruby files
[rails.git] / test / models / note_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class NoteTest < ActiveSupport::TestCase
6   def test_status_valid
7     ok = %w[open closed hidden]
8     bad = %w[expropriated fubared]
9
10     ok.each do |status|
11       note = create(:note)
12       note.status = status
13       assert_predicate note, :valid?, "#{status} is invalid, when it should be"
14     end
15
16     bad.each do |status|
17       note = create(:note)
18       note.status = status
19       assert_not_predicate note, :valid?, "#{status} is valid when it shouldn't be"
20     end
21   end
22
23   def test_close
24     note = create(:note)
25     assert_equal "open", note.status
26     assert_nil note.closed_at
27     note.close
28     assert_equal "closed", note.status
29     assert_not_nil note.closed_at
30   end
31
32   def test_reopen
33     note = create(:note, :closed)
34     assert_equal "closed", note.status
35     assert_not_nil note.closed_at
36     note.reopen
37     assert_equal "open", note.status
38     assert_nil note.closed_at
39   end
40
41   def test_visible?
42     assert_predicate create(:note, :status => "open"), :visible?
43     assert_predicate create(:note, :closed), :visible?
44     assert_not_predicate create(:note, :status => "hidden"), :visible?
45   end
46
47   def test_closed?
48     assert_predicate create(:note, :closed), :closed?
49     assert_not_predicate create(:note, :status => "open", :closed_at => nil), :closed?
50   end
51
52   def test_description
53     note = create(:note)
54     assert_equal "Default note's description", note.description
55
56     note = create(:note, :description => "Test description #1")
57     assert_equal "Test description #1", note.description
58
59     comment = create(:note_comment)
60     assert_equal "Default note's description", comment.note.description
61
62     comment = create(:note_comment, :note => build(:note, :description => "Test description #2"))
63     assert_equal "Test description #2", comment.note.description
64   end
65
66   def test_author
67     user = create(:user)
68
69     note = create(:note, :author => user)
70     assert_equal user, note.author
71
72     comment = create(:note_comment)
73     assert_nil comment.note.author
74
75     comment = create(:note_comment, :author => user, :note => build(:note, :author => user))
76     assert_equal user, comment.note.author
77   end
78
79   # Ensure the lat/lon is formatted as a decimal e.g. not 4.0e-05
80   def test_lat_lon_format
81     note = build(:note, :latitude => 0.00004 * GeoRecord::SCALE, :longitude => 0.00008 * GeoRecord::SCALE)
82
83     assert_equal "0.0000400", note.lat.to_s
84     assert_equal "0.0000800", note.lon.to_s
85   end
86 end