Sha256: 64de51f28198834cec29421aa9dd6fde30f71eb89d6666db4ee4e96209252121

Contents?: true

Size: 953 Bytes

Versions: 38

Compression:

Stored size: 953 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

        rand(1..5).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

38 entries across 38 versions & 2 rubygems

Version Path
decidim-comments-0.6.8 app/models/decidim/comments/seed.rb
decidim-0.6.8 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.6.7 app/models/decidim/comments/seed.rb
decidim-0.6.7 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.6.6 app/models/decidim/comments/seed.rb
decidim-0.6.6 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.6.5 app/models/decidim/comments/seed.rb
decidim-0.6.5 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.6.4 app/models/decidim/comments/seed.rb
decidim-0.6.4 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.6.3 app/models/decidim/comments/seed.rb
decidim-0.6.3 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.6.2 app/models/decidim/comments/seed.rb
decidim-0.6.2 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.6.1 app/models/decidim/comments/seed.rb
decidim-0.6.1 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.6.0 app/models/decidim/comments/seed.rb
decidim-0.6.0 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.5.1 app/models/decidim/comments/seed.rb
decidim-0.5.1 decidim-comments/app/models/decidim/comments/seed.rb