Sha256: b980d076eb703ce94570a5a29c53899e0fa8d2f3a0c74ca74444e4993edf1dcf

Contents?: true

Size: 1.44 KB

Versions: 15

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require "decidim/core/test/factories"

FactoryBot.define do
  factory :comment, class: "Decidim::Comments::Comment" do
    author { build(:user, organization: commentable.organization) }
    commentable { build(:dummy_resource) }
    root_commentable { commentable }
    body { Decidim::Faker::Localized.paragraph }

    after(:build) do |comment, evaluator|
      comment.body = if evaluator.body.is_a?(String)
                       { comment.root_commentable.organization.default_locale || "en" => evaluator.body }
                     else
                       evaluator.body
                     end
      comment.body = Decidim::ContentProcessor.parse_with_processor(:hashtag, comment.body, current_organization: comment.root_commentable.organization).rewrite
    end

    trait :comment_on_comment do
      author { build(:user, organization: root_commentable.organization) }
      commentable do
        build(
          :comment,
          author: author,
          root_commentable: root_commentable,
          commentable: root_commentable
        )
      end
      root_commentable { build(:dummy_resource) }
    end
  end

  factory :comment_vote, class: "Decidim::Comments::CommentVote" do
    comment { build(:comment) }
    author { build(:user, organization: comment.organization) }
    weight { [-1, 1].sample }

    trait :up_vote do
      weight { 1 }
    end

    trait :down_vote do
      weight { -1 }
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-comments-0.25.0.rc1 lib/decidim/comments/test/factories.rb
decidim-comments-0.24.3 lib/decidim/comments/test/factories.rb
decidim-comments-0.23.6 lib/decidim/comments/test/factories.rb
decidim-comments-0.24.2 lib/decidim/comments/test/factories.rb
decidim-comments-0.23.5 lib/decidim/comments/test/factories.rb
decidim-comments-0.24.1 lib/decidim/comments/test/factories.rb
decidim-comments-0.24.0 lib/decidim/comments/test/factories.rb
decidim-comments-0.24.0.rc2 lib/decidim/comments/test/factories.rb
decidim-comments-0.23.4 lib/decidim/comments/test/factories.rb
decidim-comments-0.24.0.rc1 lib/decidim/comments/test/factories.rb
decidim-comments-0.23.3 lib/decidim/comments/test/factories.rb
decidim-comments-0.23.2 lib/decidim/comments/test/factories.rb
decidim-comments-0.23.1 lib/decidim/comments/test/factories.rb
decidim-comments-0.23.1.rc1 lib/decidim/comments/test/factories.rb
decidim-comments-0.23.0 lib/decidim/comments/test/factories.rb