Skip to content

Commit bb6ec9d

Browse files
authored
Merge pull request #47 from qoqa/add-confirm-proc
Support proc in confirm option
2 parents badd13b + 6b04454 commit bb6ec9d

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/active_admin_scoped_collection_actions/resource_extension.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def scoped_collection_actions_sidebar_section
6868
b_data[:inputs] = options[:form].is_a?(Proc) ? options[:form].call : options[:form]
6969
end
7070
b_data[:confirm] = options.fetch(:confirm, I18n.t('active_admin_scoped_collection_actions.confirm_action_message'))
71+
b_data[:confirm] = b_data[:confirm].call if b_data[:confirm].is_a?(Proc)
7172
b_options[:data] = b_data.to_json
7273
button b_title, b_options
7374
end

spec/posts_actions_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,16 @@
4141
end
4242
end
4343

44+
context 'scoped collection action DELETE' do
45+
before do
46+
page.find('#collection_actions_sidebar_section button', text: 'Delete').click
47+
end
48+
49+
context 'title' do
50+
it 'has predefined confirmation title' do
51+
expect(page).to have_css('.active_admin_dialog_mass_update_by_filter', text: 'Custom text for confirm delete all?')
52+
end
53+
end
54+
end
55+
4456
end

spec/support/admin.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def add_post_resource(options = {}, &block)
4545
author_id: Author.all.map { |author| [author.name, author.id] }
4646
}
4747
}
48+
scoped_collection_action :scoped_collection_destroy,
49+
title: 'Delete',
50+
confirm: -> { 'Custom text for confirm delete all?' }
4851
end
4952

5053
Rails.application.reload_routes!

0 commit comments

Comments
 (0)