diff options
-rw-r--r-- | app/models/public_body.rb | 11 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 11 |
2 files changed, 18 insertions, 4 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 3da901e83..54a17af38 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -25,7 +25,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.136 2009-03-22 09:03:18 tony Exp $ +# $Id: public_body.rb,v 1.137 2009-03-22 10:27:03 tony Exp $ require 'csv' require 'set' @@ -148,6 +148,15 @@ class PublicBody < ActiveRecord::Base return PublicBody.find(old.first.public_body_id) end + # Requests made from this body, via Xapian + def xapian_requests + begin + perform_search([InfoRequestEvent], 'requested_from:' + self.url_name, 'newest', 'request_collapse') + rescue + return nil + end + end + # Set the first letter, which is used for faster queries before_save(:set_first_letter) diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index bcce59471..38f27cc47 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -50,7 +50,7 @@ describe PublicBody, "when searching" do end describe PublicBody, " when indexing with Xapian" do - fixtures :public_bodies + fixtures :public_bodies, :info_request_events, :info_requests before(:all) do rebuild_xapian_index @@ -68,7 +68,12 @@ describe PublicBody, " when indexing with Xapian" do xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body) end -end - + it "should find requests made to it" do + @body = public_bodies(:humpadink_public_body) + xapian_requests = @body.xapian_requests + xapian_object.results.size.should == 2 + xapian_object.results[0][:model].should == public_bodies(:humpadink_public_body) + end +end |