mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 19:46:17 +08:00
932bd6ba85
Some checks are pending
Licenses / run (push) Waiting to run
Linting / run (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (frontend, themes) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, chat) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, core) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, plugins) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, themes) (push) Waiting to run
Tests / core frontend (${{ matrix.browser }}) (Chrome) (push) Waiting to run
Tests / core frontend (${{ matrix.browser }}) (Firefox ESR) (push) Waiting to run
Tests / core frontend (${{ matrix.browser }}) (Firefox Evergreen) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (annotations, core) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (backend, core) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (backend, plugins) (push) Waiting to run
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (frontend, plugins) (push) Waiting to run
A `UserHistory` entry will now be created when an automation is destroyed. This is visible in `/admin/logs/staff_action_logs`. id, name, trigger and script will be logged. This commit also creates a service `DestroyAutomation` to hold all the destroy automation logic. --------- Co-authored-by: Martin Brennan <mjrbrennan@gmail.com>
44 lines
1.3 KiB
Ruby
44 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe DiscourseAutomation::DestroyAutomation do
|
|
describe described_class::Contract, type: :model do
|
|
subject(:contract) { described_class.new }
|
|
|
|
it { is_expected.to validate_presence_of :automation_id }
|
|
end
|
|
|
|
describe ".call" do
|
|
subject(:result) { described_class.call(params:, **dependencies) }
|
|
|
|
fab!(:user) { Fabricate(:admin) }
|
|
fab!(:automation) { Fabricate(:automation) }
|
|
|
|
let(:guardian) { user.guardian }
|
|
let(:params) { { automation_id: automation.id } }
|
|
let(:dependencies) { { guardian: } }
|
|
|
|
it "logs the action" do
|
|
expect { result }.to change { UserHistory.count }.by(1)
|
|
expect(UserHistory.last.details).to eq(
|
|
"id: #{automation.id}\nname: #{automation.name}\nscript: #{automation.script}\ntrigger: #{automation.trigger}",
|
|
)
|
|
end
|
|
|
|
it "destroys the automation" do
|
|
expect { result }.to change { DiscourseAutomation::Automation.count }.by(-1)
|
|
end
|
|
|
|
context "when the automation is not found" do
|
|
before { params[:automation_id] = 999 }
|
|
|
|
it { is_expected.to fail_to_find_a_model(:automation) }
|
|
end
|
|
|
|
context "when user can't destroy the automation" do
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
it { is_expected.to fail_a_policy(:can_destroy_automation) }
|
|
end
|
|
end
|
|
end
|