From 58d4a8b0039dc6b71b6b84b46c48c681719209d9 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Fri, 22 Mar 2024 05:50:26 +0300 Subject: [PATCH] Move changeset comments feeds to resourceful routes --- app/abilities/ability.rb | 2 +- .../changeset_comments_feeds_controller.rb | 8 ++-- .../{index.rss.builder => show.rss.builder} | 0 config/locales/en.yml | 2 +- config/routes.rb | 5 ++- ...hangeset_comments_feeds_controller_test.rb | 39 +++++++++++-------- 6 files changed, 32 insertions(+), 24 deletions(-) rename app/views/changeset_comments_feeds/{index.rss.builder => show.rss.builder} (100%) diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 89868c7a5bf..6ce42786b76 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -16,7 +16,7 @@ def initialize(user) if Settings.status != "database_offline" can [:index, :feed, :show], Changeset - can :index, :changeset_comments_feed + can :show, :changeset_comments_feed can [:confirm, :confirm_resend, :confirm_email], :confirmation can [:index, :rss, :show, :comments], DiaryEntry can [:index], Note diff --git a/app/controllers/changeset_comments_feeds_controller.rb b/app/controllers/changeset_comments_feeds_controller.rb index de62b1b4e5f..6e0a88abf3f 100644 --- a/app/controllers/changeset_comments_feeds_controller.rb +++ b/app/controllers/changeset_comments_feeds_controller.rb @@ -9,13 +9,13 @@ class ChangesetCommentsFeedsController < ApplicationController ## # Get a feed of recent changeset comments - def index - if params[:id] + def show + if params[:changeset_id] # Extract the arguments - id = params[:id].to_i + changeset_id = params[:changeset_id].to_i # Find the changeset - changeset = Changeset.find(id) + changeset = Changeset.find(changeset_id) # Return comments for this changeset only @comments = changeset.comments.includes(:author, :changeset).limit(comments_limit) diff --git a/app/views/changeset_comments_feeds/index.rss.builder b/app/views/changeset_comments_feeds/show.rss.builder similarity index 100% rename from app/views/changeset_comments_feeds/index.rss.builder rename to app/views/changeset_comments_feeds/show.rss.builder diff --git a/config/locales/en.yml b/config/locales/en.yml index 1a2aade91dc..597872f222e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -492,7 +492,7 @@ en: commented_at_by_html: "Updated %{when} by %{user}" comments: comment: "New comment on changeset #%{changeset_id} by %{author}" - index: + show: title_all: OpenStreetMap changeset discussion title_particular: "OpenStreetMap changeset #%{changeset_id} discussion" timeout: diff --git a/config/routes.rb b/config/routes.rb index c9babecdb6e..67912f2c061 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -120,8 +120,9 @@ resources :old_relations, :path => "/relation/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show resources :changesets, :path => "changeset", :id => /\d+/, :only => :show do match :subscribe, :unsubscribe, :on => :member, :via => [:get, :post] + + resource :changeset_comments_feed, :path => "comments/feed", :only => :show, :defaults => { :format => "rss" } end - get "/changeset/:id/comments/feed" => "changeset_comments_feeds#index", :as => :changeset_comments_feed, :id => /\d*/, :defaults => { :format => "rss" } resources :notes, :path => "note", :only => [:show, :new] get "/user/:display_name/history" => "changesets#index" @@ -159,7 +160,7 @@ get "/communities" => "site#communities" get "/history" => "changesets#index" get "/history/feed" => "changesets#feed", :defaults => { :format => :atom } - get "/history/comments/feed" => "changeset_comments_feeds#index", :as => :changesets_comments_feed, :defaults => { :format => "rss" } + resource :changeset_comments_feed, :path => "/history/comments/feed", :only => :show, :defaults => { :format => "rss" } get "/export" => "site#export" get "/login" => "sessions#new" post "/login" => "sessions#create" diff --git a/test/controllers/changeset_comments_feeds_controller_test.rb b/test/controllers/changeset_comments_feeds_controller_test.rb index 841e8f87874..a4a9bcd61f0 100644 --- a/test/controllers/changeset_comments_feeds_controller_test.rb +++ b/test/controllers/changeset_comments_feeds_controller_test.rb @@ -6,21 +6,21 @@ class ChangesetCommentsFeedsControllerTest < ActionDispatch::IntegrationTest def test_routes assert_routing( { :path => "/changeset/1/comments/feed", :method => :get }, - { :controller => "changeset_comments_feeds", :action => "index", :id => "1", :format => "rss" } + { :controller => "changeset_comments_feeds", :action => "show", :changeset_id => "1", :format => "rss" } ) assert_routing( { :path => "/history/comments/feed", :method => :get }, - { :controller => "changeset_comments_feeds", :action => "index", :format => "rss" } + { :controller => "changeset_comments_feeds", :action => "show", :format => "rss" } ) end - ## - # test comments feed - def test_feed - changeset = create(:changeset, :closed) - create_list(:changeset_comment, 3, :changeset => changeset) + def test_show + changeset1 = create(:changeset, :closed) + changeset2 = create(:changeset, :closed) + create_list(:changeset_comment, 1, :changeset => changeset1) + create_list(:changeset_comment, 2, :changeset => changeset2) - get changesets_comments_feed_path(:format => "rss") + get changeset_comments_feed_path(:format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -29,7 +29,7 @@ def test_feed end end - get changesets_comments_feed_path(:format => "rss", :limit => 2) + get changeset_comments_feed_path(:format => "rss", :limit => 2) assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do @@ -38,23 +38,30 @@ def test_feed end end - get changeset_comments_feed_path(:id => changeset.id, :format => "rss") + get changeset_changeset_comments_feed_path(changeset1, :format => "rss") assert_response :success assert_equal "application/rss+xml", @response.media_type assert_select "rss", :count => 1 do assert_select "channel", :count => 1 do - assert_select "item", :count => 3 + assert_select "item", :count => 1 + end + end + + get changeset_changeset_comments_feed_path(changeset2, :format => "rss") + assert_response :success + assert_equal "application/rss+xml", @response.media_type + assert_select "rss", :count => 1 do + assert_select "channel", :count => 1 do + assert_select "item", :count => 2 end end end - ## - # test comments feed - def test_feed_bad_limit - get changesets_comments_feed_path(:format => "rss", :limit => 0) + def test_show_bad_limit + get changeset_comments_feed_path(:format => "rss", :limit => 0) assert_response :bad_request - get changesets_comments_feed_path(:format => "rss", :limit => 100001) + get changeset_comments_feed_path(:format => "rss", :limit => 100001) assert_response :bad_request end end