Class: Decidim::Comments::Seed

Inherits:
Object
  • Object
show all
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

Class Method Details

.comments_for(resource) ⇒ Object

Adds a random amount of comments for a given resource.

Parameters:

  • resource (Object)
    • the Decidim resource to add the comments to.

    examples: Decidim::Proposals::CollaborativeDraft, Decidim::Proposals::Proposal,

Returns:

  • nil



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'decidim-comments/app/models/decidim/comments/seed.rb', line 16

def comments_for(resource)
  return unless resource.accepts_new_comments?

  Decidim::Comments::Comment.reset_column_information

  @organization = resource.organization

  rand(0..6).times do
    comment1 = create_comment(resource)
    NewCommentNotificationCreator.new(comment1, []).create

    if [true, false].sample
      comment2 = create_comment(comment1, resource)
      NewCommentNotificationCreator.new(comment2, []).create
    end

    next if [true, false].sample

    create_votes(comment1) if comment1
    create_votes(comment2) if comment2
  end
end