Browse Source

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.
denney-disable-on-select
Jason Denney 12 years ago
parent
commit
c99d1e5f55
  1. 10
      db/seeds.rb
  2. 10
      test/fixtures/acts_as_loggable/bike_actions.yml

10
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

10
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 %>

Loading…
Cancel
Save