Skip to content

Commit c265b43

Browse files
authored
Merge pull request #30 from Zamyatin-AA/batch_action_collection_fix
fixed batch_action_collection not working with decorators
2 parents 04cdcb9 + d199e28 commit c265b43

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ group :test do
66
gem 'sprockets-rails', '2.3.3'
77
gem 'rails', '~> 5.1'
88
gem 'rspec-rails'
9+
gem 'draper'
910
gem 'activeadmin', '1.0.0'
1011
gem 'sass-rails'
1112
gem 'sqlite3'
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
module ActiveAdminScopedCollectionActions
22
module Controller
3+
COLLECTION_APPLIES = [
4+
:authorization_scope,
5+
:filtering,
6+
:scoping,
7+
:includes,
8+
].freeze
9+
310
def scoped_collection_records
411
selection = params.fetch(:collection_selection, [])
5-
selection.any? ? batch_action_collection.where(resource_class.primary_key => selection) : batch_action_collection
12+
selection.any? ? batch_action_collection(COLLECTION_APPLIES).where(resource_class.primary_key => selection)
13+
: batch_action_collection(COLLECTION_APPLIES)
614
end
715
end
816
end

spec/authors_actions_spec.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@
7878
end
7979

8080

81-
context
81+
context 'perform Delete-action when cheked only one item' do
82+
83+
let(:delete_author) { Author.first }
84+
85+
before do
86+
page.find('#collection_actions_sidebar_section button', text: 'Delete').click
87+
page.find("#batch_action_item_#{delete_author.id}").trigger('click')
88+
page.within ('body>.active_admin_dialog_mass_update_by_filter') do
89+
page.find('button', text: 'OK').click
90+
end
91+
end
92+
93+
it 'delete only cheked author' do
94+
expect(page).to have_css('.flashes .flash.flash_notice')
95+
expect(Author.count).to eq(1)
96+
expect(Author.take.id).not_to eq(delete_author.id)
97+
expect(page).to have_css("#batch_action_item_#{Author.take.id}")
98+
end
99+
100+
end
82101

83102
end

spec/support/admin.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ def add_author_resource(options = {}, &block)
22

33
ActiveAdmin.register Author do
44
config.filters = true
5+
decorate_with AuthorDecorator
56

67
config.scoped_collection_actions_if = -> { true }
78

spec/support/rails_template.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
generate :'active_admin:install --skip-users'
2323
generate :'formtastic:install'
24+
generate :'decorator Author'
2425

2526
# Install active_admin_date_time_datetimepicker assets
2627
inject_into_file "app/assets/stylesheets/active_admin.scss",

0 commit comments

Comments
 (0)