Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/5377'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Dec 5, 2024
2 parents 08de53f + 16e97c5 commit fe81ac3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
3 changes: 2 additions & 1 deletion app/helpers/note_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def note_author(author, link_options = {})
elsif author.status == "deleted"
t("users.no_such_user.deleted")
else
link_to h(author.display_name), link_options.merge(:controller => "/users", :action => "show", :display_name => author.display_name)
link_to h(author.display_name), link_options.merge(:controller => "/users", :action => "show", :display_name => author.display_name),
:class => "mw-100 d-inline-block align-bottom text-truncate text-wrap", :dir => "auto"
end
end
end
24 changes: 11 additions & 13 deletions app/views/notes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@
</div>

<div class="details" data-coordinates="<%= @note.lat %>,<%= @note.lon %>" data-status="<%= @note.status %>">
<ul class="list-unstyled">
<li><%= note_event("opened", @note.created_at, @note.author) %></li>
<% if @note.status == "closed" %>
<li><%= note_event(@note.status, @note.closed_at, @note.all_comments.last.author) %></li>
<% end %>
<li>
<%= t "browse.location" %>
<%= link_to(t(".coordinates_html",
:latitude => tag.span(number_with_delimiter(@note.lat), :class => "latitude"),
:longitude => tag.span(number_with_delimiter(@note.lon), :class => "longitude")),
root_path(:anchor => "map=18/#{@note.lat}/#{@note.lon}")) %>
</li>
</ul>
<p class="mb-2"><%= note_event("opened", @note.created_at, @note.author) %></p>
<% if @note.status == "closed" %>
<p class="mb-2"><%= note_event(@note.status, @note.closed_at, @note.all_comments.last.author) %></p>
<% end %>
<p>
<%= t "browse.location" %>
<%= link_to t(".coordinates_html",
:latitude => tag.span(number_with_delimiter(@note.lat), :class => "latitude"),
:longitude => tag.span(number_with_delimiter(@note.lon), :class => "longitude")),
root_path(:anchor => "map=18/#{@note.lat}/#{@note.lon}") %>
</p>
</div>

<% if @note_comments.find { |comment| comment.author.nil? } -%>
Expand Down
34 changes: 30 additions & 4 deletions test/helpers/note_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,43 @@ def test_note_event
date = Time.utc(2014, 3, 5, 21, 37, 45)
user = create(:user)

assert_match %r{^Created by anonymous <time title=" 5 March 2014 at 21:37" datetime="2014-03-05T21:37:45Z">.* ago</time>$}, note_event("opened", date, nil)
assert_match %r{^Resolved by <a href="/user/#{ERB::Util.u(user.display_name)}">#{user.display_name}</a> <time title=" 5 March 2014 at 21:37" datetime="2014-03-05T21:37:45Z">.* ago</time>$}, note_event("closed", date, user)
note_event_dom = Rails::Dom::Testing.html_document_fragment.parse "<div>#{note_event('opened', date, nil)}</div>"
assert_dom note_event_dom, ":root", :text => /^Created by anonymous .* ago$/ do
assert_dom "> a", :count => 0
assert_dom "> time", :count => 1 do
assert_dom "> @title", "5 March 2014 at 21:37"
assert_dom "> @datetime", "2014-03-05T21:37:45Z"
end
end

note_event_dom = Rails::Dom::Testing.html_document_fragment.parse "<div>#{note_event('closed', date, user)}</div>"
assert_dom note_event_dom, ":root", :text => /^Resolved by #{user.display_name} .* ago$/ do
assert_dom "> a", :count => 1, :text => user.display_name do
assert_dom "> @href", "/user/#{ERB::Util.u(user.display_name)}"
end
assert_dom "> time", :count => 1 do
assert_dom "> @title", "5 March 2014 at 21:37"
assert_dom "> @datetime", "2014-03-05T21:37:45Z"
end
end
end

def test_note_author
deleted_user = create(:user, :deleted)
user = create(:user)

assert_equal "", note_author(nil)

assert_equal "deleted", note_author(deleted_user)
assert_equal "<a href=\"/user/#{ERB::Util.u(user.display_name)}\">#{user.display_name}</a>", note_author(user)
assert_equal "<a href=\"http://test.host/user/#{ERB::Util.u(user.display_name)}\">#{user.display_name}</a>", note_author(user, :only_path => false)

note_author_dom = Rails::Dom::Testing.html_document_fragment.parse note_author(user)
assert_dom note_author_dom, "a:root", :text => user.display_name do
assert_dom "> @href", "/user/#{ERB::Util.u(user.display_name)}"
end

note_author_dom = Rails::Dom::Testing.html_document_fragment.parse note_author(user, :only_path => false)
assert_dom note_author_dom, "a:root", :text => user.display_name do
assert_dom "> @href", "http://test.host/user/#{ERB::Util.u(user.display_name)}"
end
end
end

0 comments on commit fe81ac3

Please sign in to comment.