Skip to content

Commit

Permalink
Move changeset comments feeds to resourceful routes
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Mar 22, 2024
1 parent 1f15096 commit 58d4a8b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/abilities/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/changeset_comments_feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
39 changes: 23 additions & 16 deletions test/controllers/changeset_comments_feeds_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 58d4a8b

Please sign in to comment.