Sha256: a175c42094d46ea365111e59ea40005a4c18e67ce137c3d786cebaeb24a82c2d

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

require "spec_helper"

shared_context "when it is a comment event" do
  include Decidim::ComponentPathHelper
  include Decidim::SanitizeHelper

  include_context "when a simple event"

  let(:resource) { comment.commentable }

  let(:comment) { create :comment }
  let(:comment_author) { comment.author }
  let(:normalized_comment_author) { comment.author }
  let(:comment_author_name) { decidim_html_escape comment.author.name }

  let(:extra) { { comment_id: comment.id } }
  let(:resource_title) { decidim_sanitize_translated(resource.title) }
  let(:user_group) do
    user_group = create(:user_group, :verified, organization:, users: [comment_author])
    comment.update!(user_group:)
    user_group
  end
end

shared_examples_for "a comment event" do
  it_behaves_like "a simple event"

  describe "author" do
    it "returns the comment author" do
      if defined? user_group_author
        expect(subject.author).to eq(user_group_author)
      else
        expect(subject.author).to eq(comment_author)
      end
    end
  end

  describe "resource_text" do
    it "outputs the comment body" do
      expect(subject.resource_text).to eq comment.formatted_body
    end
  end

  describe "hidden_resource?" do
    context "when comment is not moderated" do
      it "returns false" do
        expect(subject.hidden_resource?).to be false
      end
    end

    context "when comment is moderated" do
      let(:comment) { create(:comment, :moderated) }

      it "returns true" do
        expect(subject.hidden_resource?).to be true
      end
    end

    context "when resource is not moderated" do
      it "returns false" do
        expect(subject.hidden_resource?).to be false
      end
    end

    context "when resource is moderated" do
      before do
        create(:moderation, reportable: resource, hidden_at: 2.days.ago)
        resource.reload
      end

      it "returns true" do
        expect(subject.hidden_resource?).to be true
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-comments-0.29.1 lib/decidim/comments/test/shared_examples/comment_event.rb
decidim-comments-0.28.4 lib/decidim/comments/test/shared_examples/comment_event.rb
decidim-comments-0.29.0 lib/decidim/comments/test/shared_examples/comment_event.rb
decidim-comments-0.28.3 lib/decidim/comments/test/shared_examples/comment_event.rb
decidim-comments-0.29.0.rc4 lib/decidim/comments/test/shared_examples/comment_event.rb
decidim-comments-0.29.0.rc3 lib/decidim/comments/test/shared_examples/comment_event.rb
decidim-comments-0.29.0.rc2 lib/decidim/comments/test/shared_examples/comment_event.rb
decidim-comments-0.29.0.rc1 lib/decidim/comments/test/shared_examples/comment_event.rb
decidim-comments-0.28.2 lib/decidim/comments/test/shared_examples/comment_event.rb