From c99d1e5f5572f414ac246dd90d1b72f1bc548ce8 Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Fri, 7 Dec 2012 10:39:13 -0500 Subject: [PATCH] Can now seed via rake db:seed Only using fixtures for seeding, using factories for testing. -For some reason, module fixtures won't auto create dates, must include updated_at and created_at dates in fixture. --- db/seeds.rb | 10 +++++++++- test/fixtures/acts_as_loggable/bike_actions.yml | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index e605943..bcc1fe8 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,7 +5,15 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) +require 'active_record/fixtures' + +Dir.glob(File.join(Rails.root, 'test', 'fixtures', '**/*.{yml,csv}')).each do |fixture_file, something| + puts fixture_file + puts File.dirname(fixture_file) + ActiveRecord::Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*')) +end if Rails.env.development? - FactoryGirl.create(:user) + user = FactoryGirl.build(:user) + FactoryGirl.create(:user) if not User.find_by_email(user.email) end diff --git a/test/fixtures/acts_as_loggable/bike_actions.yml b/test/fixtures/acts_as_loggable/bike_actions.yml index bdfc531..c64121b 100644 --- a/test/fixtures/acts_as_loggable/bike_actions.yml +++ b/test/fixtures/acts_as_loggable/bike_actions.yml @@ -1,15 +1,25 @@ acquired: id: 1 action: ACQUIRED + created_at: <%= Time.now %> + updated_at: <%= Time.now %> scrapped: id: 2 action: SCRAPPED + created_at: <%= Time.now %> + updated_at: <%= Time.now %> worked: id: 3 action: WORKED + created_at: <%= Time.now %> + updated_at: <%= Time.now %> completed: id: 4 action: COMPLETED + created_at: <%= Time.now %> + updated_at: <%= Time.now %> sold: id: 5 action: SOLD + created_at: <%= Time.now %> + updated_at: <%= Time.now %>