From 0dae690c06fd32a03cea3d45c53f52d29439e4da Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 16 Mar 2024 18:36:33 +0300 Subject: [PATCH] Simplify changeset/element-related link_to calls --- app/helpers/changesets_helper.rb | 2 +- app/views/browse/_containing_relation.html.erb | 2 +- app/views/browse/_relation_member.html.erb | 2 +- app/views/changesets/_heading.html.erb | 4 ++-- app/views/changesets/show.html.erb | 6 +++--- app/views/dashboards/_contact.html.erb | 4 ++-- app/views/dashboards/_popup.html.erb | 2 +- test/controllers/changesets_controller_test.rb | 10 ++++++++++ 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/helpers/changesets_helper.rb b/app/helpers/changesets_helper.rb index dbee08c50..970522160 100644 --- a/app/helpers/changesets_helper.rb +++ b/app/helpers/changesets_helper.rb @@ -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 diff --git a/app/views/browse/_containing_relation.html.erb b/app/views/browse/_containing_relation.html.erb index 0b6a2c8f8..febb3e129 100644 --- a/app/views/browse/_containing_relation.html.erb +++ b/app/views/browse/_containing_relation.html.erb @@ -1,4 +1,4 @@ -
  • <%= linked_name = link_to printable_element_name(containing_relation.relation), relation_path(containing_relation.relation) +
  • <%= 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 diff --git a/app/views/browse/_relation_member.html.erb b/app/views/browse/_relation_member.html.erb index 7ea75a106..d122f0edf 100644 --- a/app/views/browse/_relation_member.html.erb +++ b/app/views/browse/_relation_member.html.erb @@ -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? diff --git a/app/views/changesets/_heading.html.erb b/app/views/changesets/_heading.html.erb index 33bc71696..a125a135a 100644 --- a/app/views/changesets/_heading.html.erb +++ b/app/views/changesets/_heading.html.erb @@ -5,11 +5,11 @@ <%= user_thumbnail changeset.user %>
    -

    <%= link_to title, changeset_path(changeset) %>

    +

    <%= link_to title, changeset %>

    - <%= 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)) %> diff --git a/app/views/changesets/show.html.erb b/app/views/changesets/show.html.erb index fdaf7654c..3ba3968f7 100644 --- a/app/views/changesets/show.html.erb +++ b/app/views/changesets/show.html.erb @@ -34,7 +34,7 @@ <%= 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"), @@ -125,7 +125,7 @@ <% if @next_by_user || @prev_by_user %>
    <% 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 %> @@ -135,7 +135,7 @@ link_to tag.bdi(user), :controller => "changesets", :action => "index", :display_name => user %> <% if @next_by_user %> · - <%= 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 %> diff --git a/app/views/dashboards/_contact.html.erb b/app/views/dashboards/_contact.html.erb index b789f721b..b28a28a26 100644 --- a/app/views/dashboards/_contact.html.erb +++ b/app/views/dashboards/_contact.html.erb @@ -10,7 +10,7 @@

    - <%= 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"] %> - <%= link_to comment, changeset_path(changeset), :title => t("changesets.changeset.view_changeset_details") %> + <%= link_to comment, changeset, :title => t("changesets.changeset.view_changeset_details") %> <% else %> <%= t "changesets.changeset.no_edits" %> <% end %> diff --git a/app/views/dashboards/_popup.html.erb b/app/views/dashboards/_popup.html.erb index c4f8b627a..de90a117b 100644 --- a/app/views/dashboards/_popup.html.erb +++ b/app/views/dashboards/_popup.html.erb @@ -4,6 +4,6 @@

    <%= t(".#{type}") %>

    -

    <%= link_to popup.display_name, user_path(popup) %>

    +

    <%= link_to popup.display_name, popup %>

    diff --git a/test/controllers/changesets_controller_test.rb b/test/controllers/changesets_controller_test.rb index ae5a28021..32a4e4f70 100644 --- a/test/controllers/changesets_controller_test.rb +++ b/test/controllers/changesets_controller_test.rb @@ -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 -- 2.43.2