aboutsummaryrefslogtreecommitdiffstats
path: root/script/load-sample-data
diff options
context:
space:
mode:
Diffstat (limited to 'script/load-sample-data')
-rwxr-xr-xscript/load-sample-data24
1 files changed, 17 insertions, 7 deletions
diff --git a/script/load-sample-data b/script/load-sample-data
index 86e1af128..c9e5997f5 100755
--- a/script/load-sample-data
+++ b/script/load-sample-data
@@ -4,16 +4,26 @@
# the fact that the fixtures aren't aware of the fact that RawEmails
# have a filesystem representation of their contents
-LOC=`dirname "$0"`
+export LOC=`dirname "$0"`
+bundle exec rails runner /dev/stdin <<END
+require 'rspec/rails'
+require Rails.root.join("spec", "support", "load_file_fixtures")
+require Rails.root.join("spec", "support", "email_helpers")
-bundle exec rake --silent spec:db:fixtures:load
+RSpec.configure do |config|
+ config.fixture_path = Rails.root.join("spec","fixtures")
+end
-"$LOC/runner" /dev/stdin <<END
-env = ENV["RAILS_ENV"]
-require "spec/spec_helper.rb" # this sets RAILS_ENV to 'test'
-ENV["RAILS_ENV"] = env # so restore to what it was before
+# 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 = Rails.root.join("spec","fixtures").to_s
+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"
+echo "Loaded fixtures. You may now wish to run $LOC/update-xapian-index"