Skip to content

Commit 1712b62

Browse files
mathieumarache
authored andcommitted
playing with seeds
1 parent 740401a commit 1712b62

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

db/seeds.rb

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# This file should contain all the record creation needed to seed the database with its default values.
2-
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3-
#
4-
# Examples:
5-
#
6-
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7-
# Mayor.create(name: 'Emanuel', city: cities.first)
1+
require 'active_record/fixtures'
2+
3+
Product.delete_all
4+
Fixtures.create_fixtures("#{Rails.root}/test/fixtures", "products")

test/fixtures/products.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
22

33
one:
4-
title: MyString
4+
title: My first product
55
name: MyString
66
description: MyText
77

88
two:
9-
title: MyString
9+
title: My second product
1010
name: MyString
1111
description: MyText

test/fixtures/users.yml

+4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
#
77
user_one:
88
9+
encrypted_password: <%= User.new.send(:password_digest, 'one') %>
10+
products: one, two
911

1012
# column: value
1113
#
1214
user_two:
1315
16+
encrypted_password: <%= User.new.send(:password_digest, 'two') %>
17+
products: two
1418

1519
# column: value

0 commit comments

Comments
 (0)