Class: Decidim::Comments::Seed
- Inherits:
-
Object
- Object
- Decidim::Comments::Seed
- Defined in:
- 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
Adds a random amount of comments for a given resource.
Class Method Details
.comments_for(resource) ⇒ Object
Adds a random amount of comments for a given resource.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/decidim/comments/seed.rb', line 18 def comments_for(resource) return unless resource.accepts_new_comments? Decidim::Comments::Comment.reset_column_information @organization = resource.organization rand(0..config_value(:comments_count)).times do comment1 = create_comment(resource) NewCommentNotificationCreator.new(comment1, []).create if rand < config_value(:comments_nested_probability) comment2 = create_comment(comment1, resource) NewCommentNotificationCreator.new(comment2, []).create end next if rand < config_value(:comments_vote_skip_probability) create_votes(comment1) if comment1 create_votes(comment2) if comment2 end end |