Skip to content

Commit

Permalink
Merge pull request #17363 from d-m-u/change_import_field_responders_t…
Browse files Browse the repository at this point in the history
…o_not_use_old_if_new_exist_on_dialog

Change dialog import to only use auto_refresh if new triggers are blank
(cherry picked from commit f8e4a47)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1573254
  • Loading branch information
gmcculloug authored and simaishi committed Apr 30, 2018
1 parent 8545d9a commit 0e25cfd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
7 changes: 3 additions & 4 deletions lib/services/dialog_import_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,15 @@ def import_from_dialogs(dialogs)
dialog.except!(:blueprint_id, 'blueprint_id') # blueprint_id might appear in some old dialogs, but no longer exists
new_or_existing_dialog = Dialog.where(:label => dialog["label"]).first_or_create
dialog['id'] = new_or_existing_dialog.id
associations_to_be_created = build_association_list(dialog)
new_associations = build_association_list(dialog)
new_or_existing_dialog.update_attributes(
dialog.merge(
"dialog_tabs" => build_dialog_tabs(dialog),
"resource_actions" => build_resource_actions(dialog)
)
)
old_associations = build_old_association_list(new_or_existing_dialog.dialog_fields).flatten
association_list = (associations_to_be_created + old_associations).reject(&:blank?)
build_associations(new_or_existing_dialog, association_list)
association_list = new_associations.reject(&:blank?).present? ? new_associations : build_old_association_list(new_or_existing_dialog.dialog_fields).flatten
build_associations(new_or_existing_dialog, association_list.reject(&:blank?))
end
rescue DialogFieldImporter::InvalidDialogFieldTypeError
raise
Expand Down
32 changes: 28 additions & 4 deletions spec/lib/services/dialog_import_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,43 @@
dialog_import_service.import_all_service_dialogs_from_yaml_file("filename")
end

it "sets associations" do
it "sets only new associations when both new and old style exist" do
expect do
dialog_import_service.import_all_service_dialogs_from_yaml_file("filename")
end.to change(DialogFieldAssociation, :count).by(2)
end.to change(DialogFieldAssociation, :count).by(1)

expect(DialogField.find(DialogFieldAssociation.last.respond_id).name).to eq("df_with_old_responder")
expect(DialogField.find(DialogFieldAssociation.last.trigger_id).name).to eq("df_with_old_trigger")
expect(DialogField.find(DialogFieldAssociation.first.trigger_id).name).to eq("dialog_field_2")
expect(DialogField.find(DialogFieldAssociation.first.respond_id).name).to eq("dialog_field")
end
end
end

describe "association creation" do
context "with only old defunct associations present" do
before do
fields = []
built_dialog_field3 = DialogField.create(:name => "df_with_old_trigger", :trigger_auto_refresh => true, :position => 0)
built_dialog_field4 = DialogField.create(:name => "df_with_old_responder", :auto_refresh => true, :position => 1)
fields << built_dialog_field3
fields << built_dialog_field4
allow(dialog_field_importer).to receive(:import_field).and_return(built_dialog_field3, built_dialog_field4)
group = [{"label" => "New Box", "dialog_fields" => fields, :position => 1}]
tab = [{"label" => "New Tab", "dialog_groups" => group, :position => 2}]
dialog = [{"label" => "Test", "dialog_tabs" => tab}]
allow(YAML).to receive(:load_file).with("filename").and_return(dialog)
end

it "sets only old associations when only old style exists" do
expect do
dialog_import_service.import_all_service_dialogs_from_yaml_file("filename")
end.to change(DialogFieldAssociation, :count).by(1)

expect(DialogField.find(DialogFieldAssociation.first.trigger_id).name).to eq("df_with_old_trigger")
expect(DialogField.find(DialogFieldAssociation.first.respond_id).name).to eq("df_with_old_responder")
end
end
end

describe "#import_service_dialogs" do
include_context "DialogImportService dialog setup"

Expand Down

0 comments on commit 0e25cfd

Please sign in to comment.