diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-11-12 15:06:46 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-11-12 15:06:46 +0000 |
commit | a1ca0f9123a3aea843ba35508a97d5a4fd5cb0db (patch) | |
tree | b9d3c1390f6b9c8b201e47507f26829b239f2773 /spec/controllers/general_controller_spec.rb | |
parent | 8271b2c664f04d1b68a8b4d4fdb801f5c6b00b8c (diff) | |
parent | c96b27c301023a6a1f50c12f0c387205b0255836 (diff) |
Merge remote-tracking branch 'origin/release/0.6.8'0.6.8
Conflicts:
locale/cs/app.po
locale/sl/app.po
locale/sq/app.po
locale/tr/app.po
locale/uk/app.po
Diffstat (limited to 'spec/controllers/general_controller_spec.rb')
-rw-r--r-- | spec/controllers/general_controller_spec.rb | 136 |
1 files changed, 91 insertions, 45 deletions
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index de8dd8422..935f8eab6 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -17,12 +17,38 @@ describe GeneralController, "when trying to show the blog" do end end -describe GeneralController, "when searching" do +describe GeneralController, 'when getting the blog feed' do + + it 'should add a lang param correctly to a url with no querystring' do + Configuration.stub!(:blog_feed).and_return("http://blog.example.com") + get :blog + assigns[:feed_url].should == "http://blog.example.com?lang=en" + end + + it 'should add a lang param correctly to a url with an existing querystring' do + Configuration.stub!(:blog_feed).and_return("http://blog.example.com?alt=rss") + get :blog + assigns[:feed_url].should == "http://blog.example.com?alt=rss&lang=en" + end + +end + +describe GeneralController, "when showing the frontpage" do + integrate_views - before(:each) do - load_raw_emails_data - rebuild_xapian_index + before do + public_body = mock_model(PublicBody, :name => "Example Public Body", + :url_name => 'example_public_body') + info_request = mock_model(InfoRequest, :public_body => public_body, + :title => 'Example Request', + :url_title => 'example_request') + info_request_event = mock_model(InfoRequestEvent, :created_at => Time.now, + :info_request => info_request, + :described_at => Time.now, + :search_text_main => 'example text') + xapian_result = mock('xapian result', :results => [{:model => info_request_event}]) + controller.stub!(:perform_search).and_return(xapian_result) end it "should render the front page successfully" do @@ -71,11 +97,6 @@ describe GeneralController, "when searching" do response.should be_success 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', :combined => "mouse", :view => "all") # URL /search/:query/all - end - describe "when using different locale settings" do home_link_regex = /href=".*\/en\// it "should generate URLs with a locale prepended when there's more than one locale set" do @@ -117,23 +138,41 @@ describe GeneralController, "when searching" do I18n.available_locales = old_i18n_available_locales end end +end +describe GeneralController, "when showing the front page with fixture data" do describe 'when constructing the list of recent requests' do + before(:each) do - load_raw_emails_data - rebuild_xapian_index + rebuild_xapian_index end - it 'should list the newest successful request first' do - # Make sure the newest is listed first even if an older one - # has a newer comment or was reclassified more recently: - # https://github.com/mysociety/alaveteli/issues/370 - # - # This is a deliberate behaviour change, in that the - # previous behaviour (showing more-recently-reclassified - # requests first) was intentional. - get :frontpage - assigns[:request_events].first.info_request.should == info_requests(:another_boring_request) + describe 'when there are fewer than five successful requests' do + + it 'should list the most recently sent and successful requests by the creation date of the + request event' do + # Make sure the newest response is listed first even if a request + # with an older response has a newer comment or was reclassified more recently: + # https://github.com/mysociety/alaveteli/issues/370 + # + # This is a deliberate behaviour change, in that the + # previous behaviour (showing more-recently-reclassified + # requests first) was intentional. + get :frontpage + + request_events = assigns[:request_events] + previous = nil + request_events.each do |event| + if previous + previous.created_at.should be >= event.created_at + end + ['sent', 'response'].include?(event.event_type).should be_true + if event.event_type == 'response' + ['successful', 'partially_successful'].include?(event.calculated_state).should be_true + end + previous = event + end + end end it 'should coalesce duplicate requests' do @@ -142,37 +181,44 @@ describe GeneralController, "when searching" do end end - describe 'when using xapian search' do +end - # rebuild xapian index after fixtures loaded - before(:each) do - load_raw_emails_data - rebuild_xapian_index - end +describe GeneralController, 'when using xapian search' do - 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) + integrate_views - assigns[:xapian_requests].words_to_highlight == ["fancy", "dog"] - end + # rebuild xapian index after fixtures loaded + before(:each) do + load_raw_emails_data + rebuild_xapian_index + 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') + 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', :combined => "mouse", :view => "all") # URL /search/:query/all + 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 - 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) + 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_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].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 it "should filter results based on end of URL being 'all'" do |