Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Dependency.destroy_all
Comment.destroy_all
Copy link

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.


puts "create 2 dependencies: d1 and d2"
Copy link

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.

d1 = Dependency.create(name: "Gem n°1")
Copy link

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.

d2 = Dependency.create(name: "Gem n°2")

puts "create 1 unpublished comment, c0,related to dependency d1"
c0 = Comment.create(body: "unpublished comment", published: false, dependency: d1)

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)
Copy link

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.


puts "#{Dependency.count} created"
puts "#{Comment.count} created"

puts "Happy Growing !"
Copy link

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.