Sha256: 511866900f1169e194305239494111003736b6badcbbd45f56194804a584c803

Contents?: true

Size: 1.51 KB

Versions: 10

Compression:

Stored size: 1.51 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 }
    participatory_space { commentable.try(:participatory_space) }

    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

10 entries across 10 versions & 1 rubygems

Version Path
decidim-comments-0.26.1 lib/decidim/comments/test/factories.rb
decidim-comments-0.26.0 lib/decidim/comments/test/factories.rb
decidim-comments-0.26.0.rc2 lib/decidim/comments/test/factories.rb
decidim-comments-0.26.0.rc1 lib/decidim/comments/test/factories.rb
decidim-comments-0.25.2 lib/decidim/comments/test/factories.rb
decidim-comments-0.25.1 lib/decidim/comments/test/factories.rb
decidim-comments-0.25.0 lib/decidim/comments/test/factories.rb
decidim-comments-0.25.0.rc4 lib/decidim/comments/test/factories.rb
decidim-comments-0.25.0.rc3 lib/decidim/comments/test/factories.rb
decidim-comments-0.25.0.rc2 lib/decidim/comments/test/factories.rb