diff options
-rw-r--r-- | app/controllers/general_controller.rb | 4 | ||||
-rw-r--r-- | config/routes.rb | 6 | ||||
-rw-r--r-- | spec/controllers/general_controller_spec.rb | 8 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 2 |
4 files changed, 13 insertions, 7 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index c052e4e1e..afdbee82b 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -5,7 +5,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: general_controller.rb,v 1.21 2008-04-30 00:46:00 francis Exp $ +# $Id: general_controller.rb,v 1.22 2008-04-30 00:57:20 francis Exp $ class GeneralController < ApplicationController @@ -53,6 +53,8 @@ class GeneralController < ApplicationController # Actual search def search + # XXX Why is this so complicated with arrays and stuff? Look at the route + # in config/routes.rb for comments. combined = params[:combined] sortby = nil if combined.size > 1 and combined[-1] == 'newest' diff --git a/config/routes.rb b/config/routes.rb index bafc7ff36..083accc9e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: routes.rb,v 1.56 2008-04-30 00:37:51 francis Exp $ +# $Id: routes.rb,v 1.57 2008-04-30 00:57:20 francis Exp $ ActionController::Routing::Routes.draw do |map| @@ -19,6 +19,10 @@ ActionController::Routing::Routes.draw do |map| general.auto_complete_for_public_body_query 'auto_complete_for_public_body_query', :action => 'auto_complete_for_public_body_query' general.search_redirect '/search', :action => 'search_redirect' + # XXX combined is the search query, and then if sorted a "/newest" at the end. + # Couldn't find a way to do this in routes which also picked up multiple other slashes + # and dots and other characters that can appear in search query. So we sort it all + # out in the controller. general.search_general '/search/*combined', :action => 'search' general.fai_test '/test', :action => 'fai_test' diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 7a9efcbb8..355a464d6 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -22,13 +22,13 @@ describe GeneralController, "when searching" do it "should redirect from search query URL to pretty URL" do post :search_redirect, :query => "mouse" # query hidden in POST parameters - response.should redirect_to(:action => 'search', :query => "mouse") # URL /search/:query + response.should redirect_to(:action => 'search', :combined => "mouse") # URL /search/:query end it "should find info request when searching for '\"fancy dog\"'" do #ActsAsXapian.rebuild_index([PublicBody, User, InfoRequestEvent]) ActsAsXapian.update_index - get :search, :query => '"fancy dog"' + get :search, :combined => ['"fancy dog"'] response.should render_template('search') assigns[:search_hits].should == 1 @@ -48,7 +48,7 @@ describe GeneralController, "when searching" do it "should find public body and incoming message (in that order) when searching for 'geraldine quango'" do ActsAsXapian.update_index - get :search, :query => 'geraldine quango' + get :search, :combined => ['geraldine quango'] response.should render_template('search') assigns[:search_hits].should == 2 @@ -60,7 +60,7 @@ describe GeneralController, "when searching" do it "should find incoming message and public body (in that order) when searching for 'geraldine quango', newest first" do ActsAsXapian.update_index - get :search, :query => 'geraldine quango', :sortby => 'newest' + get :search, :combined => ['geraldine quango','newest'] response.should render_template('search') assigns[:search_hits].should == 2 diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 05e53b1f4..4855a88c2 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -23,7 +23,7 @@ describe RequestController, "when listing all requests" do # reverse-chronological order assigns[:search_results].size.should == 2 assigns[:search_results][0][:model].should == info_request_events(:silly_outgoing_message_event) - assigns[:search_results][1][:model].should == info_request_events(:useless_incoming_message_event) + assigns[:search_results][1][:model].should == info_request_events(:useless_outgoing_message_event) end end |