Skip to content

Commit 87fa686

Browse files
committed
[NEP-18619]: Rspec fixes
1 parent 6208ff8 commit 87fa686

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

lib/superset/dashboard/datasets/list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def datasets_details
5050
private
5151

5252
def filter_dataset_ids
53-
@filter_dataset_ids ||= Superset::Dashboard::Filters::List.new(id).perform
53+
@filter_dataset_ids ||= Dashboard::Filters::List.new(id).perform
5454
end
5555

5656
def filter_datasets(filter_dataset_ids_not_used_in_charts)

lib/superset/services/duplicate_dashboard.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,16 @@ def duplicate_source_dashboard_datasets
9494
# reason: there is a bug(or feature) in the SS API where a dataset name must be uniq when duplicating.
9595
# (note however renaming in the GUI to a dup name works fine)
9696
new_dataset_name = "#{dataset[:datasource_name]}-#{target_schema}"
97-
existing_datasets = Dataset::List.new(title_equals: new_dataset_name, schema_equals: source_dataset.schema).result
98-
if existing_dataset.any?
97+
existing_datasets = Superset::Dataset::List.new(title_equals: new_dataset_name, schema_equals: target_schema).result
98+
if existing_datasets.any?
9999
new_dataset_id = existing_datasets[0]["id"] # assuming that we do not name multiple datasets with same name in a single schema
100100
else
101101
new_dataset_id = Superset::Dataset::Duplicate.new(source_dataset_id: dataset[:id], new_dataset_name: new_dataset_name).perform
102+
# update the new dataset with the target schema and target database
103+
Superset::Dataset::UpdateSchema.new(source_dataset_id: new_dataset_id, target_database_id: target_database_id, target_schema: target_schema).perform
102104
end
103-
104105
# keep track of the previous dataset and the matching new dataset_id
105106
dataset_duplication_tracker << { source_dataset_id: dataset[:id], new_dataset_id: new_dataset_id }
106-
107-
# update the new dataset with the target schema and target database
108-
Superset::Dataset::UpdateSchema.new(source_dataset_id: new_dataset_id, target_database_id: target_database_id, target_schema: target_schema).perform
109107
end
110108
end
111109

spec/superset/services/duplicate_dashboard_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,18 @@
107107
context 'with valid params' do
108108
before do
109109
# duplicating the current datasets
110-
expect(Superset::Dataset::Duplicate).to receive(:new).with(source_dataset_id: source_dataset_1, new_dataset_name: "Dataset 1-schema_two").and_return(double(perform: new_dataset_1))
110+
expect(Superset::Dataset::Duplicate).not_to receive(:new).with(source_dataset_id: source_dataset_1, new_dataset_name: "Dataset 1-schema_two")
111111
expect(Superset::Dataset::Duplicate).to receive(:new).with(source_dataset_id: source_dataset_2, new_dataset_name: "Dataset 2-schema_two").and_return(double(perform: new_dataset_2))
112112

113113
# updating the new datasets to point to the target schema and target database
114-
expect(Superset::Dataset::UpdateSchema).to receive(:new).with(source_dataset_id: new_dataset_1, target_database_id: target_database_id, target_schema: target_schema).and_return(double(perform: new_dataset_1))
114+
expect(Superset::Dataset::UpdateSchema).not_to receive(:new).with(source_dataset_id: new_dataset_1, target_database_id: target_database_id, target_schema: target_schema)
115115
expect(Superset::Dataset::UpdateSchema).to receive(:new).with(source_dataset_id: new_dataset_2, target_database_id: target_database_id, target_schema: target_schema).and_return(double(perform: new_dataset_2))
116116

117117
# getting the list of charts for the source dashboard
118118
allow(Superset::Dashboard::Charts::List).to receive(:new).with(source_dashboard_id).and_return(double(result: [{ 'slice_name' => "chart 1", "id" => source_chart_1}, { 'slice_name' => "chart 2", "id" => source_chart_2}])) # , chart_ids: [source_chart_1, source_chart_2]
119119
allow(Superset::Dashboard::Charts::List).to receive(:new).with(new_dashboard_id).and_return(double(result: [{ 'slice_name' => "chart 1", "id" => new_chart_1}, { 'slice_name' => "chart 2", "id" => new_chart_2}]))
120+
allow(Superset::Dataset::List).to receive(:new).with(title_equals: "Dataset 1-schema_two", schema_equals: target_schema).and_return(double(result: [{id: 301}]))
121+
allow(Superset::Dataset::List).to receive(:new).with(title_equals: "Dataset 2-schema_two", schema_equals: target_schema).and_return(double(result: []))
120122

121123
# getting the current dataset_id for the new charts .. still pointing to the old datasets
122124
expect(Superset::Chart::Get).to receive(:new).with(new_chart_1).and_return(double(datasource_id: source_dataset_1))

0 commit comments

Comments
 (0)