diff --git a/app/models/decidim/action_delegator/unversioned_vote.rb b/app/models/decidim/action_delegator/unversioned_vote.rb new file mode 100644 index 00000000..a0131963 --- /dev/null +++ b/app/models/decidim/action_delegator/unversioned_vote.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Decidim + module ActionDelegator + class UnversionedVote < SimpleDelegator + def save + PaperTrail.request(enabled: false) do + super + end + end + end + end +end diff --git a/app/overrides/commands/decidim/consultations/vote_question.rb b/app/overrides/commands/decidim/consultations/vote_question.rb index 011d75dc..f2c58c8b 100644 --- a/app/overrides/commands/decidim/consultations/vote_question.rb +++ b/app/overrides/commands/decidim/consultations/vote_question.rb @@ -8,10 +8,11 @@ def build_vote form.context.delegation = delegation Decidim::ActionDelegator::VoteDelegation.new(form).call else - form.context.current_question.votes.build( + vote = form.context.current_question.votes.build( author: form.context.current_user, response: form.response ) + Decidim::ActionDelegator::UnversionedVote.new(vote) end end diff --git a/spec/commands/decidim/consultations/vote_question_spec.rb b/spec/commands/decidim/consultations/vote_question_spec.rb index b6d833c6..fb59e63a 100644 --- a/spec/commands/decidim/consultations/vote_question_spec.rb +++ b/spec/commands/decidim/consultations/vote_question_spec.rb @@ -51,10 +51,9 @@ module Consultations end describe "originator", versioning: true do - it "tracks who was responsible for the action" do - subject.call - vote = Vote.last - expect(vote.paper_trail.originator).to be_nil + it "does not track who was responsible for the action" do + expect { subject.call } + .not_to change(PaperTrail::Version.where(item_type: "Decidim::Consultations::Vote"), :count) end end diff --git a/spec/models/decidim/action_delegator/unversioned_vote_spec.rb b/spec/models/decidim/action_delegator/unversioned_vote_spec.rb new file mode 100644 index 00000000..4093ede6 --- /dev/null +++ b/spec/models/decidim/action_delegator/unversioned_vote_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module ActionDelegator + describe UnversionedVote do + subject(:unversioned_vote) { described_class.new(vote) } + + let(:vote) { build(:vote) } + + it "disables PaperTrail", versioning: true do + subject.save + + expect(unversioned_vote.versions).to be_empty + end + end + end +end