1 # frozen_string_literal: true
 
   5 class NoteTest < ActiveSupport::TestCase
 
   7     ok = %w[open closed hidden]
 
   8     bad = %w[expropriated fubared]
 
  13       assert_predicate note, :valid?, "#{status} is invalid, when it should be"
 
  19       assert_not_predicate note, :valid?, "#{status} is valid when it shouldn't be"
 
  25     assert_equal "open", note.status
 
  26     assert_nil note.closed_at
 
  28     assert_equal "closed", note.status
 
  29     assert_not_nil note.closed_at
 
  33     note = create(:note, :closed)
 
  34     assert_equal "closed", note.status
 
  35     assert_not_nil note.closed_at
 
  37     assert_equal "open", note.status
 
  38     assert_nil note.closed_at
 
  42     assert_predicate create(:note, :status => "open"), :visible?
 
  43     assert_predicate create(:note, :closed), :visible?
 
  44     assert_not_predicate create(:note, :status => "hidden"), :visible?
 
  48     assert_predicate create(:note, :closed), :closed?
 
  49     assert_not_predicate create(:note, :status => "open", :closed_at => nil), :closed?
 
  54     assert_equal "Default note's description", note.description
 
  56     note = create(:note, :description => "Test description #1")
 
  57     assert_equal "Test description #1", note.description
 
  59     comment = create(:note_comment)
 
  60     assert_equal "Default note's description", comment.note.description
 
  62     comment = create(:note_comment, :note => build(:note, :description => "Test description #2"))
 
  63     assert_equal "Test description #2", comment.note.description
 
  69     note = create(:note, :author => user)
 
  70     assert_equal user, note.author
 
  72     comment = create(:note_comment)
 
  73     assert_nil comment.note.author
 
  75     comment = create(:note_comment, :author => user, :note => build(:note, :author => user))
 
  76     assert_equal user, comment.note.author
 
  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)
 
  83     assert_equal "0.0000400", note.lat.to_s
 
  84     assert_equal "0.0000800", note.lon.to_s