Skip to content

Commit

Permalink
Fix ActionLog when a ballot style is deleted (decidim#9355)
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolgual authored and eliegaboriau committed Oct 25, 2022
1 parent a437d99 commit b6de658
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def destroy_ballot_style!
:delete,
ballot_style,
current_user,
visibility: "all"
{ visibility: "all", code: ballot_style.code }
) do
ballot_style.destroy!
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ class BallotStylePresenter < Decidim::Log::BasePresenter

def i18n_params
super.merge(
ballot_style_code: action_log.resource.code
ballot_style_code: ballot_style_code.to_s
)
end

def ballot_style_code
action_log&.resource&.code || action_log.extra["code"]
end

def action_string
case action
when "create", "delete", "update"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ module Admin
it "traces the action", versioning: true do
expect(Decidim.traceability)
.to receive(:perform_action!)
.with(:delete, ballot_style, user, visibility: "all")
.with(:delete, ballot_style, user, { visibility: "all", code: ballot_style.code })
.and_call_original

expect { subject.call }.to change(Decidim::ActionLog, :count)
action_log = Decidim::ActionLog.last
expect(action_log.action).to eq("delete")
expect(action_log.extra["code"]).to eq(ballot_style.code)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module Decidim
create(
:action_log,
action: action,
resource: resource
resource: resource,
extra_data: { code: resource.code }
)
end

Expand Down Expand Up @@ -42,6 +43,11 @@ module Decidim
context "when the ballot style is deleted" do
let(:action) { :delete }

before do
resource.destroy!
action_log.reload
end

it "shows that the ballot style has been created" do
expect(subject.present).to include(resource.code)
expect(subject.present).to include("deleted the ballot style")
Expand Down

0 comments on commit b6de658

Please sign in to comment.