Sha256: cd5cba67dad2010ba2e775def9679cd3cb306b03aca03309b08ea56cab8c716f

Contents?: true

Size: 1.25 KB

Versions: 37

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Decidim
  module Comments
    # 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 Seed
      # Public: adds a random amount of comments for a given resource.
      #
      # resource - the resource to add the coments to.
      #
      # Returns nothing.
      def self.comments_for(resource)
        return unless resource.accepts_new_comments?

        Decidim::Comments::Comment.reset_column_information

        organization = resource.organization

        2.times do
          author = Decidim::User.where(organization: organization).all.sample
          user_group = [true, false].sample ? Decidim::UserGroups::ManageableUserGroups.for(author).verified.sample : nil

          params = {
            commentable: resource,
            root_commentable: resource,
            body: { en: ::Faker::Lorem.sentence(word_count: 50) },
            author: author,
            user_group: user_group
          }

          Decidim.traceability.create!(
            Decidim::Comments::Comment,
            author,
            params,
            visibility: "public-only"
          )
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-comments-0.27.9 app/models/decidim/comments/seed.rb
decidim-comments-0.27.8 app/models/decidim/comments/seed.rb
decidim-comments-0.27.7 app/models/decidim/comments/seed.rb
decidim-comments-0.27.6 app/models/decidim/comments/seed.rb
decidim-comments-0.26.10 app/models/decidim/comments/seed.rb
decidim-comments-0.26.9 app/models/decidim/comments/seed.rb
decidim-comments-0.27.5 app/models/decidim/comments/seed.rb
decidim-comments-0.26.8 app/models/decidim/comments/seed.rb
decidim-comments-0.27.4 app/models/decidim/comments/seed.rb
decidim-comments-0.27.3 app/models/decidim/comments/seed.rb
decidim-comments-0.26.7 app/models/decidim/comments/seed.rb
decidim-comments-0.26.5 app/models/decidim/comments/seed.rb
decidim-comments-0.27.2 app/models/decidim/comments/seed.rb
decidim-comments-0.27.1 app/models/decidim/comments/seed.rb
decidim-comments-0.26.4 app/models/decidim/comments/seed.rb
decidim-comments-0.27.0 app/models/decidim/comments/seed.rb
decidim-comments-0.26.3 app/models/decidim/comments/seed.rb
decidim-comments-0.27.0.rc2 app/models/decidim/comments/seed.rb
decidim-comments-0.27.0.rc1 app/models/decidim/comments/seed.rb
decidim-comments-0.26.2 app/models/decidim/comments/seed.rb