diff options
author | francis <francis> | 2009-04-21 22:48:41 +0000 |
---|---|---|
committer | francis <francis> | 2009-04-21 22:48:41 +0000 |
commit | b7904ef075bee6db7eab9302857723b2e8452d07 (patch) | |
tree | f215c3eb21ef9a3a00cee041ec789a1ae9ab74b9 /spec/models/xapian_spec.rb | |
parent | 84bfdecad8c7b26988b018363129e9dde57ab9a2 (diff) |
When user's URL changes, update Xapian index of requests made by them.
Diffstat (limited to 'spec/models/xapian_spec.rb')
-rw-r--r-- | spec/models/xapian_spec.rb | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index 0228713b2..114cae387 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -38,7 +38,7 @@ describe PublicBody, " when indexing public bodies with Xapian" do end describe " when indexing requests by body they are to" do - fixtures :public_bodies, :info_request_events + fixtures :public_bodies, :info_request_events, :info_requests before(:all) do rebuild_xapian_index @@ -75,6 +75,46 @@ describe " when indexing requests by body they are to" do end end +describe " when indexing requests by user they are from" do + fixtures :users, :info_request_events, :info_requests + + before(:all) do + rebuild_xapian_index + end + + it "should find requests from the user" do + xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 4 + end + + it "should update index correctly when URL name of user changes" do + verbose = false + + # initial search + xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", '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 + u= users(:bob_smith_user) + u.name = 'Robert Smith' + u.save! + u.url_name.should == 'robert_smith' + ActsAsXapian.update_index(true, verbose) # true = flush to disk + + # check we get results expected + 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 + models_found_after = xapian_object.results.map { |x| x[:model] } + + models_found_before.should == models_found_after + end +end + + + |