diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/info_request_event_spec.rb | 20 | ||||
-rw-r--r-- | spec/models/xapian_spec.rb | 63 | ||||
-rw-r--r-- | spec/spec_helper.rb | 12 |
3 files changed, 92 insertions, 3 deletions
diff --git a/spec/models/info_request_event_spec.rb b/spec/models/info_request_event_spec.rb index 666f5cb1a..055965c23 100644 --- a/spec/models/info_request_event_spec.rb +++ b/spec/models/info_request_event_spec.rb @@ -50,5 +50,25 @@ describe InfoRequestEvent do end end + + describe "doing search/index stuff" do + fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things + + it 'should get search text for outgoing messages' do + event = info_request_events(:useless_outgoing_message_event) + message = outgoing_messages(:useless_outgoing_message).body + event.search_text_main.should == message + "\n\n" + end + + it 'should get search text for incoming messages' do + event = info_request_events(:useless_incoming_message_event) + event.search_text_main.strip.should == "No way! I'm not going to tell you that in a month of Thursdays.\n\nThe Geraldine Quango" + end + + + end + + + end diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index 932966dfb..cf9ea5fbd 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -12,9 +12,10 @@ describe User, " when indexing users with Xapian" do end it "should search by 'about me' text" do + rebuild_xapian_index user = users(:bob_smith_user) - # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) + # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) xapian_object = InfoRequest.full_search([User], "stuff", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 xapian_object.results[0][:model].should == user @@ -332,6 +333,66 @@ describe PublicBody, " when indexing authorities by tag" do end end +describe PublicBody, " when only indexing selected things on a rebuild" do + 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) + end + + it "should only index what we ask it to" do + rebuild_xapian_index + body = public_bodies(:geraldine_public_body) + body.tag_string = 'mice:3' + body.name = 'frobzn' + body.save! + # only reindex 'variety' term + dropfirst = true + terms = "V" + values = false + texts = false + rebuild_xapian_index(terms, values, texts, dropfirst) + xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 2 + # only reindex 'tag' and text + dropfirst = true + terms = "U" + values = false + texts = true + rebuild_xapian_index(terms, values, texts, dropfirst) + xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + # only reindex 'variety' term, but keeping the existing data in-place + dropfirst = false + terms = "V" + texts = false + rebuild_xapian_index(terms, values, texts, dropfirst) + xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 2 + # only reindex 'variety' term, blowing away existing data + dropfirst = true + rebuild_xapian_index(terms, values, texts, dropfirst) + xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 2 + end +end + + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ecb67a3b4..e5a42f1a9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -77,12 +77,20 @@ def load_file_fixture(file_name) return content end -def rebuild_xapian_index +def rebuild_xapian_index(terms = true, values = true, texts = true, dropfirst = true) + if dropfirst + begin + ActsAsXapian.readable_init + FileUtils.rm_r(ActsAsXapian.db_path) + rescue RuntimeError + end + ActsAsXapian.writable_init + end verbose = false # safe_rebuild=true, which involves forking to avoid memory leaks, doesn't work well with rspec. # unsafe is significantly faster, and we can afford possible memory leaks while testing. safe_rebuild = false - ActsAsXapian.rebuild_index(["PublicBody", "User", "InfoRequestEvent"].map{|m| m.constantize}, verbose, safe_rebuild) + ActsAsXapian.rebuild_index(["PublicBody", "User", "InfoRequestEvent"].map{|m| m.constantize}, verbose, terms, values, texts, safe_rebuild) end def update_xapian_index |