diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2012-01-13 13:28:23 +0000 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2012-01-13 13:28:23 +0000 |
commit | 07068037e9b0ac8de80a9eae36a323689c83139d (patch) | |
tree | fc910d2304471a54ff1f08ec5ba58fcc6c56e4b6 | |
parent | 08dd56bac73ce83fcb12e4776b32c4e0ce75545a (diff) |
Fix bug introduced in cec2c545e0a10e0641c4ee67839c88d872b394b8, related to issue #343.
-rw-r--r-- | app/controllers/application_controller.rb | 2 | ||||
-rw-r--r-- | spec/controllers/admin_public_body_controller_spec.rb | 15 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 7 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 22 | ||||
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/fixtures/info_request_events.yml | 9 | ||||
-rw-r--r-- | spec/fixtures/info_requests.yml | 11 | ||||
-rw-r--r-- | spec/fixtures/outgoing_messages.yml | 12 | ||||
-rw-r--r-- | spec/models/xapian_spec.rb | 19 |
9 files changed, 78 insertions, 21 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f3406ee8a..2633aca4d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -435,7 +435,7 @@ class ApplicationController < ActionController::Base params[:latest_status] = [params[:latest_status]] end if params[:latest_status].include?("recent") || params[:latest_status].include?("all") - query += " variety:sent OR variety:followup_sent OR variety:response OR variety:comment" + query += " (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)" end if params[:latest_status].include? "successful" statuses << ['latest_status:successful', 'latest_status:partially_successful'] diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb index 22af3df80..97636023a 100644 --- a/spec/controllers/admin_public_body_controller_spec.rb +++ b/spec/controllers/admin_public_body_controller_spec.rb @@ -44,6 +44,9 @@ describe AdminPublicBodyController, "when administering public bodies" do it "destroys a public body" do PublicBody.count.should == 2 + info_request_events(:badger_outgoing_message_event).destroy + outgoing_messages(:badger_outgoing_message).destroy + info_requests(:badger_request).destroy post :destroy, { :id => 3 } PublicBody.count.should == 1 end @@ -74,6 +77,9 @@ describe AdminPublicBodyController, "when administering public bodies and paying config['ADMIN_PASSWORD'] = '' @request.env["HTTP_AUTHORIZATION"] = "" PublicBody.count.should == 2 + info_request_events(:badger_outgoing_message_event).destroy + outgoing_messages(:badger_outgoing_message).destroy + info_requests(:badger_request).destroy post :destroy, { :id => 3 } PublicBody.count.should == 1 session[:using_admin].should == 1 @@ -84,6 +90,9 @@ describe AdminPublicBodyController, "when administering public bodies and paying config['ADMIN_PASSWORD'] = 'fuz' @request.env["HTTP_AUTHORIZATION"] = "" PublicBody.count.should == 2 + info_request_events(:badger_outgoing_message_event).destroy + outgoing_messages(:badger_outgoing_message).destroy + info_requests(:badger_request).destroy post :destroy, { :id => 3 } PublicBody.count.should == 1 session[:using_admin].should == 1 @@ -95,6 +104,9 @@ describe AdminPublicBodyController, "when administering public bodies and paying @request.env["HTTP_AUTHORIZATION"] = "" PublicBody.count.should == 2 basic_auth_login(@request, "baduser", "badpassword") + info_request_events(:badger_outgoing_message_event).destroy + outgoing_messages(:badger_outgoing_message).destroy + info_requests(:badger_request).destroy post :destroy, { :id => 3 } response.code.should == "401" PublicBody.count.should == 2 @@ -168,6 +180,9 @@ describe AdminPublicBodyController, "when administering public bodies with i18n" it "destroy a public body" do PublicBody.count.should == 2 + info_request_events(:badger_outgoing_message_event).destroy + outgoing_messages(:badger_outgoing_message).destroy + info_requests(:badger_request).destroy post :destroy, { :id => 3 } PublicBody.count.should == 1 end diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index 3996bd520..a563b92ad 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -6,6 +6,11 @@ describe PublicBodyController, "when showing a body" do integrate_views fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things + before(:each) do + load_raw_emails_data(raw_emails) + rebuild_xapian_index + end + it "should be successful" do get :show, :url_name => "dfh", :view => 'all' response.should be_success @@ -26,6 +31,8 @@ describe PublicBodyController, "when showing a body" do assigns[:xapian_requests].results.count.should == 2 get :show, :url_name => "tgq", :view => 'successful' assigns[:xapian_requests].results.count.should == 0 + get :show, :url_name => "dfh", :view => 'all' + assigns[:xapian_requests].results.count.should == 1 end it "should assign the body using different locale from that used for url_name" do diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 52fea03b5..40cb168f4 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -23,9 +23,9 @@ describe RequestController, "when listing recent requests" do it "should filter requests" do get :list, :view => 'all' - assigns[:list_results].size.should == 2 + assigns[:list_results].size.should == 3 # default sort order is the request with the most recently created event first - assigns[:list_results][0].info_request.id.should == 101 + assigns[:list_results][0].info_request.id.should == 104 get :list, :view => 'successful' assigns[:list_results].size.should == 0 end @@ -34,9 +34,9 @@ describe RequestController, "when listing recent requests" do get :list, :view => 'all', :request_date_before => '13/10/2007' assigns[:list_results].size.should == 1 get :list, :view => 'all', :request_date_after => '13/10/2007' - assigns[:list_results].size.should == 2 + assigns[:list_results].size.should == 3 get :list, :view => 'all', :request_date_after => '13/10/2007', :request_date_before => '01/11/2007' - assigns[:list_results].size.should == 2 + assigns[:list_results].size.should == 1 end it "should list internal_review requests as unresolved ones" do @@ -56,7 +56,7 @@ describe RequestController, "when listing recent requests" do :matches_estimated => 103) InfoRequest.should_receive(:full_search). - with([InfoRequestEvent]," variety:sent OR variety:followup_sent OR variety:response OR variety:comment", "created_at", anything, anything, anything, anything). + with([InfoRequestEvent]," (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)", "created_at", anything, anything, anything, anything). and_return(xap_results) get :list, :view => 'recent' assigns[:list_results].size.should == 25 @@ -1124,8 +1124,8 @@ describe RequestController, "sending overdue request alerts" do RequestMailer.alert_overdue_requests deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - mail = deliveries[0] + deliveries.size.should == 2 + mail = deliveries[1] mail.body.should =~ /promptly, as normally/ mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email @@ -1152,8 +1152,8 @@ describe RequestController, "sending overdue request alerts" do RequestMailer.alert_overdue_requests deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - mail = deliveries[0] + deliveries.size.should == 2 + mail = deliveries[1] mail.body.should =~ /promptly, as normally/ mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email end @@ -1177,8 +1177,8 @@ describe RequestController, "sending overdue request alerts" do RequestMailer.alert_overdue_requests deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - mail = deliveries[0] + deliveries.size.should == 2 + mail = deliveries[1] mail.body.should =~ /required by law/ mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 30ad61706..0cf574aa9 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -45,7 +45,7 @@ describe UserController, "when showing a user" do it "should search the user's contributions" do get :show, :url_name => "bob_smith" - assigns[:xapian_requests].results.count.should == 2 + assigns[:xapian_requests].results.count.should == 3 get :show, :url_name => "bob_smith", :user_query => "money" assigns[:xapian_requests].results.count.should == 1 end diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml index 5e3c13083..9c6aa393d 100644 --- a/spec/fixtures/info_request_events.yml +++ b/spec/fixtures/info_request_events.yml @@ -38,4 +38,13 @@ silly_comment_event: event_type: comment outgoing_message_id: created_at: 2008-08-12 23:05:12.500942 +badger_outgoing_message_event: + params_yaml: "--- \n\ + :outgoing_message_id: 3\n" + id: 904 + info_request_id: 104 + event_type: sent + created_at: 2011-10-12 01:56:58.586598 + described_state: + outgoing_message_id: 3 diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml index c1e3c1910..7b7e55ba6 100644 --- a/spec/fixtures/info_requests.yml +++ b/spec/fixtures/info_requests.yml @@ -20,3 +20,14 @@ naughty_chicken_request: described_state: waiting_response awaiting_description: false idhash: e8d18c84 +badger_request: + id: 104 + title: Are you really a badger? + url_title: are_you_really_a_badger + created_at: 2011-10-13 18:15:57 + updated_at: 2011-10-13 18:15:57 + public_body_id: 3 + user_id: 1 + described_state: waiting_response + awaiting_description: false + idhash: e8d18c84 diff --git a/spec/fixtures/outgoing_messages.yml b/spec/fixtures/outgoing_messages.yml index b89492aa5..0cebdd5c5 100644 --- a/spec/fixtures/outgoing_messages.yml +++ b/spec/fixtures/outgoing_messages.yml @@ -33,4 +33,16 @@ silly_outgoing_message: last_sent_at: 2007-10-14 10:41:12.686264 created_at: 2007-10-14 01:56:58.586598 what_doing: normal_sort +badger_outgoing_message: + id: 3 + info_request_id: 104 + message_type: initial_request + status: sent + updated_at: 2011-10-14 01:56:58.586598 + body: "Is it true that you are really a badger, in fact?" + last_sent_at: 2011-10-14 10:41:12.686264 + created_at: 2011-10-14 01:56:58.586598 + what_doing: normal_sort + + diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index ec11c944b..ebd6b1890 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -63,6 +63,9 @@ describe PublicBody, " when indexing public bodies with Xapian" do xapian_object.results.size.should == 1 xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body) + info_request_events(:badger_outgoing_message_event).destroy + outgoing_messages(:badger_outgoing_message).destroy + info_requests(:badger_request).destroy public_bodies(:humpadink_public_body).destroy update_xapian_index @@ -141,16 +144,16 @@ describe User, " when indexing requests by user they are from" do it "should find requests from the user" do rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1) - xapian_object.results.size.should == 4 + xapian_object.results.size.should == 5 end it "should find just the sent message events from a particular user" do rebuild_xapian_index # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith variety:sent", 'created_at', true, nil, 100, 1) - xapian_object.results.size.should == 2 - xapian_object.results[1][:model].should == info_request_events(:useless_outgoing_message_event) - xapian_object.results[0][:model].should == info_request_events(:silly_outgoing_message_event) + xapian_object.results.size.should == 3 + xapian_object.results[2][:model].should == info_request_events(:useless_outgoing_message_event) + xapian_object.results[1][:model].should == info_request_events(:silly_outgoing_message_event) end it "should not find it when one of the request's users is changed" do @@ -164,8 +167,8 @@ describe User, " when indexing requests by user they are from" do # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, 'request_collapse', 100, 1) - xapian_object.results.size.should == 1 - xapian_object.results[0][:model].should == info_request_events(:silly_comment_event) + xapian_object.results.size.should == 2 + xapian_object.results[1][:model].should == info_request_events(:silly_comment_event) end it "should not get confused searching for requests when one user has a name which has same stem as another" do @@ -198,7 +201,7 @@ describe User, " when indexing requests by user they are from" do # initial search rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1) - xapian_object.results.size.should == 4 + xapian_object.results.size.should == 5 models_found_before = xapian_object.results.map { |x| x[:model] } # change the URL name of the body @@ -212,7 +215,7 @@ describe User, " when indexing requests by user they are from" do xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 0 xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:robert_smith", 'created_at', true, nil, 100, 1) - xapian_object.results.size.should == 4 + xapian_object.results.size.should == 5 models_found_after = xapian_object.results.map { |x| x[:model] } models_found_before.should == models_found_after |