aboutsummaryrefslogtreecommitdiffstats
path: root/script/load-sample-data
blob: e9151688623ecca96e3cd47119394d19d4f3c294 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

# This script loads spec fixtures, but also needs to do a hack around
# the fact that the fixtures aren't aware of the fact that RawEmails
# have a filesystem representation of their contents

export LOC=`dirname "$0"`

bundle exec rails runner /dev/stdin <<END
require 'rspec/rails'
require "#{ENV['LOC']}/../spec/support/load_file_fixtures.rb"
require "#{ENV['LOC']}/../spec/support/email_helpers.rb"

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
end

# HACK: Normally to load fixtures you'd run `rake db:fixtures:load` but since we
# have .csv files in the fixtures folder Rails tries to load those too. Therefore
# we've pinched some code to load the fixtures:
# https://github.com/rails/rails/blob/v3.1.11/activerecord/lib/active_record/railties/databases.rake#L311
fixtures_dir = "#{ENV['LOC']}/../spec/fixtures"

Dir["#{fixtures_dir}/**/*.yml"].each do |fixture_file|
  ActiveRecord::Fixtures.create_fixtures(fixtures_dir, fixture_file[(fixtures_dir.size + 1)..-5])
end

load_raw_emails_data
END

echo "Loaded fixtures. You may now wish to run $LOC/update-xapian-index"