]> git.openstreetmap.org Git - rails.git/blob - test/controllers/changeset_comments/feeds_controller_test.rb
Merge pull request #5932 from tomhughes/frozen-strings
[rails.git] / test / controllers / changeset_comments / feeds_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 module ChangesetComments
6   class FeedsControllerTest < ActionDispatch::IntegrationTest
7     ##
8     # test all routes which lead to this controller
9     def test_routes
10       assert_routing(
11         { :path => "/changeset/1/comments/feed", :method => :get },
12         { :controller => "changeset_comments/feeds", :action => "show", :changeset_id => "1", :format => "rss" }
13       )
14       assert_routing(
15         { :path => "/history/comments/feed", :method => :get },
16         { :controller => "changeset_comments/feeds", :action => "show", :format => "rss" }
17       )
18     end
19
20     ##
21     # test comments feed
22     def test_feed
23       changeset = create(:changeset, :closed)
24       create_list(:changeset_comment, 3, :changeset => changeset)
25
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
32         end
33       end
34
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
41         end
42       end
43
44       get changeset_comments_feed_path(changeset, :format => "rss")
45       assert_response :success
46       assert_equal "application/rss+xml", @response.media_type
47       last_comment_id = -1
48       assert_select "rss", :count => 1 do
49         assert_select "channel", :count => 1 do
50           assert_select "item", :count => 3 do |items|
51             items.each do |item|
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
57               end
58             end
59           end
60         end
61       end
62     end
63
64     ##
65     # test comments feed
66     def test_feed_bad_limit
67       get changesets_comments_feed_path(:format => "rss", :limit => 0)
68       assert_response :bad_request
69
70       get changesets_comments_feed_path(:format => "rss", :limit => 100001)
71       assert_response :bad_request
72     end
73
74     def test_feed_timeout
75       with_settings(:web_timeout => -1) do
76         get changesets_comments_feed_path
77       end
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/
82     end
83
84     def test_feed_changeset_timeout
85       with_settings(:web_timeout => -1) do
86         get changeset_comments_feed_path(123)
87       end
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/
92     end
93   end
94 end