Michael J. I. Jackson
2009-Feb-23 21:52 UTC
How to set up fixtures to use ActiveRecord callbacks?
Hi all,
I have a rake task that is seeding my database. This is so I can drop
and recreate the entire database and then add some company accounts
very easily. My rake file (lib/tasks/database.rake) looks like this:
namespace :db do
desc "Load seed fixtures (from db/fixture) into the current
environment''s database."
task :seed => :environment do
require ''active_record/fixtures''
Dir.glob(RAILS_ROOT + ''/db/fixture/*.yml'').each do |file|
Fixtures.create_fixtures(''db/fixture'',
File.basename(file, ''.*''))
end
end
end
Basically, it''s just looking through db/fixture for any fixture files
to load into the database. As mentioned previously, I''d like to use
the fixture to create some user accounts. However, in my account
model, I have a before_save callback that is responsible for creating
hashes of user''s passwords before they are saved out to the database.
Is there any way to do either make the rake task respect the
ActiveRecord callbacks or somehow add the hashing logic directly to
the task?
Thanks in advance,
Michael J. I. Jackson
mjijackson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I''ve found the easiest way to do this is to put hashed passwords in the fixtures, i.e. user_1: id: 1 email: user-t1rxLZ7CIXi4Mf/Zr4nk6A@public.gmane.org password: ae135e826bbd76cf593d8db38c02ed2e134e159f #test On Mon, Feb 23, 2009 at 1:52 PM, Michael J. I. Jackson <mjijackson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I have a rake task that is seeding my database. This is so I can drop > and recreate the entire database and then add some company accounts > very easily. My rake file (lib/tasks/database.rake) looks like this: > > namespace :db do > desc "Load seed fixtures (from db/fixture) into the current > environment''s database." > task :seed => :environment do > require ''active_record/fixtures'' > Dir.glob(RAILS_ROOT + ''/db/fixture/*.yml'').each do |file| > Fixtures.create_fixtures(''db/fixture'', File.basename(file, ''.*'')) > end > end > end > > Basically, it''s just looking through db/fixture for any fixture files > to load into the database. As mentioned previously, I''d like to use > the fixture to create some user accounts. However, in my account > model, I have a before_save callback that is responsible for creating > hashes of user''s passwords before they are saved out to the database. > Is there any way to do either make the rake task respect the > ActiveRecord callbacks or somehow add the hashing logic directly to > the task? > > Thanks in advance, > > Michael J. I. Jackson > mjijackson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---