aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/general_controller_spec.rb72
-rw-r--r--spec/fixtures/info_requests.yml2
-rw-r--r--spec/rcov.opts2
-rw-r--r--spec/spec_helper.rb4
4 files changed, 66 insertions, 14 deletions
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|