diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-01-29 19:07:42 +0000 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-01-29 19:07:42 +0000 |
commit | 2f82314374a644952019ac34b59dff10f6470004 (patch) | |
tree | 1a1e3f1ed0914d0917f5fb299703ae36d19c32c9 | |
parent | 11f45e188c59c8ad272a9fa611b387c54fcec80a (diff) |
Change order of requests on front page
Put the most-recently-answered first, rather than the
most-recently-reclassified. This is inspired by issue #370,
though it does not fix all the issues raised in that ticket.
(The wording is still outright misleading in some cases.)
-rw-r--r-- | app/controllers/general_controller.rb | 11 | ||||
-rw-r--r-- | spec/controllers/general_controller_spec.rb | 7 | ||||
-rw-r--r-- | spec/fixtures/info_request_events.yml | 4 | ||||
-rw-r--r-- | spec/fixtures/info_requests.yml | 2 | ||||
-rw-r--r-- | spec/fixtures/raw_emails.yml | 6 |
5 files changed, 18 insertions, 12 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 8ac41b05a..82b1b8629 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -45,20 +45,21 @@ class GeneralController < ApplicationController :joins => :translations) end end - # Get some successful requests # + # Get some successful requests begin query = 'variety:response (status:successful OR status:partially_successful)' - # query = 'variety:response' # XXX debug - sortby = "described" + sortby = "newest" max_count = 5 xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_title_collapse', max_count) @request_events = xapian_object.results.map { |r| r[:model] } - @request_events = @request_events.sort_by { |e| e.described_at }.reverse + + # If there are not yet enough successful requests, fill out the list with + # other requests if @request_events.count < max_count query = 'variety:sent' xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_title_collapse', max_count-@request_events.count) more_events = xapian_object.results.map { |r| r[:model] } - @request_events += more_events.sort_by { |e| e.described_at }.reverse + @request_events += more_events end rescue @request_events = [] diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 00239c14e..6c9f8b88d 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -116,8 +116,13 @@ describe GeneralController, "when searching" do end it 'should list the newest successful request first' do - # Make sure the newest is listed first even if an older one has an even newer comment: + # Make sure the newest is listed first even if an older one + # has a newer comment or was reclassified more recently: # https://github.com/sebbacon/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) end diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml index 3fdeb16e9..c72ef60c8 100644 --- a/spec/fixtures/info_request_events.yml +++ b/spec/fixtures/info_request_events.yml @@ -60,14 +60,14 @@ boring_outgoing_message_event: created_at: 2006-01-12 01:56:58.586598 described_state: waiting_response calculated_state: waiting_response -useful_incoming_message_event: +useful_incoming_message_event: id: 906 params_yaml: "--- \n\ :incoming_message_id: 2\n" incoming_message_id: 2 info_request_id: 105 event_type: response - created_at: 2007-11-13 18:09:20.042061 + created_at: 2007-11-13 18:00:20 described_state: successful calculated_state: successful diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml index 89c53e9f3..69f51a9e4 100644 --- a/spec/fixtures/info_requests.yml +++ b/spec/fixtures/info_requests.yml @@ -45,7 +45,7 @@ boring_request: another_boring_request: id: 106 title: The cost of boring - url_title: the_cost_of_boring_2 + url_title: the_cost_of_boring_two # Not _2, because we want to avoid the search collapsing these two created_at: 2006-01-12 01:56:58.586598 updated_at: 2007-11-13 18:09:20.042061 public_body_id: 5 diff --git a/spec/fixtures/raw_emails.yml b/spec/fixtures/raw_emails.yml index 6c5b6a6bb..d2c591812 100644 --- a/spec/fixtures/raw_emails.yml +++ b/spec/fixtures/raw_emails.yml @@ -4,11 +4,11 @@ # of the search functions, so if you use either of these words # in the email text then some tests will have to be updated. -useless_raw_email: +useless_raw_email: id: 1 -useful_raw_email: +useful_raw_email: id: 2 -another_useful_raw_email: +another_useful_raw_email: id: 3 |