]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5744'
authorTom Hughes <tom@compton.nu>
Wed, 5 Mar 2025 19:03:33 +0000 (19:03 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 5 Mar 2025 19:03:33 +0000 (19:03 +0000)
app/models/note.rb
test/controllers/api/notes_controller_test.rb
test/factories/note_comments.rb
test/factories/notes.rb
test/models/issue_test.rb
test/models/note_test.rb
test/system/index_test.rb
test/system/note_layer_test.rb
test/system/report_note_test.rb

index 2ec72a03ac6fd5bf228d3319546fd6700e140995..068efa59a3c35c39c920e1d92882822963bde444 100644 (file)
@@ -92,22 +92,9 @@ class Note < ApplicationRecord
     closed_at + DEFAULT_FRESHLY_CLOSED_LIMIT
   end
 
-  # Return the note's description, derived from the first comment
+  # Return the note's description
   def description
-    if user_ip.nil? && user_id.nil?
-      all_comments.first.body if all_comments.first&.event == "opened"
-    else
-      RichText.new("text", super)
-    end
-  end
-
-  # Return the note's author object, derived from the first comment
-  def author
-    if user_ip.nil? && user_id.nil?
-      all_comments.first.author if all_comments.first&.event == "opened"
-    else
-      super
-    end
+    RichText.new("text", super)
   end
 
   private
index c0c67fc91fc3c7f961706ab9138c7421bc7e7b3f..ab05dda9e8b310e233f0831945ff159102b24042 100644 (file)
@@ -338,7 +338,7 @@ module Api
       second_user = create(:user)
       third_user = create(:user)
 
-      note_with_comments_by_users = create(:note) do |note|
+      note_with_comments_by_users = create(:note, :author => first_user) do |note|
         create(:note_comment, :note => note, :author => first_user)
         create(:note_comment, :note => note, :author => second_user)
       end
index da51c022818cfaad36cf15a27093c3567bb7e540..a6d7b532881b7a710aa13002bca633a62d0a6df9 100644 (file)
@@ -2,7 +2,7 @@ FactoryBot.define do
   factory :note_comment do
     sequence(:body) { |n| "This is note comment #{n}" }
     visible { true }
-    event { "opened" }
+    event { "commented" }
     note
   end
 end
index ab7d5df5677cf87f6f277bbf76c22cec1386a0a7..268a2bfb7a489a4f679e0f3f03e71a38be0b245f 100644 (file)
@@ -2,7 +2,7 @@ FactoryBot.define do
   factory :note do
     latitude { 1 * GeoRecord::SCALE }
     longitude { 1 * GeoRecord::SCALE }
-    # tile { QuadTile.tile_for_point(1,1) }
+    description { "Default note's description" }
 
     trait :closed do
       transient do
@@ -23,7 +23,8 @@ FactoryBot.define do
       end
 
       after(:create) do |note, evaluator|
-        create_list(:note_comment, evaluator.comments_count, :note => note)
+        create(:note_comment, :event => "opened", :note => note)
+        create_list(:note_comment, evaluator.comments_count - 1, :note => note)
       end
     end
   end
index b2a868a93f7d62e94576f7abee33155165a1d2af..12a7efec2b1f2c012f919a184a91c4def660b341 100644 (file)
@@ -12,8 +12,8 @@ class IssueTest < ActiveSupport::TestCase
   def test_reported_user
     create(:language, :code => "en")
     user = create(:user)
-    note = create(:note_comment, :author => create(:user)).note
-    anonymous_note = create(:note_comment, :author => nil).note
+    note = create(:note, :author => create(:user))
+    anonymous_note = create(:note, :author => nil)
     diary_entry = create(:diary_entry)
     diary_comment = create(:diary_comment, :diary_entry => diary_entry)
 
index 8b0439ac22dc0e5487f6017e872f6883b50fc4cc..706cda413f014761f5788c852e8b351872b25f40 100644 (file)
@@ -48,20 +48,29 @@ class NoteTest < ActiveSupport::TestCase
   end
 
   def test_description
+    note = create(:note)
+    assert_equal "Default note's description", note.description
+
+    note = create(:note, :description => "Test description #1")
+    assert_equal "Test description #1", note.description
+
     comment = create(:note_comment)
-    assert_equal comment.body, comment.note.description
+    assert_equal "Default note's description", comment.note.description
 
-    user = create(:user)
-    comment = create(:note_comment, :author => user)
-    assert_equal comment.body, comment.note.description
+    comment = create(:note_comment, :note => build(:note, :description => "Test description #2"))
+    assert_equal "Test description #2", comment.note.description
   end
 
   def test_author
+    user = create(:user)
+
+    note = create(:note, :author => user)
+    assert_equal user, note.author
+
     comment = create(:note_comment)
     assert_nil comment.note.author
 
-    user = create(:user)
-    comment = create(:note_comment, :author => user)
+    comment = create(:note_comment, :author => user, :note => build(:note, :author => user))
     assert_equal user, comment.note.author
   end
 
index 2944b817edced0d8f4e3590e84ff79ad8895bf2d..8352cdd1c5ee7a010ecb645a88341d90796b3f83 100644 (file)
@@ -56,20 +56,20 @@ class IndexTest < ApplicationSystemTestCase
 
   test "can navigate from hidden note to visible note" do
     sign_in_as(create(:moderator_user))
-    hidden_note = create(:note, :status => "hidden")
-    create(:note_comment, :note => hidden_note, :body => "this-is-a-hidden-note")
+    hidden_note = create(:note, :status => "hidden", :description => "Hidden Note Description")
+    create(:note_comment, :note => hidden_note, :body => "this-is-a-hidden-note", :event => "opened")
     position = (1.003 * GeoRecord::SCALE).to_i
-    visible_note = create(:note, :latitude => position, :longitude => position)
-    create(:note_comment, :note => visible_note, :body => "this-is-a-visible-note")
+    visible_note = create(:note, :latitude => position, :longitude => position, :description => "Visible Note Description")
+    create(:note_comment, :note => visible_note, :body => "this-is-a-visible-note", :event => "opened")
 
     visit root_path(:anchor => "map=15/1/1") # view place of hidden note in case it is not rendered during note_path(hidden_note)
     visit note_path(hidden_note)
     find(".leaflet-control.control-layers .control-button").click
     find("#map-ui .overlay-layers .form-check-label", :text => "Map Notes").click
     visible_note_marker = find(".leaflet-marker-icon[title=this-is-a-visible-note]")
-    assert_selector "#sidebar", :text => "this-is-a-hidden-note"
+    assert_selector "#sidebar", :text => "Hidden Note Description"
 
     visible_note_marker.click
-    assert_selector "#sidebar", :text => "this-is-a-visible-note"
+    assert_selector "#sidebar", :text => "Visible Note Description"
   end
 end
index 792c3416d61e433735c64ee0b81be6b2cd3e5165..ae940320375c56649baca3666842063f9f39a250 100644 (file)
@@ -4,7 +4,7 @@ class NoteLayerTest < ApplicationSystemTestCase
   test "note marker should have description as a title" do
     position = (1.1 * GeoRecord::SCALE).to_i
     create(:note, :latitude => position, :longitude => position) do |note|
-      create(:note_comment, :note => note, :body => "Note description")
+      create(:note_comment, :note => note, :body => "Note description", :event => "opened")
     end
 
     visit root_path(:anchor => "map=18/1.1/1.1&layers=N")
@@ -16,8 +16,8 @@ class NoteLayerTest < ApplicationSystemTestCase
   test "note marker should not have a title if the note has no visible description" do
     position = (1.1 * GeoRecord::SCALE).to_i
     create(:note, :latitude => position, :longitude => position) do |note|
-      create(:note_comment, :note => note, :body => "Note description is hidden", :visible => false)
-      create(:note_comment, :note => note, :body => "Note comment visible", :event => "commented")
+      create(:note_comment, :note => note, :body => "Note description is hidden", :event => "opened", :visible => false)
+      create(:note_comment, :note => note, :body => "Note comment visible")
     end
 
     visit root_path(:anchor => "map=18/1.1/1.1&layers=N")
@@ -29,7 +29,7 @@ class NoteLayerTest < ApplicationSystemTestCase
   test "note marker should not have a title if the note has no visible description and comments" do
     position = (1.1 * GeoRecord::SCALE).to_i
     create(:note, :latitude => position, :longitude => position) do |note|
-      create(:note_comment, :note => note, :body => "Note description is hidden", :visible => false)
+      create(:note_comment, :note => note, :body => "Note description is hidden", :event => "opened", :visible => false)
     end
 
     visit root_path(:anchor => "map=18/1.1/1.1&layers=N")
index c4bcc612d61751264908e22641422d44d3c60862..0756c8af7350967f21a185d9aca7aa79092c22ab 100644 (file)
@@ -31,7 +31,8 @@ class ReportNoteTest < ApplicationSystemTestCase
   end
 
   def test_can_report_notes_with_author
-    note = create(:note_comment, :author => create(:user)).note
+    user = create(:user)
+    note = create(:note_comment, :author => user, :note => build(:note, :author => user)).note
     sign_in_as(create(:user))
     visit note_path(note)