From 12e5bef3721faf26a8ed11c1fa5656f9e9bd0d59 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 23 Sep 2022 17:00:41 +0200 Subject: [PATCH] Add spec for action callbacks --- spec/components/custom_wizard/action_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index a9d8b0a8..d482b8ea 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -298,4 +298,23 @@ describe CustomWizard::Action do updater.update expect(updater.result[:redirect_on_next]).to eq("https://google.com") end + + it 'registers callbacks' do + wizard = CustomWizard::Builder.new(@template[:id], user).build + + described_class.register_callback(:before_create_topic) do |params, wizard, action, submission| + params[:topic_opts][:custom_fields]["topic_custom_field"] = true + params + end + + action = CustomWizard::Action.new( + wizard: wizard, + action: create_topic.with_indifferent_access, + submission: wizard.current_submission + ) + action.perform + + expect(action.result.success?).to eq(true) + expect(Topic.find(action.result.output).custom_fields["topic_custom_field"]).to eq("t") + end end