1 # frozen_string_literal: true
 
   5 module ChangesetComments
 
   6   class FeedsControllerTest < ActionDispatch::IntegrationTest
 
   8     # test all routes which lead to this controller
 
  11         { :path => "/changeset/1/comments/feed", :method => :get },
 
  12         { :controller => "changeset_comments/feeds", :action => "show", :changeset_id => "1", :format => "rss" }
 
  15         { :path => "/history/comments/feed", :method => :get },
 
  16         { :controller => "changeset_comments/feeds", :action => "show", :format => "rss" }
 
  23       changeset = create(:changeset, :closed)
 
  24       create_list(:changeset_comment, 3, :changeset => changeset)
 
  26       get changesets_comments_feed_path(:format => "rss")
 
  27       assert_response :success
 
  28       assert_equal "application/rss+xml", @response.media_type
 
  29       assert_select "rss", :count => 1 do
 
  30         assert_select "channel", :count => 1 do
 
  31           assert_select "item", :count => 3
 
  35       get changesets_comments_feed_path(:format => "rss", :limit => 2)
 
  36       assert_response :success
 
  37       assert_equal "application/rss+xml", @response.media_type
 
  38       assert_select "rss", :count => 1 do
 
  39         assert_select "channel", :count => 1 do
 
  40           assert_select "item", :count => 2
 
  44       get changeset_comments_feed_path(changeset, :format => "rss")
 
  45       assert_response :success
 
  46       assert_equal "application/rss+xml", @response.media_type
 
  48       assert_select "rss", :count => 1 do
 
  49         assert_select "channel", :count => 1 do
 
  50           assert_select "item", :count => 3 do |items|
 
  52               assert_select item, "link", :count => 1 do |link|
 
  53                 match = assert_match(/^#{changeset_url changeset}#c(\d+)$/, link.text)
 
  54                 comment_id = match[1].to_i
 
  55                 assert_operator comment_id, "<", last_comment_id if last_comment_id != -1
 
  56                 last_comment_id = comment_id
 
  66     def test_feed_bad_limit
 
  67       get changesets_comments_feed_path(:format => "rss", :limit => 0)
 
  68       assert_response :bad_request
 
  70       get changesets_comments_feed_path(:format => "rss", :limit => 100001)
 
  71       assert_response :bad_request
 
  75       with_settings(:web_timeout => -1) do
 
  76         get changesets_comments_feed_path
 
  78       assert_response :error
 
  79       assert_equal "application/rss+xml; charset=utf-8", @response.header["Content-Type"]
 
  80       assert_dom "rss>channel>title", :text => "OpenStreetMap changeset discussion"
 
  81       assert_dom "rss>channel>description", :text => /the list of changeset comments you requested took too long to retrieve/
 
  84     def test_feed_changeset_timeout
 
  85       with_settings(:web_timeout => -1) do
 
  86         get changeset_comments_feed_path(123)
 
  88       assert_response :error
 
  89       assert_equal "application/rss+xml; charset=utf-8", @response.header["Content-Type"]
 
  90       assert_dom "rss>channel>title", :text => "OpenStreetMap changeset #123 discussion"
 
  91       assert_dom "rss>channel>description", :text => /the list of changeset comments you requested took too long to retrieve/