]> git.openstreetmap.org Git - rails.git/commitdiff
Simplify changeset/element-related link_to calls
authorAnton Khorev <tony29@yandex.ru>
Sat, 16 Mar 2024 15:36:33 +0000 (18:36 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 16 Mar 2024 15:36:33 +0000 (18:36 +0300)
app/helpers/changesets_helper.rb
app/views/browse/_containing_relation.html.erb
app/views/browse/_relation_member.html.erb
app/views/changesets/_heading.html.erb
app/views/changesets/show.html.erb
app/views/dashboards/_contact.html.erb
app/views/dashboards/_popup.html.erb
test/controllers/changesets_controller_test.rb

index dbee08c507f175e691fffae849b45b357f3515f7..9705221607cddd6a9180b1533d59d61579fcec7f 100644 (file)
@@ -3,7 +3,7 @@ module ChangesetsHelper
     if changeset.user.status == "deleted"
       t("users.no_such_user.deleted")
     elsif changeset.user.data_public?
-      link_to(changeset.user.display_name, user_path(changeset.user))
+      link_to changeset.user.display_name, changeset.user
     else
       t("browse.anonymous")
     end
index 0b6a2c8f8b6f9f2a86108d997af1d1d7bd705eaa..febb3e129fcbdd4575a80cc4d024cab458415b42 100644 (file)
@@ -1,4 +1,4 @@
-<li><%= linked_name = link_to printable_element_name(containing_relation.relation), relation_path(containing_relation.relation)
+<li><%= linked_name = link_to printable_element_name(containing_relation.relation), containing_relation.relation
         if containing_relation.member_role.blank?
           t ".entry_html", :relation_name => linked_name
         else
index 7ea75a1062be11be97d0cde5bcf258aa453dfcb7..d122f0edfed8f327f2c81893a317cbfb588073d8 100644 (file)
@@ -1,4 +1,4 @@
-<% linked_name = link_to printable_element_name(relation_member.member), { :controller => relation_member.member_type.downcase.pluralize, :action => :show, :id => relation_member.member_id.to_s }, { :rel => link_follow(relation_member.member) }
+<% linked_name = link_to printable_element_name(relation_member.member), relation_member.member, { :rel => link_follow(relation_member.member) }
    type_str = t ".type.#{relation_member.member_type.downcase}" %>
 <%= element_list_item relation_member.member_type.downcase, relation_member.member do %>
   <%= if relation_member.member_role.blank?
index 33bc7169693e17ac894a0ef67ba059e7eee62868..a125a135a5ff34c315f47cde4e4f0781492ee771 100644 (file)
@@ -5,11 +5,11 @@
       <%= user_thumbnail changeset.user %>
     </div>
     <div class="col">
-      <h2><%= link_to title, changeset_path(changeset) %></h2>
+      <h2><%= link_to title, changeset %></h2>
     </div>
   </div>
 
   <small class='text-muted'>
-    <%= t(".created_by_html", :link_user => link_to(changeset.user.display_name, user_path(changeset.user)), :created => l(changeset.created_at, :format => :blog)) %>
+    <%= t(".created_by_html", :link_user => link_to(changeset.user.display_name, changeset.user), :created => l(changeset.created_at, :format => :blog)) %>
   </small>
 </div>
index fdaf7654ceeb6180bd71abd9c6ff951634f71c7c..3ba3968f704b20626496e189676fec7e9e831994 100644 (file)
@@ -34,7 +34,7 @@
           <small class='text-muted'>
             <%= t comment.visible ? ".comment_by_html" : ".hidden_comment_by_html",
                   :time_ago => friendly_date_ago(comment.created_at),
-                  :user => link_to(comment.author.display_name, user_path(comment.author)) %>
+                  :user => link_to(comment.author.display_name, comment.author) %>
             <% if current_user&.moderator? %>
               —
               <%= tag.button t("javascripts.changesets.show.#{comment.visible ? 'hide' : 'unhide'}_comment"),
 <% if @next_by_user || @prev_by_user %>
   <div class='secondary-actions'>
     <% if @prev_by_user %>
-      <%= link_to({ :id => @prev_by_user.id }, :class => "icon-link") do %>
+      <%= link_to @prev_by_user, :class => "icon-link" do %>
         <%= previous_page_svg_tag :height => 11 %>
         <%= @prev_by_user.id %>
       <% end %>
         link_to tag.bdi(user), :controller => "changesets", :action => "index", :display_name => user %>
     <% if @next_by_user %>
       &middot;
-      <%= link_to({ :id => @next_by_user.id }, :class => "icon-link") do %>
+      <%= link_to @next_by_user, :class => "icon-link" do %>
         <%= @next_by_user.id %>
         <%= next_page_svg_tag :height => 11 %>
       <% end %>
index b789f721bc828eec29bbc7fc7da2303b6b6eb753..b28a28a26770ead4a7ffd029bcab072d8bf63a5e 100644 (file)
@@ -10,7 +10,7 @@
   </div>
   <div class="col">
     <p class='text-muted mb-0'>
-      <%= link_to contact.display_name, user_path(contact) %>
+      <%= link_to contact.display_name, contact %>
       <% if @user.home_location? and contact.home_location? %>
         <% distance = @user.distance(contact) %>
         <% if distance < 1 %>
@@ -25,7 +25,7 @@
       <% if changeset %>
         <%= t(".latest_edit_html", :ago => friendly_date_ago(changeset.created_at)) %>
         <% comment = changeset.tags["comment"].to_s == "" ? t("browse.no_comment") : changeset.tags["comment"] %>
-        <q><%= link_to comment, changeset_path(changeset), :title => t("changesets.changeset.view_changeset_details") %></q>
+        <q><%= link_to comment, changeset, :title => t("changesets.changeset.view_changeset_details") %></q>
       <% else %>
        <%= t "changesets.changeset.no_edits" %>
       <% end %>
index c4f8b627a153d7ab4fc854518e2d67e64cbea2cd..de90a117b236fc90de1490c0ba435a6cfb0b0ab9 100644 (file)
@@ -4,6 +4,6 @@
   </div>
   <div class="col mx-1">
     <p><%= t(".#{type}") %></p>
-    <p><%= link_to popup.display_name, user_path(popup) %></p>
+    <p><%= link_to popup.display_name, popup %></p>
   </div>
 </div>
index ae5a28021bb40e8a0c3f6821110b9d0c483a2fe0..32a4e4f70545eaddb275a3055fa40f63b2251cd7 100644 (file)
@@ -266,6 +266,7 @@ class ChangesetsControllerTest < ActionDispatch::IntegrationTest
     assert_dom "p", :text => "tested-changeset-comment"
     assert_dom "li#c#{changeset_comment.id}" do
       assert_dom "> small", :text => /^Comment from #{commenting_user.display_name}/
+      assert_dom "a[href='#{user_path(commenting_user)}']"
     end
   end
 
@@ -316,6 +317,15 @@ class ChangesetsControllerTest < ActionDispatch::IntegrationTest
     end
   end
 
+  def test_show_adjacent_changesets
+    user = create(:user)
+    changesets = create_list(:changeset, 3, :user => user)
+
+    sidebar_browse_check :changeset_path, changesets[1].id, "changesets/show"
+    assert_dom "a[href='#{changeset_path changesets[0]}']", :count => 1
+    assert_dom "a[href='#{changeset_path changesets[2]}']", :count => 1
+  end
+
   ##
   # This should display the last 20 non-empty changesets
   def test_feed