diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-12-17 15:32:39 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-12-17 15:32:39 +0000 |
commit | 153984fd2e6841f3b0bc62e25e1718800a7c63ed (patch) | |
tree | 75a4c86dd00cfb733ce820e48fc657306b4bd632 | |
parent | 1378bcb7ba19214c8b0f99d3825278223e207e65 (diff) |
Only serve up 'similar' pages up to the offset we use for list.
-rw-r--r-- | app/controllers/request_controller.rb | 5 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 8 |
2 files changed, 13 insertions, 0 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index d8c34c2dd..5d950ceb2 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -139,6 +139,11 @@ class RequestController < ApplicationController short_cache @per_page = 25 @page = (params[:page] || "1").to_i + + # Later pages are very expensive to load + if @page > MAX_RESULTS / PER_PAGE + raise ActiveRecord::RecordNotFound.new("Sorry. No pages after #{MAX_RESULTS / PER_PAGE}.") + end @info_request = InfoRequest.find_by_url_title!(params[:url_title]) raise ActiveRecord::RecordNotFound.new("Request not found") if @info_request.nil? diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 45803d74f..148e4327d 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2226,6 +2226,14 @@ describe RequestController, "when showing similar requests" do }.should raise_error(ActiveRecord::RecordNotFound) end + + it "should return 404 for pages we don't want to serve up" do + badger_request = info_requests(:badger_request) + lambda { + get :similar, :url_title => badger_request.url_title, :page => 100 + }.should raise_error(ActiveRecord::RecordNotFound) + end + end |