-
Notifications
You must be signed in to change notification settings - Fork 0
write seeds for comments and dependencies #20
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not in favor to add those to db/seeds.rb
which I would keep for "real"
data that is essential for running the application.
But if we find them useful, I'm not against adding this as a script in bin
directory, as a rake task, or maybe another way?
db/seeds.rb
Outdated
@@ -0,0 +1,18 @@ | |||
Dependency.destroy_all | |||
Comment.destroy_all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether it's "real" seeds, or fake data we would find useful in a development
workflow, I would not do this, we should never destroy all records for a model
in seeds IMO.
db/seeds.rb
Outdated
Dependency.destroy_all | ||
Comment.destroy_all | ||
|
||
puts "create 2 dependencies: d1 and d2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this. If we want more info about seeds, we can just read this
file, and when we execute the db:seed
task, rails logs are printed on
standard output if I recall correctly.
db/seeds.rb
Outdated
Comment.destroy_all | ||
|
||
puts "create 2 dependencies: d1 and d2" | ||
d1 = Dependency.create(name: "Gem n°1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend Dependency#find_or_create_by!
, so that it's created only once,
and fail directly when the creation is not possible.
db/seeds.rb
Outdated
|
||
puts "create 2 published comments; c1 and c2, related to dependency d2" | ||
c1 = Comment.create(body: "published comment number 1", published: true, dependency: d2) | ||
c2 = Comment.create(body: "published comment number 2", published: true, dependency: d2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Local variables c0
, c1
, c2
are dead code (unused) I think.
db/seeds.rb
Outdated
puts "#{Dependency.count} created" | ||
puts "#{Comment.count} created" | ||
|
||
puts "Happy Growing !" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said, I'd remove all #puts
calls. But we miss a final \n
at end of file
here.
Another remark: we must keep in mind that if we add this, we'll have to maintain it. |
I moved this behavior on a rake task
|
Some seeds to start using our toolbox.