diff options
Diffstat (limited to 'spec/models')
-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 + + + |