aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/xapian_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/xapian_spec.rb')
-rw-r--r--spec/models/xapian_spec.rb44
1 files changed, 42 insertions, 2 deletions
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index d3e88eedf..0228713b2 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../spec_helper'
-describe User, " when indexing with Xapian" do
+describe User, " when indexing users with Xapian" do
fixtures :users
before(:all) do
@@ -16,7 +16,7 @@ describe User, " when indexing with Xapian" do
end
-describe PublicBody, " when indexing with Xapian" do
+describe PublicBody, " when indexing public bodies with Xapian" do
fixtures :public_bodies
before(:all) do
@@ -37,4 +37,44 @@ describe PublicBody, " when indexing with Xapian" do
end
+describe " when indexing requests by body they are to" do
+ fixtures :public_bodies, :info_request_events
+
+ before(:all) do
+ rebuild_xapian_index
+ end
+
+ it "should find requests to the body" do
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 4
+ end
+
+ it "should update index correctly when URL name of body changes" do
+ verbose = false
+
+ # initial search
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 4
+ models_found_before = xapian_object.results.map { |x| x[:model] }
+
+ # change the URL name of the body
+ body = public_bodies(:geraldine_public_body)
+ body.short_name = 'GQ'
+ body.save!
+ body.url_name.should == 'gq'
+ ActsAsXapian.update_index(true, verbose) # true = flush to disk
+
+ # check we get results expected
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 0
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:gq", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 4
+ models_found_after = xapian_object.results.map { |x| x[:model] }
+
+ models_found_before.should == models_found_after
+ end
+end
+
+
+