diff --git a/lib/avo/base_action.rb b/lib/avo/base_action.rb index 4f2cab02bb..17ab2e5d37 100644 --- a/lib/avo/base_action.rb +++ b/lib/avo/base_action.rb @@ -238,6 +238,8 @@ def close_modal self end + alias_method :do_nothing, :close_modal + # Add a placeholder silent message from when a user wants to do a redirect action or something similar def silent add_message nil, :silent diff --git a/spec/dummy/app/avo/actions/test/do_nothing.rb b/spec/dummy/app/avo/actions/test/do_nothing.rb new file mode 100644 index 0000000000..fd310a5611 --- /dev/null +++ b/spec/dummy/app/avo/actions/test/do_nothing.rb @@ -0,0 +1,13 @@ +class Avo::Actions::Test::DoNothing < Avo::BaseAction + self.name = "Do Nothing" + self.standalone = true + self.visible = -> { + true + } + + def handle(**args) + TestBuddy.hi "Hello from Avo::Actions::Test::DoNothing handle method" + succeed "Nothing Done!!" + do_nothing + end +end diff --git a/spec/dummy/app/avo/resources/user.rb b/spec/dummy/app/avo/resources/user.rb index 490467af9e..6502dd85fe 100644 --- a/spec/dummy/app/avo/resources/user.rb +++ b/spec/dummy/app/avo/resources/user.rb @@ -73,6 +73,7 @@ def actions divider action Avo::Actions::Test::NoConfirmationRedirect action Avo::Actions::Test::CloseModal + action Avo::Actions::Test::DoNothing action Avo::Actions::DetachUser end diff --git a/spec/system/avo/actions_spec.rb b/spec/system/avo/actions_spec.rb index baf7d7a45e..18a5cbb872 100644 --- a/spec/system/avo/actions_spec.rb +++ b/spec/system/avo/actions_spec.rb @@ -179,8 +179,30 @@ end end + + describe "do_nothing" do + it "closes the modal and flashes messages" do + allow(TestBuddy).to receive(:hi).and_call_original + expect(TestBuddy).to receive(:hi).with("Hello from Avo::Actions::Test::DoNothing handle method").at_least :once + + visit "/admin/resources/users/new" + + fill_in "user_first_name", with: "First name should persist after action." + + + click_on "Actions" + click_on "Do Nothing" + expect(page).to have_css('turbo-frame#actions_show') + expect(page).to have_selector(modal = "[role='dialog']") + click_on "Run" + expect(page).not_to have_selector(modal) + expect(page).to have_text "Nothing Done!!" + expect(page).to have_field('user_first_name', with: 'First name should persist after action.') + end + end + describe "close_modal" do - it "closes the modal and flahses messages" do + it "closes the modal and flashes messages" do allow(TestBuddy).to receive(:hi).and_call_original expect(TestBuddy).to receive(:hi).with("Hello from Avo::Actions::Test::CloseModal handle method").at_least :once