Sha256: 1196fa84ba4de99885edc7d8df192d308795f343dc2f282e4d4884431ea56a45

Contents?: true

Size: 1.59 KB

Versions: 11

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Comments
    describe CommentVote do
      let!(:organization) { create(:organization) }
      let!(:participatory_process) { create(:participatory_process, organization: organization) }
      let!(:feature) { create(:feature, participatory_process: participatory_process) }
      let!(:commentable) { create(:dummy_resource, feature: feature) }
      let!(:author) { create(:user, organization: organization) }
      let!(:comment) { create(:comment, commentable: commentable, author: author) }
      let!(:comment_vote) { create(:comment_vote, comment: comment, author: author) }

      it "is valid" do
        expect(comment_vote).to be_valid
      end

      it "has an associated author" do
        expect(comment_vote.author).to be_a(Decidim::User)
      end

      it "has an associated comment" do
        expect(comment_vote.comment).to be_a(Decidim::Comments::Comment)
      end

      it "validates uniqueness for author and comment combination" do
        expect do
          create(:comment_vote, comment: comment, author: author)
        end.to raise_error(ActiveRecord::RecordInvalid)
      end

      it "is invalid with a weight different from 1 and -1" do
        comment_vote.weight = 2
        expect(comment_vote).to be_invalid
      end

      it "is invalid if comment and author have different organizations" do
        author = create(:user)
        comment = create(:comment)
        comment_vote = build(:comment_vote, comment: comment, author: author)
        expect(comment_vote).to be_invalid
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
decidim-0.5.1 decidim-comments/spec/models/comment_vote_spec.rb
decidim-0.5.0 decidim-comments/spec/models/comment_vote_spec.rb
decidim-0.4.4 decidim-comments/spec/models/comment_vote_spec.rb
decidim-0.4.3 decidim-comments/spec/models/comment_vote_spec.rb
decidim-0.4.2 decidim-comments/spec/models/comment_vote_spec.rb
decidim-0.4.1 decidim-comments/spec/models/comment_vote_spec.rb
decidim-0.4.0 decidim-comments/spec/models/comment_vote_spec.rb
decidim-0.3.2 decidim-comments/spec/models/comment_vote_spec.rb
decidim-0.3.1 decidim-comments/spec/models/comment_vote_spec.rb
decidim-0.3.0 decidim-comments/spec/models/comment_vote_spec.rb
decidim-0.2.0 decidim-comments/spec/models/comment_vote_spec.rb