From: Anton Khorev Date: Wed, 1 May 2024 12:02:59 +0000 (+0300) Subject: Link to previous/next nonempty user's changeset on changeset pages X-Git-Tag: live~581^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/15e1459f25673ec7b59392cc21a7533e0f15f9d7 Link to previous/next nonempty user's changeset on changeset pages --- diff --git a/app/controllers/changesets_controller.rb b/app/controllers/changesets_controller.rb index 3ea5fb64e..6a80f260a 100644 --- a/app/controllers/changesets_controller.rb +++ b/app/controllers/changesets_controller.rb @@ -84,8 +84,9 @@ class ChangesetsController < ApplicationController @way_pages, @ways = paginate(:old_ways, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "way_page") @relation_pages, @relations = paginate(:old_relations, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "relation_page") if @changeset.user.active? && @changeset.user.data_public? - @next_by_user = @changeset.user.changesets.where("id > ?", @changeset.id).reorder(:id => :asc).first - @prev_by_user = @changeset.user.changesets.where("id < ?", @changeset.id).reorder(:id => :desc).first + changesets = conditions_nonempty(@changeset.user.changesets) + @next_by_user = changesets.where("id > ?", @changeset.id).reorder(:id => :asc).first + @prev_by_user = changesets.where("id < ?", @changeset.id).reorder(:id => :desc).first end render :layout => map_layout rescue ActiveRecord::RecordNotFound diff --git a/test/controllers/changesets_controller_test.rb b/test/controllers/changesets_controller_test.rb index 1fd9de2e8..3d264181c 100644 --- a/test/controllers/changesets_controller_test.rb +++ b/test/controllers/changesets_controller_test.rb @@ -321,13 +321,26 @@ class ChangesetsControllerTest < ActionDispatch::IntegrationTest def test_show_adjacent_changesets user = create(:user) - changesets = create_list(:changeset, 3, :user => user) + changesets = create_list(:changeset, 3, :user => user, :num_changes => 1) 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 + def test_show_adjacent_nonempty_changesets + user = create(:user) + changeset1 = create(:changeset, :user => user, :num_changes => 1) + create(:changeset, :user => user, :num_changes => 0) + changeset3 = create(:changeset, :user => user, :num_changes => 1) + create(:changeset, :user => user, :num_changes => 0) + changeset5 = create(:changeset, :user => user, :num_changes => 1) + + sidebar_browse_check :changeset_path, changeset3.id, "changesets/show" + assert_dom "a[href='#{changeset_path changeset1}']", :count => 1 + assert_dom "a[href='#{changeset_path changeset5}']", :count => 1 + end + ## # This should display the last 20 non-empty changesets def test_feed