aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenare Degan <henare.degan@gmail.com>2013-02-19 11:30:02 +1100
committerHenare Degan <henare.degan@gmail.com>2013-02-19 11:30:02 +1100
commit5eceb8870c2dc4c1bc2567ed033e30a81e5f5c43 (patch)
treea6236b66e4cbe748141763dfd0d3cae3edcaab87
parenta0f250204a376ce97a187cf8a9b2cb0b8c628298 (diff)
Upgrade load-sample-data to work with Rails 3
-rwxr-xr-xscript/load-sample-data18
1 files changed, 12 insertions, 6 deletions
diff --git a/script/load-sample-data b/script/load-sample-data
index 86e1af128..06fc9b579 100755
--- a/script/load-sample-data
+++ b/script/load-sample-data
@@ -4,14 +4,20 @@
# 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 rake --silent spec:db:fixtures:load
+bundle exec rails runner /dev/stdin <<END
+require "spec/spec_helper.rb"
-"$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/5ecd14c5f16533d09c01007bf5d70f70a59c30e3/activerecord/lib/active_record/railties/databases.rake#L319
+fixtures_dir = "#{ENV['LOC']}/../spec/fixtures"
+
+Dir["#{fixtures_dir}/**/*.yml"].each do |fixture_file|
+ Fixtures.create_fixtures(fixtures_dir, fixture_file[(fixtures_dir.size + 1)..-5])
+end
load_raw_emails_data
END