aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application_controller.rb9
-rw-r--r--spec/controllers/request_controller_spec.rb9
2 files changed, 14 insertions, 4 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 7b5eb5590..ce18e6ef5 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -134,10 +134,10 @@ class ApplicationController < ActionController::Base
# Make sure expiry time for session is set (before_filters are
# otherwise missed by this override)
session_remember_me
-
+
# Make sure the locale is set correctly too
set_gettext_locale
-
+
case exception
when ActiveRecord::RecordNotFound, ActionController::UnknownAction, ActionController::RoutingError
@status = 404
@@ -392,8 +392,11 @@ class ApplicationController < ActionController::Base
# might fail later if the database has subsequently been reopened.
return result
end
+
def get_search_page_from_params
- return (params[:page] || "1").to_i
+ page = (params[:page] || "1").to_i
+ page = 1 if page < 1
+ return page
end
def perform_search_typeahead(query, model)
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index f91f87323..f7316a2c0 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -114,6 +114,7 @@ describe RequestController, "when listing recent requests" do
assigns[:list_results].size.should == 25
assigns[:show_no_more_than].should == RequestController::MAX_RESULTS
end
+
it "should return 404 for pages we don't want to serve up" do
xap_results = mock_model(ActsAsXapian::Search,
:results => (1..25).to_a.map { |m| { :model => m } },
@@ -123,6 +124,12 @@ describe RequestController, "when listing recent requests" do
}.should raise_error(ActiveRecord::RecordNotFound)
end
+ it 'should not raise an error for a page param of less than zero, but should treat it as
+ a param of 1' do
+ lambda{ get :list, :view => 'all', :page => "-1" }.should_not raise_error
+ assigns[:page].should == 1
+ end
+
end
describe RequestController, "when changing things that appear on the request page" do
@@ -1890,7 +1897,7 @@ describe RequestController, "when reporting a request (logged in)" do
@user = users(:robin_user)
session[:user_id] = @user.id
end
-
+
it "should 404 for non-existent requests" do
lambda {
post :report_request, :url_title => "hjksfdhjk_louytu_qqxxx"