Skip to content

Commit

Permalink
Track unvotes with PaperTrail
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Oct 30, 2020
1 parent 27ce60b commit c9615f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ def destroy

user = delegation.blank? ? current_user : delegation.granter

Decidim::Consultations::UnvoteQuestion.call(current_question, user) do
on(:ok) do
current_question.reload
render :update_vote_button
PaperTrail.request(enabled: delegation.present?) do
Decidim::Consultations::UnvoteQuestion.call(current_question, user) do
on(:ok) do
current_question.reload
render :update_vote_button
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Consultations
let(:question) { create(:question, consultation: consultation) }
let(:setting) { create(:setting, consultation: consultation) }

context "when a delegation is specified" do
context "when a delegation is specified", versioning: true do
let(:delegation) { create(:delegation, setting: setting, grantee: user) }

before { create(:vote, author: delegation.granter, question: question) }
Expand All @@ -29,18 +29,28 @@ module Consultations
delete :destroy, params: { question_slug: question.slug, decidim_consultations_delegation_id: delegation.id }, format: :js
expect(response).to render_template(:update_vote_button)
end

it "creates a new version" do
expect do
delete :destroy, params: { question_slug: question.slug, decidim_consultations_delegation_id: delegation.id }, format: :js
end.to change(PaperTrail::Version, :count)
end
end

context "when no delegation is specified" do
context "when no delegation is specified", versioning: true do
before { create(:vote, author: user, question: question) }

it "destroys the vote" do
delete :destroy, params: { question_slug: question.slug }, format: :js
expect(response).to render_template(:update_vote_button)
end

it "does not create a new version" do
expect { delete :destroy, params: { question_slug: question.slug }, format: :js }
.not_to change(PaperTrail::Version, :count)
end
end
end
end
end
end

0 comments on commit c9615f6

Please sign in to comment.