diff options
-rw-r--r-- | spec/controllers/general_controller_spec.rb | 61 |
1 files changed, 37 insertions, 24 deletions
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 3cba0900c..9c9ab46f6 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -2,11 +2,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe GeneralController, "when searching" do integrate_views - fixtures :info_requests, :info_request_events, :public_bodies, :users, :raw_emails - - before(:all) do - rebuild_xapian_index - end + fixtures [ :info_requests, + :info_request_events, + :public_bodies, + :users, + :raw_emails, + :outgoing_messages, + :incoming_messages, + :comments ] it "should render the front page successfully" do get :frontpage @@ -17,16 +20,37 @@ describe GeneralController, "when searching" do post :search_redirect, :query => "mouse" # query hidden in POST parameters response.should redirect_to(:action => 'search', :combined => "mouse") # URL /search/:query end - - it "should find info request when searching for '\"fancy dog\"'" do - get :search, :combined => ['"fancy dog"'] - response.should render_template('search') - assigns[:xapian_requests].matches_estimated.should == 1 - assigns[:xapian_requests].results.size.should == 1 - assigns[:xapian_requests].results[0][:model].should == info_request_events(:useless_outgoing_message_event) + describe 'when using xapian search' do + + # rebuild xapian index after fixtures loaded + before(:all) do + rebuild_xapian_index + end + + it "should find info request when searching for '\"fancy dog\"'" do + get :search, :combined => ['"fancy dog"'] + response.should render_template('search') + assigns[:xapian_requests].matches_estimated.should == 1 + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].should == info_request_events(:useless_outgoing_message_event) + + assigns[:xapian_requests].words_to_highlight == ["fancy", "dog"] + end + + it "should find public body and incoming message when searching for 'geraldine quango'" do + get :search, :combined => ['geraldine quango'] + response.should render_template('search') + + assigns[:xapian_requests].matches_estimated.should == 1 + assigns[:xapian_requests].results.size.should == 1 + assigns[:xapian_requests].results[0][:model].should == info_request_events(:useless_incoming_message_event) + + assigns[:xapian_bodies].matches_estimated.should == 1 + assigns[:xapian_bodies].results.size.should == 1 + assigns[:xapian_bodies].results[0][:model].should == public_bodies(:geraldine_public_body) + end - assigns[:xapian_requests].words_to_highlight == ["fancy", "dog"] end it "should show help when searching for nothing" do @@ -36,17 +60,6 @@ describe GeneralController, "when searching" do assigns[:query].should be_nil end - it "should find public body and incoming message when searching for 'geraldine quango'" do - get :search, :combined => ['geraldine quango'] - response.should render_template('search') - - assigns[:xapian_requests].matches_estimated.should == 1 - assigns[:xapian_requests].results.size.should == 1 - assigns[:xapian_requests].results[0][:model].should == info_request_events(:useless_incoming_message_event) - assigns[:xapian_bodies].matches_estimated.should == 1 - assigns[:xapian_bodies].results.size.should == 1 - assigns[:xapian_bodies].results[0][:model].should == public_bodies(:geraldine_public_body) - end end |