Skip to content

Commit

Permalink
Extract WhodunnitVote as a model
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Oct 29, 2020
1 parent 3f21c5b commit 298b83e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
17 changes: 0 additions & 17 deletions app/commands/decidim/action_delegator/vote_delegation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions app/models/decidim/action_delegator/whodunnit_vote.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions spec/models/decidim/action_delegator/whodunnit_vote_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 298b83e

Please sign in to comment.