Setting up 1000 Devise user accounts using fixtures

Seting up a one Devise user (version 3.5.1 and later) is simple

in file <app>/test/fixtures/users.yml:
tom:
  id: 11
  name: TestUser
  email: test@example.org
  encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>

If you want to setup 1000 users, use some ERB code instead.

<% 1.upto(1000) do |i| %>
 fix_<%= i %>:
 id: <%= i %>
 name: guy_<%= i %>
 email: guy_<%= i %>@example.org
 encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>
 <% end %>

Note that it is OK to insert ERB code in the YML file.

Now run the command:

time rake db:fixtures:load

I prefix with “time” just to see how long it take to run. On my machine, it took about 2 minutes to create 1000 Devise users.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.