Ver código fonte

Add User seeds

Frans Bergman 7 anos atrás
pai
commit
4dfc66ebdb
3 arquivos alterados com 24 adições e 0 exclusões
  1. 2 0
      Gemfile
  2. 3 0
      Gemfile.lock
  3. 19 0
      db/seeds.rb

+ 2 - 0
Gemfile

@@ -35,6 +35,8 @@ gem "font-awesome-rails"
 # gem 'redis', '~> 3.0'
 # Use ActiveModel has_secure_password
 gem 'bcrypt', '~> 3.1.7'
+# Use faker to generate seed data
+gem 'faker', '~> 1.7.3'
 
 # Use Capistrano for deployment
 # gem 'capistrano-rails', group: :development

+ 3 - 0
Gemfile.lock

@@ -70,6 +70,8 @@ GEM
     crass (1.0.3)
     erubi (1.7.0)
     execjs (2.7.0)
+    faker (1.7.3)
+      i18n (~> 0.5)
     ffi (1.9.18)
     font-awesome-rails (4.7.0.2)
       railties (>= 3.2, < 5.2)
@@ -196,6 +198,7 @@ DEPENDENCIES
   byebug
   capybara (~> 2.13)
   coffee-rails (~> 4.2)
+  faker (~> 1.7.3)
   font-awesome-rails
   jbuilder (~> 2.5)
   jquery-rails (~> 4.3.1)

+ 19 - 0
db/seeds.rb

@@ -5,3 +5,22 @@
 #
 #   movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
 #   Character.create(name: 'Luke', movie: movies.first)
+
+User.create!(name:  "Example User",
+             login: "example",
+             email: "example@example.com",
+             password:              "foobar",
+             password_confirmation: "foobar")
+
+
+99.times do |n|
+ name  = Faker::Name.name
+ email = "example-#{n+1}@example.com"
+ password = "password"
+ login = "example_#{n+1}"
+ User.create!(name:  name,
+              email: email,
+              login: login,
+              password:              password,
+              password_confirmation: password)
+end