Sha256: b488637558841d2200ae90fee6b3f3a3b4629fe82fd51d723c17bec1790f0d8c

Contents?: true

Size: 817 Bytes

Versions: 13

Compression:

Stored size: 817 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
          random = rand(Decidim::User.count)
          Comment.create(
            commentable: resource,
            body: ::Faker::Lorem.sentence,
            author: Decidim::User.where(organization: organization).offset(random).first
          )
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
decidim-comments-0.0.8.1 app/models/decidim/comments/seed.rb
decidim-0.0.8.1 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.0.7 app/models/decidim/comments/seed.rb
decidim-0.0.7 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.0.6 app/models/decidim/comments/seed.rb
decidim-0.0.6 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.0.5 app/models/decidim/comments/seed.rb
decidim-0.0.5 decidim-comments/app/models/decidim/comments/seed.rb
decidim-0.0.4 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.0.3 app/models/decidim/comments/seed.rb
decidim-0.0.3 decidim-comments/app/models/decidim/comments/seed.rb
decidim-comments-0.0.2 app/models/decidim/comments/seed.rb
decidim-0.0.2 decidim-comments/app/models/decidim/comments/seed.rb