Sha256: 4a0374c9420fa5789f3be0d70eed4251f90fee0a19893f48b7468061278d5dbc

Contents?: true

Size: 944 Bytes

Versions: 30

Compression:

Stored size: 944 Bytes

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)
        organization = resource.organization

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

          Comment.create(
            commentable: resource,
            root_commentable: resource,
            body: ::Faker::Lorem.sentence,
            author: author,
            user_group: user_group
          )
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
decidim-comments-0.14.4 app/models/decidim/comments/seed.rb
decidim-comments-0.14.3 app/models/decidim/comments/seed.rb
decidim-comments-0.14.2 app/models/decidim/comments/seed.rb
decidim-comments-0.14.1 app/models/decidim/comments/seed.rb
decidim-comments-0.13.1 app/models/decidim/comments/seed.rb
decidim-comments-0.12.2 app/models/decidim/comments/seed.rb
decidim-comments-0.13.0 app/models/decidim/comments/seed.rb
decidim-comments-0.12.1 app/models/decidim/comments/seed.rb
decidim-comments-0.13.0.pre1 app/models/decidim/comments/seed.rb
decidim-comments-0.12.0 app/models/decidim/comments/seed.rb
decidim-comments-0.11.2 app/models/decidim/comments/seed.rb
decidim-comments-0.12.0.pre app/models/decidim/comments/seed.rb
decidim-comments-0.11.1 app/models/decidim/comments/seed.rb
decidim-comments-0.11.0.pre1 app/models/decidim/comments/seed.rb
decidim-comments-0.10.1 app/models/decidim/comments/seed.rb
decidim-comments-0.10.0 app/models/decidim/comments/seed.rb
decidim-comments-0.9.3 app/models/decidim/comments/seed.rb
decidim-comments-0.9.2 app/models/decidim/comments/seed.rb
decidim-comments-0.9.1 app/models/decidim/comments/seed.rb
decidim-comments-0.9.0 app/models/decidim/comments/seed.rb