]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5178'
authorTom Hughes <tom@compton.nu>
Fri, 13 Sep 2024 17:09:37 +0000 (18:09 +0100)
committerTom Hughes <tom@compton.nu>
Fri, 13 Sep 2024 17:09:37 +0000 (18:09 +0100)
app/controllers/application_controller.rb
app/views/changeset_comments/feeds/timeout.atom.builder [deleted file]
app/views/changeset_comments/feeds/timeout.html.erb [deleted file]
app/views/changeset_comments/feeds/timeout.rss.builder [new file with mode: 0644]
test/controllers/changeset_comments/feeds_controller_test.rb

index 4b36607bb00a988b671ce3f2da760633f0aabeba..fdc2ac4e8694191790ffadab11ae9bbe5e55dc54 100644 (file)
@@ -216,20 +216,25 @@ class ApplicationController < ActionController::Base
   ##
   # wrap a web page in a timeout
   def web_timeout(&block)
+    raise Timeout::Error if Settings.web_timeout.negative?
+
     Timeout.timeout(Settings.web_timeout, &block)
   rescue ActionView::Template::Error => e
     e = e.cause
 
     if e.is_a?(Timeout::Error) ||
        (e.is_a?(ActiveRecord::StatementInvalid) && e.message.include?("execution expired"))
-      ActiveRecord::Base.connection.raw_connection.cancel
-      render :action => "timeout"
+      respond_to_timeout
     else
       raise
     end
   rescue Timeout::Error
+    respond_to_timeout
+  end
+
+  def respond_to_timeout
     ActiveRecord::Base.connection.raw_connection.cancel
-    render :action => "timeout"
+    render :action => "timeout", :status => :gateway_timeout
   end
 
   ##
diff --git a/app/views/changeset_comments/feeds/timeout.atom.builder b/app/views/changeset_comments/feeds/timeout.atom.builder
deleted file mode 100644 (file)
index b5eeeed..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-atom_feed(:language => I18n.locale, :schema_date => 2009,
-          :id => url_for(params.merge(:only_path => false)),
-          :root_url => url_for(params.merge(:only_path => false, :format => nil)),
-          "xmlns:georss" => "http://www.georss.org/georss") do |feed|
-  feed.title @title
-
-  feed.subtitle :type => "xhtml" do |xhtml|
-    xhtml.p do |p|
-      p << t(".sorry")
-    end
-  end
-end
diff --git a/app/views/changeset_comments/feeds/timeout.html.erb b/app/views/changeset_comments/feeds/timeout.html.erb
deleted file mode 100644 (file)
index 641b1df..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<p><%= t ".sorry" %></p>
diff --git a/app/views/changeset_comments/feeds/timeout.rss.builder b/app/views/changeset_comments/feeds/timeout.rss.builder
new file mode 100644 (file)
index 0000000..c56ebb8
--- /dev/null
@@ -0,0 +1,12 @@
+xml.rss("version" => "2.0",
+        "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do
+  xml.channel do
+    if params[:changeset_id]
+      xml.title t("changeset_comments.feeds.show.title_particular", :changeset_id => params[:changeset_id])
+    else
+      xml.title t("changeset_comments.feeds.show.title_all")
+    end
+    xml.link root_url
+    xml.description t(".sorry")
+  end
+end
index 20db62cefce8479bb56951aeebbb4135ab938459..4858eb085c417a72cb0763ed96d7870a47676829 100644 (file)
@@ -68,5 +68,25 @@ module ChangesetComments
       get changesets_comments_feed_path(:format => "rss", :limit => 100001)
       assert_response :bad_request
     end
+
+    def test_feed_timeout
+      with_settings(:web_timeout => -1) do
+        get changesets_comments_feed_path
+      end
+      assert_response :error
+      assert_equal "application/rss+xml; charset=utf-8", @response.header["Content-Type"]
+      assert_dom "rss>channel>title", :text => "OpenStreetMap changeset discussion"
+      assert_dom "rss>channel>description", :text => /the list of changeset comments you requested took too long to retrieve/
+    end
+
+    def test_feed_changeset_timeout
+      with_settings(:web_timeout => -1) do
+        get changeset_comments_feed_path(123)
+      end
+      assert_response :error
+      assert_equal "application/rss+xml; charset=utf-8", @response.header["Content-Type"]
+      assert_dom "rss>channel>title", :text => "OpenStreetMap changeset #123 discussion"
+      assert_dom "rss>channel>description", :text => /the list of changeset comments you requested took too long to retrieve/
+    end
   end
 end