From b9d7b5e15db08113161aea660ad76ee678c704c1 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 12 Dec 2012 16:05:47 +1100 Subject: Add more spec helper methods and update acts_as_xapian to make info_request model specs pass --- spec/support/xapian_index.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/support/xapian_index.rb (limited to 'spec/support/xapian_index.rb') diff --git a/spec/support/xapian_index.rb b/spec/support/xapian_index.rb new file mode 100644 index 000000000..21f6192ef --- /dev/null +++ b/spec/support/xapian_index.rb @@ -0,0 +1,21 @@ +# Rebuild the current 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 + ActsAsXapian.writable_db.close + end + parse_all_incoming_messages + # 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. + models = [PublicBody, User, InfoRequestEvent] + ActsAsXapian.rebuild_index(models, verbose=false, terms, values, texts, safe_rebuild=false) +end + +def update_xapian_index + ActsAsXapian.update_index(flush_to_disk=false, verbose=false) +end -- cgit v1.2.3 From 50dd3ad01371e73912f8c2bf3a9fad70c8aa94fb Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Tue, 18 Dec 2012 18:31:33 +1100 Subject: Add some more xapian methods for models/xapian_spec.rb --- spec/support/xapian_index.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'spec/support/xapian_index.rb') diff --git a/spec/support/xapian_index.rb b/spec/support/xapian_index.rb index 21f6192ef..344c28ebb 100644 --- a/spec/support/xapian_index.rb +++ b/spec/support/xapian_index.rb @@ -19,3 +19,24 @@ end def update_xapian_index ActsAsXapian.update_index(flush_to_disk=false, verbose=false) end + +# Copy the xapian index created in create_fixtures_xapian_index to a temporary +# copy at the same level and point xapian at the copy +def get_fixtures_xapian_index() + # Create a base index for the fixtures if not already created + $existing_xapian_db ||= create_fixtures_xapian_index + # Store whatever the xapian db path is originally + $original_xapian_path ||= ActsAsXapian.db_path + path_array = $original_xapian_path.split(File::Separator) + path_array.pop + temp_path = File.join(path_array, 'test.temp') + FileUtils.remove_entry_secure(temp_path, force=true) + FileUtils.cp_r($original_xapian_path, temp_path) + ActsAsXapian.db_path = temp_path +end + +# Create a clean xapian index based on the fixture files and the raw_email data. +def create_fixtures_xapian_index + load_raw_emails_data + rebuild_xapian_index +end -- cgit v1.2.3