http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-usersRailstutorial : db : 채집 대 공장 소녀
namespace :db do
desc "Fill database with sample data"
task :populate => :environment do
Rake::Task['db:reset'].invoke
User.create!(:name => "Example User",
:email => "[email protected]",
:password => "foobar",
:password_confirmation => "foobar")
99.times do |n|
name = Faker::Name.name
email = "example-#{n+1}@railstutorial.org"
password = "password"
User.create!(:name => name,
:email => email,
:password => password,
:password_confirmation => password)
end
end
end
가짜 사용자로 데이터베이스를 채울 때 (Listing 7.16) http://ruby.railstutorial.org/chapters/modeling-and-viewing-users-two
Factory.define :user do |user|
user.name "Michael Hartl"
user.email "[email protected]"
user.password "foobar"
user.password_confirmation "foobar"
end
두 가지 방법으로 데이터베이스에 사용자를 올바르게 생성 한 것으로 보입니다 (공장 소녀가 데이터베이스에 사용자를 생성합니까?). 테스트 사용자를 생성하는 두 가지 다른 방법의 이유는 무엇이며 어떻게 다릅니 까? 하나의 방법이 다른 것보다 더 적합한 경우는 언제입니까?
흠 ...하지만 왜 그는 Userkeys 대신에 레이크 작업에서 FactoryGirl을 사용하지 않을까요? 그게 가능하지 않니? – Ajedi32