Skip to content

Commit ba36923

Browse files
committed
adds spec
1 parent 539cac6 commit ba36923

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/superset/dashboard/bulk_delete_cascade.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ class InvalidParameterError < StandardError; end
1111
attr_reader :dashboard_ids
1212

1313
def initialize(dashboard_ids: [])
14-
@dashboard_ids = dashboard_ids.sort # delete sequentially
14+
@dashboard_ids = dashboard_ids # delete sequentially
1515
end
1616

1717
def perform
1818
raise InvalidParameterError, "dashboard_ids array of integers expected" unless dashboard_ids.is_a?(Array)
1919
raise InvalidParameterError, "dashboard_ids array must contain Integer only values" unless dashboard_ids.all? { |item| item.is_a?(Integer) }
2020
# TODO check if dashboard_ids are valid
2121

22-
dashboard_ids.each do |dashboard_id|
22+
dashboard_ids.sort.each do |dashboard_id|
2323
logger.info("Dashboard Id: #{dashboard_id.to_s} Attempting CASCADE delete of dashboard, charts, datasets")
2424
delete_datasets(dashboard_id)
2525
delete_charts(dashboard_id)
2626
delete_dashboard(dashboard_id)
2727
end
28+
true
2829
end
2930

3031
private
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

0 commit comments

Comments
 (0)