Class: Decidim::Comments::Seed
- Inherits:
-
Object
- Object
- Decidim::Comments::Seed
- Defined in:
- decidim-comments/app/models/decidim/comments/seed.rb
Overview
A comment can belong to many Commentable models. This class is responsible to Seed those models in order to be able to use them in the development app.
Class Method Summary collapse
-
.comments_for(resource) ⇒ Object
Public: adds a random amount of comments for a given resource.
Class Method Details
.comments_for(resource) ⇒ Object
Public: adds a random amount of comments for a given resource.
resource - the resource to add the coments to.
Returns nothing.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'decidim-comments/app/models/decidim/comments/seed.rb', line 14 def self.comments_for(resource) return unless resource.accepts_new_comments? Decidim::Comments::Comment.reset_column_information organization = resource.organization 2.times do = Decidim::User.where(organization:).all.sample user_group = [true, false].sample ? Decidim::UserGroups::ManageableUserGroups.for().verified.sample : nil params = { commentable: resource, root_commentable: resource, body: { en: ::Faker::Lorem.sentence(word_count: 50) }, author:, user_group: } Decidim.traceability.create!( Decidim::Comments::Comment, , params, visibility: "public-only" ) end end |