Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change dialog import to only use auto_refresh if new triggers are blank #17363

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
end

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