diff options
-rw-r--r-- | spec/spec_helper.rb | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e6d81540b..d4dad591d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,7 +23,6 @@ FakeWeb.register_uri(:purge, %r|varnish.localdomain|, :body => "OK") # Use test-specific translations FastGettext.add_text_domain 'app', :path => File.join(File.dirname(__FILE__), 'fixtures', 'locale'), :type => :po FastGettext.default_text_domain = 'app' - Spec::Runner.configure do |config| # If you're not using ActiveRecord you should remove these # lines, delete config/database.yml and disable :active_record @@ -47,6 +46,7 @@ Spec::Runner.configure do |config| :holidays, :track_things_sent_emails + # == Fixtures # # You can declare fixtures for each example_group like this: @@ -99,6 +99,19 @@ def load_file_fixture(file_name) return content end +def parse_all_incoming_messages + IncomingMessage.find(:all).each{ |x| x.parse_raw_email! } +end + +def load_raw_emails_data + raw_emails_yml = File.join(Spec::Runner.configuration.fixture_path, "raw_emails.yml") + for raw_email_id in YAML::load_file(raw_emails_yml).map{|k,v| v["id"]} do + raw_email = RawEmail.find(raw_email_id) + raw_email.data = load_file_fixture("raw_emails/%d.email" % [raw_email_id]) + end +end + +# Rebuild the current xapian index def rebuild_xapian_index(terms = true, values = true, texts = true, dropfirst = true) if dropfirst begin @@ -110,16 +123,35 @@ def rebuild_xapian_index(terms = true, values = true, texts = true, dropfirst = ActsAsXapian.writable_db.close end parse_all_incoming_messages - 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, terms, values, texts, safe_rebuild) + models = [PublicBody, User, InfoRequestEvent] + ActsAsXapian.rebuild_index(models, verbose=false, terms, values, texts, safe_rebuild=false) +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 def update_xapian_index - verbose = false - ActsAsXapian.update_index(flush_to_disk=false, verbose) + 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 # Validate an entire HTML page @@ -200,22 +232,10 @@ def safe_mock_model(model, args = {}) mock end -def load_raw_emails_data - raw_emails_yml = File.join(Spec::Runner.configuration.fixture_path, "raw_emails.yml") - for raw_email_id in YAML::load_file(raw_emails_yml).map{|k,v| v["id"]} do - raw_email = RawEmail.find(raw_email_id) - raw_email.data = load_file_fixture("raw_emails/%d.email" % [raw_email_id]) - end -end - def get_fixture_mail(filename) MailHandler.mail_from_raw_email(load_file_fixture(filename)) end -def parse_all_incoming_messages - IncomingMessage.find(:all).each{|x| x.parse_raw_email!} -end - def load_test_categories PublicBodyCategories.add(:en, [ "Local and regional", |