Skip to content

Commit

Permalink
apply 2038 & 2034
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Nov 24, 2023
1 parent d47ac08 commit 04a28ae
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/avo/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def destroy
association_name = BaseResource.valid_association_name(@record, params[:related_name])

if reflection_class == "HasManyReflection"
@record.send(association_name).destroy @attachment_record
@record.send(association_name).delete @attachment_record
else
@record.send("#{association_name}=", nil)
end
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/js/controllers/action_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Controller } from '@hotwired/stimulus'
import { castBoolean } from '../helpers/cast_boolean'

export default class extends Controller {
static targets = ['controllerDiv', 'resourceIds', 'form', 'selectedAllQuery']
static targets = ['controllerDiv', 'resourceIds', 'submit', 'selectedAllQuery']

connect() {
if (this.resourceIdsTarget.value === '') {
Expand All @@ -15,7 +15,7 @@ export default class extends Controller {
}

if (this.noConfirmation) {
this.formTarget.submit()
this.submitTarget.click()
} else {
this.controllerDivTarget.classList.remove('hidden')
}
Expand Down
12 changes: 7 additions & 5 deletions lib/avo/base_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ class << self
def form_data_attributes
# We can't respond with a file download from Turbo se we disable it on the form
if may_download_file
{turbo: turbo || false, remote: false, action_target: :form}
{turbo: turbo || false, remote: false}
else
{turbo: turbo, turbo_frame: :_top, action_target: :form}.compact
{turbo: turbo, turbo_frame: :_top}.compact
end
end

# We can't respond with a file download from Turbo se we disable close the modal manually after a while (it's a hack, we know)
def submit_button_data_attributes
attributes = { action_target: "submit" }

if may_download_file
{action: "click->modal#delayedClose"}
else
{}
attributes[:action] = "click->modal#delayedClose"
end

attributes
end

def to_param
Expand Down
26 changes: 26 additions & 0 deletions spec/system/avo/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,32 @@
end
end

describe "redirects when no confirmation" do
it "redirects to hey page" do
original_dummy_action = Avo::Actions::Sub::DummyAction.dup

Avo::Actions::Sub::DummyAction.class_eval do
self.no_confirmation = true

define_method(:redirect_handle) do |**args|
redirect_to main_app.hey_path
end

alias_method :handle, :redirect_handle
end

visit "/admin/resources/users"

click_on "Actions"
click_on "Dummy action"

expect(page).to have_text "hey en"

Avo::Actions::Sub.send(:remove_const, "DummyAction")
Avo::Actions::Sub.const_set("DummyAction", original_dummy_action)
end
end

# let!(:roles) { { admin: false, manager: false, writer: false } }
# let!(:user) { create :user, active: true, roles: roles }

Expand Down

0 comments on commit 04a28ae

Please sign in to comment.