Skip to content

Commit

Permalink
Do not track regular votes
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Nov 5, 2020
1 parent c518582 commit 4c64f52
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
13 changes: 13 additions & 0 deletions app/models/decidim/action_delegator/unversioned_vote.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions spec/commands/decidim/consultations/vote_question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions spec/models/decidim/action_delegator/unversioned_vote_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4c64f52

Please sign in to comment.