From 4f5f47c998c5cefd679148a3cc4e7cdef5e23cdc Mon Sep 17 00:00:00 2001 From: Gerard Date: Sun, 7 Jul 2024 15:05:22 +1200 Subject: [PATCH 1/3] Added new do_nothing action as alias for close_modal --- lib/avo/base_action.rb | 2 ++ spec/dummy/app/avo/actions/test/do_nothing.rb | 13 +++++++++++++ spec/dummy/app/avo/resources/user.rb | 1 + 3 files changed, 16 insertions(+) create mode 100644 spec/dummy/app/avo/actions/test/do_nothing.rb diff --git a/lib/avo/base_action.rb b/lib/avo/base_action.rb index 4f2cab02bb..c7629f0009 100644 --- a/lib/avo/base_action.rb +++ b/lib/avo/base_action.rb @@ -238,6 +238,8 @@ def close_modal self end + alias 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 From 12c1c87f9f09e8ffc5dd4d789234ed0dbc972d35 Mon Sep 17 00:00:00 2001 From: Gerard Date: Sun, 7 Jul 2024 15:16:52 +1200 Subject: [PATCH 2/3] adding system spec for do_nothing --- spec/system/avo/actions_spec.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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 From 37fdae5433ed9edb9ddc060bbf892496eb5a3b3d Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Mon, 8 Jul 2024 14:04:50 +0300 Subject: [PATCH 3/3] Update lib/avo/base_action.rb --- lib/avo/base_action.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/avo/base_action.rb b/lib/avo/base_action.rb index c7629f0009..17ab2e5d37 100644 --- a/lib/avo/base_action.rb +++ b/lib/avo/base_action.rb @@ -238,7 +238,7 @@ def close_modal self end - alias do_nothing close_modal + 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