diff options
author | francis <francis> | 2008-03-19 03:05:20 +0000 |
---|---|---|
committer | francis <francis> | 2008-03-19 03:05:20 +0000 |
commit | 992e97b3bd16190d75a0d08718eadd0ed9fad3f3 (patch) | |
tree | 656a1b9638962527b50bd5af964ca18cf6e7b609 | |
parent | c2d387322e1945ff0d456ddcc027bb0f8a237bb3 (diff) |
Test code for search and the front page.
-rw-r--r-- | app/controllers/general_controller.rb | 21 | ||||
-rw-r--r-- | spec/controllers/general_controller_spec.rb | 72 | ||||
-rw-r--r-- | spec/fixtures/info_requests.yml | 2 | ||||
-rw-r--r-- | spec/rcov.opts | 2 | ||||
-rw-r--r-- | spec/spec_helper.rb | 4 | ||||
-rw-r--r-- | todo.txt | 8 |
6 files changed, 80 insertions, 29 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 0920b2eb6..829ac829e 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.9 2008-03-13 11:29:46 francis Exp $ +# $Id: general_controller.rb,v 1.10 2008-03-19 03:05:25 francis Exp $ class GeneralController < ApplicationController @@ -63,12 +63,8 @@ class GeneralController < ApplicationController raise "Unknown sort order " + @sortby end - # Used for simpler word highlighting view code for users and public bodies - query_nopunc = @query.gsub(/[^a-z0-9]/i, " ") - query_nopunc = query_nopunc.gsub(/\s+/, " ") - @highlight_words = query_nopunc.split(" ") - - @solr_object = InfoRequest.multi_solr_search(@query, :models => [ OutgoingMessage, IncomingMessage, PublicBody, User ], + # Peform the search + solr_object = InfoRequest.multi_solr_search(@query, :models => [ OutgoingMessage, IncomingMessage, PublicBody, User ], :limit => @per_page, :offset => (@page - 1) * @per_page, :highlight => { :prefix => '<span class="highlight">', @@ -81,11 +77,16 @@ class GeneralController < ApplicationController "name" # User ]}, :order => order ) - @search_results = @solr_object.results - @search_hits = @solr_object.total_hits + @search_results = solr_object.results + @search_hits = solr_object.total_hits + + # Calculate simple word highlighting view code for users and public bodies + query_nopunc = @query.gsub(/[^a-z0-9]/i, " ") + query_nopunc = query_nopunc.gsub(/\s+/, " ") + @highlight_words = query_nopunc.split(" ") # Extract better Solr highlighting for info request related results - @highlighting = @solr_object.highlights + @highlighting = solr_object.highlights end def fai_test diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index ab2a0eb60..52350ec80 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -1,26 +1,74 @@ require File.dirname(__FILE__) + '/../spec_helper' -describe GeneralController, "when showing the front page" do +describe GeneralController, "when searching" do integrate_views - fixtures :users + fixtures :users, :outgoing_messages, :incoming_messages, :info_requests, :info_request_events, :public_bodies - it "should be successful" do + it "should render the front page successfully" do get :frontpage response.should be_success end - it "should have sign in/up link when not signed in" do - get :frontpage - response.should have_tag('a', "Sign in or sign up") + it "when doing public body AJAX search should return list of matches" do + get :auto_complete_for_public_body_query, :public_body => { :query => "humpa" } + assigns[:public_bodies] = [ public_bodies(:humpadink_public_body) ] + response.should render_template('_public_body_query') end - it "should have sign out link when signed in" do - session[:user_id] = users(:bob_smith_user).id - get :frontpage - response.should have_tag('a', "Sign out") + it "when front page public body search has exact name match, should redirect to public body page" do + post :frontpage, :public_body => { :query => public_bodies(:geraldine_public_body).name } + response.should redirect_to(:controller => 'body', :action => 'show', :url_name => public_bodies(:geraldine_public_body).url_name) end - -end + 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 + end + + it "should find info request when searching for '\"fancy dog\"'" do + InfoRequest.update_solr_index + get :search, :query => '"fancy dog"' + response.should render_template('search') + + assigns[:search_hits].should == 1 + assigns[:search_results].should == [ info_requests(:fancy_dog_request) ] + + assigns[:highlight_words].should == ["fancy", "dog"] + assigns[:highlighting]["InfoRequest"][101]["initial"][0].should include('Why do you have such a <span class="highlight">fancy</span> <span class="highlight">dog</span>?') + end + + it "should show help when searching for nothing" do + get :search_redirect, :query => nil + response.should render_template('search') + assigns[:search_hits].should be_nil + assigns[:query].should be_nil + end + + it "should find public body and incoming message (in that order) when searching for 'geraldine quango'" do + InfoRequest.update_solr_index + PublicBody.rebuild_solr_index + User.rebuild_solr_index + get :search, :query => 'geraldine quango' + response.should render_template('search') + + assigns[:search_hits].should == 2 + assigns[:search_results].should == [ public_bodies(:geraldine_public_body), incoming_messages(:useless_incoming_message) ] + end + + it "should find incoming message and public body (in that order) when searching for 'geraldine quango', newest first" do + InfoRequest.update_solr_index + PublicBody.rebuild_solr_index + User.rebuild_solr_index + + get :search, :query => 'geraldine quango', :sortby => 'newest' + response.should render_template('search') + + assigns[:search_hits].should == 2 + assigns[:search_results].should == [ incoming_messages(:useless_incoming_message), public_bodies(:geraldine_public_body) ] + end + + + # assigns[:display_user].should == users(:bob_smith_user) +end diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml index a849542b8..dd296410b 100644 --- a/spec/fixtures/info_requests.yml +++ b/spec/fixtures/info_requests.yml @@ -8,6 +8,7 @@ fancy_dog_request: user_id: 1 described_state: waiting_response awaiting_description: true + solr_up_to_date: false naughty_chicken_request: id: 103 title: How much public money is wasted on breeding naughty chickens? @@ -18,5 +19,6 @@ naughty_chicken_request: user_id: 1 described_state: waiting_response awaiting_description: false + solr_up_to_date: false diff --git a/spec/rcov.opts b/spec/rcov.opts new file mode 100644 index 000000000..baf694c9c --- /dev/null +++ b/spec/rcov.opts @@ -0,0 +1,2 @@ +--exclude "spec/*,gems/*" +--rails
\ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 43a67d304..8945bc7b2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,8 +44,8 @@ if $tempfilecount.nil? # Call original process function self.original_process(action, parameters, session, flash) - # And then if HTML, validate it - if @response.content_type == "text/html" and @response.response_code != 302 + # And then if HTML, not a redirect (302), and not a partial template (something/_something, such as in AJAX partial results) + if @response.content_type == "text/html" and @response.response_code != 302 and not @response.rendered_file.include?("/_") $tempfilecount = $tempfilecount + 1 tempfilename = File.join(Dir::tmpdir, "railshtmlvalidate."+$$.to_s+"."+$tempfilecount.to_s+".html") File.open(tempfilename, "w+") do |f| @@ -27,7 +27,9 @@ BAILII - relationship with law courts, robots.txt ? Next ==== -Need something to mark contact as bad, e.g. for university of huddersfield +Send email to remind people to classify +Send email to tell admins something isn't classified +Send email to remind people to clarify Add all new stuff to test code till it has reasonable coverage @@ -45,10 +47,6 @@ Tom's request to Parliament: Consider removing login links from notifications of new responses Consider password change code in relation to this -Send email to remind people to classify -Send email to tell admins something isn't classified -Send email to remind people to clarify - Now of course when ids go into requests/users for new ones it just adds an _ on end which is crap! Later |