From 298b83e0df0a08ce270e21e5b158711bac345ef1 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 29 Oct 2020 10:22:22 +0100 Subject: [PATCH] Extract WhodunnitVote as a model --- .../action_delegator/vote_delegation.rb | 17 -------------- .../action_delegator/whodunnit_vote.rb | 22 +++++++++++++++++++ .../action_delegator/whodunnit_vote_spec.rb | 17 ++++++++++++++ 3 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 app/models/decidim/action_delegator/whodunnit_vote.rb create mode 100644 spec/models/decidim/action_delegator/whodunnit_vote_spec.rb diff --git a/app/commands/decidim/action_delegator/vote_delegation.rb b/app/commands/decidim/action_delegator/vote_delegation.rb index 77998bca..a831f648 100644 --- a/app/commands/decidim/action_delegator/vote_delegation.rb +++ b/app/commands/decidim/action_delegator/vote_delegation.rb @@ -22,23 +22,6 @@ def build_vote response: response ) end - - class WhodunnitVote < DelegateClass(Decidim::Consultations::Vote) - def initialize(vote, user) - @user = user - super(vote) - end - - def save - PaperTrail.request(whodunnit: user.id) do - super - end - end - - private - - attr_reader :user - end end end end diff --git a/app/models/decidim/action_delegator/whodunnit_vote.rb b/app/models/decidim/action_delegator/whodunnit_vote.rb new file mode 100644 index 00000000..e6257176 --- /dev/null +++ b/app/models/decidim/action_delegator/whodunnit_vote.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Decidim + module ActionDelegator + class WhodunnitVote < DelegateClass(Decidim::Consultations::Vote) + def initialize(vote, user) + @user = user + super(vote) + end + + def save + PaperTrail.request(whodunnit: user.id) do + super + end + end + + private + + attr_reader :user + end + end +end diff --git a/spec/models/decidim/action_delegator/whodunnit_vote_spec.rb b/spec/models/decidim/action_delegator/whodunnit_vote_spec.rb new file mode 100644 index 00000000..c1f8dd8a --- /dev/null +++ b/spec/models/decidim/action_delegator/whodunnit_vote_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::ActionDelegator::WhodunnitVote do + describe "#save" do + subject { described_class.new(vote, user) } + + let(:vote) { build(:vote) } + let(:user) { create(:user) } + + it "sets PaperTrail's whodunnit" do + expect(PaperTrail).to receive(:request).with(whodunnit: user.id).and_yield + subject.save + end + end +end