From: Tom Hughes Date: Thu, 16 Jan 2025 18:35:36 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/5494' X-Git-Tag: live~379 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/283e7b975b5a80d3f3e8091ce83e8f89b33bb06c?hp=dfc843e7af602350cb240c17b98319f9fa00d08a Merge remote-tracking branch 'upstream/pull/5494' --- diff --git a/app/models/note.rb b/app/models/note.rb index 6d8ca078f..d23f458e5 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -82,12 +82,22 @@ class Note < ApplicationRecord closed_at + DEFAULT_FRESHLY_CLOSED_LIMIT end - # Return the author object, derived from the first comment + # Return the note's description, derived from the first comment + def description + comments.first.body + end + + # Return the note's author object, derived from the first comment def author comments.first.author end - # Return the author IP address, derived from the first comment + # Return the note's author ID, derived from the first comment + def author_id + comments.first.author_id + end + + # Return the note's author IP address, derived from the first comment def author_ip comments.first.author_ip end diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index c88312665..f805a1040 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -48,7 +48,7 @@ <%= link_to note.id, note %> <%= note_author(note.author) %> - <%= note.comments.first.body.to_html %> + <%= note.description.to_html %> <%= friendly_date_ago(note.created_at) %> <%= friendly_date_ago(note.updated_at) %> diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb index d17612e29..a32024048 100644 --- a/app/views/notes/show.html.erb +++ b/app/views/notes/show.html.erb @@ -5,7 +5,7 @@

<%= t(".description") %>

- <%= h(@note_comments.first.body.to_html) %> + <%= h(@note.description.to_html) %>
diff --git a/test/models/note_test.rb b/test/models/note_test.rb index 34b16c19d..ba87911e3 100644 --- a/test/models/note_test.rb +++ b/test/models/note_test.rb @@ -47,6 +47,15 @@ class NoteTest < ActiveSupport::TestCase assert_not_predicate create(:note, :status => "open", :closed_at => nil), :closed? end + def test_description + comment = create(:note_comment) + assert_equal comment.body, comment.note.description + + user = create(:user) + comment = create(:note_comment, :author => user) + assert_equal comment.body, comment.note.description + end + def test_author comment = create(:note_comment) assert_nil comment.note.author @@ -56,6 +65,15 @@ class NoteTest < ActiveSupport::TestCase assert_equal user, comment.note.author end + def test_author_id + comment = create(:note_comment) + assert_nil comment.note.author_id + + user = create(:user) + comment = create(:note_comment, :author => user) + assert_equal user.id, comment.note.author_id + end + def test_author_ip comment = create(:note_comment) assert_nil comment.note.author_ip diff --git a/test/system/report_note_test.rb b/test/system/report_note_test.rb index 79894eb89..c4bcc612d 100644 --- a/test/system/report_note_test.rb +++ b/test/system/report_note_test.rb @@ -4,7 +4,7 @@ class ReportNoteTest < ApplicationSystemTestCase def test_no_link_when_not_logged_in note = create(:note_with_comments) visit note_path(note) - assert_content note.comments.first.body + assert_content note.description assert_no_content I18n.t("notes.show.report") end diff --git a/test/system/report_user_test.rb b/test/system/report_user_test.rb index 7a9e800c8..6ef488e78 100644 --- a/test/system/report_user_test.rb +++ b/test/system/report_user_test.rb @@ -4,7 +4,7 @@ class ReportUserTest < ApplicationSystemTestCase def test_no_link_when_not_logged_in note = create(:note_with_comments) visit note_path(note) - assert_content note.comments.first.body + assert_content note.description assert_no_content I18n.t("users.show.report") end