File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -11,20 +11,21 @@ class InvalidParameterError < StandardError; end
11
11
attr_reader :dashboard_ids
12
12
13
13
def initialize ( dashboard_ids : [ ] )
14
- @dashboard_ids = dashboard_ids . sort # delete sequentially
14
+ @dashboard_ids = dashboard_ids # delete sequentially
15
15
end
16
16
17
17
def perform
18
18
raise InvalidParameterError , "dashboard_ids array of integers expected" unless dashboard_ids . is_a? ( Array )
19
19
raise InvalidParameterError , "dashboard_ids array must contain Integer only values" unless dashboard_ids . all? { |item | item . is_a? ( Integer ) }
20
20
# TODO check if dashboard_ids are valid
21
21
22
- dashboard_ids . each do |dashboard_id |
22
+ dashboard_ids . sort . each do |dashboard_id |
23
23
logger . info ( "Dashboard Id: #{ dashboard_id . to_s } Attempting CASCADE delete of dashboard, charts, datasets" )
24
24
delete_datasets ( dashboard_id )
25
25
delete_charts ( dashboard_id )
26
26
delete_dashboard ( dashboard_id )
27
27
end
28
+ true
28
29
end
29
30
30
31
private
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ RSpec . describe Superset ::Dashboard ::BulkDeleteCascade do
4
+ subject { described_class . new ( dashboard_ids : dashboard_ids ) }
5
+ let ( :dashboard_ids ) { nil }
6
+
7
+ describe '.perform' do
8
+ context 'when dashboard_ids is not present' do
9
+ it 'raises an error' do
10
+ expect { subject . perform } . to raise_error ( Superset ::Dashboard ::BulkDeleteCascade ::InvalidParameterError , "dashboard_ids array of integers expected" )
11
+ end
12
+ end
13
+
14
+ context 'when dashboard_ids contains non integer values' do
15
+ let ( :dashboard_ids ) { [ 1 , 'string' ] }
16
+
17
+ it 'raises an error' do
18
+ expect { subject . perform } . to raise_error ( Superset ::Dashboard ::BulkDeleteCascade ::InvalidParameterError , "dashboard_ids array must contain Integer only values" )
19
+ end
20
+ end
21
+
22
+ context 'when dashboard_ids are valid' do
23
+ let ( :dashboard_ids ) { [ 1 ] }
24
+
25
+ before do
26
+ allow ( Superset ::Dashboard ::Datasets ::List ) . to receive ( :new ) . with ( 1 ) . and_return ( double ( datasets_details : [ { id : 11 } , { id : 12 } ] ) )
27
+ allow ( Superset ::Dataset ::BulkDelete ) . to receive ( :new ) . with ( dataset_ids : [ 11 , 12 ] ) . and_return ( double ( perform : true ) )
28
+
29
+ allow ( Superset ::Dashboard ::Charts ::List ) . to receive ( :new ) . with ( 1 ) . and_return ( double ( chart_ids : [ 21 , 22 ] ) )
30
+ allow ( Superset ::Chart ::BulkDelete ) . to receive ( :new ) . with ( chart_ids : [ 21 , 22 ] ) . and_return ( double ( perform : true ) )
31
+
32
+ allow ( Superset ::Dashboard ::Delete ) . to receive ( :new ) . with ( dashboard_id : 1 , confirm_zero_charts : true ) . and_return ( double ( perform : true ) )
33
+ end
34
+
35
+ it 'bulk deletes related charts, datasets and the dashboard' do
36
+ expect ( subject . perform ) . to eq ( true )
37
+ end
38
+ end
39
+ end
40
+ end
You can’t perform that action at this time.
0 commit comments