Sha256: b6881a13cab068f021c290af1142b0a38dd02acc9fc70fe188ec7c11354561ad

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true
require "spec_helper"

module Decidim
  module Proposals
    describe ProposalVote do
      let!(:organization) { create(:organization) }
      let!(:feature) { create(:feature, organization: organization, manifest_name: "proposals") }
      let!(:participatory_process) { create(:participatory_process, organization: organization) }
      let!(:author) { create(:user, organization: organization) }
      let!(:proposal) { create(:proposal, feature: feature, author: author) }
      let!(:proposal_vote) { create(:proposal_vote, proposal: proposal, author: author) }

      subject { proposal_vote }

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

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

      it "has an associated proposal" do
        expect(proposal_vote.proposal).to be_a(Decidim::Proposals::Proposal)
      end

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

      context "when no author" do
        before do
          proposal_vote.author = nil
        end

        it { is_expected.to be_invalid }
      end

      context "when no proposal" do
        before do
          proposal_vote.proposal = nil
        end

        it { is_expected.to be_invalid }
      end

      context "when proposal and author have different organization" do
        let(:other_author) { create(:user) }
        let(:other_proposal) { create(:proposal) }

        it "is invalid" do
          proposal_vote = build(:proposal_vote, proposal: other_proposal, author: other_author)
          expect(proposal_vote).to be_invalid
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-0.1.0 decidim-proposals/spec/models/decidim/proposals/proposal_vote_spec.rb