diff --git a/app/models/dialog.rb b/app/models/dialog.rb index 1d2de89cacb..1450c1f8229 100644 --- a/app/models/dialog.rb +++ b/app/models/dialog.rb @@ -123,19 +123,21 @@ def content(target = nil, resource_action = nil, all_attributes = false) # Creates a new item without an ID, # Removes any items not passed in the content. def update_tabs(tabs) - updated_tabs = [] - tabs.each do |dialog_tab| - if dialog_tab.key?('id') - DialogTab.find(self.class.uncompress_id(dialog_tab['id'])).tap do |tab| - tab.update_attributes(dialog_tab.except('dialog_groups')) - tab.update_dialog_groups(dialog_tab['dialog_groups']) - updated_tabs << tab + transaction do + updated_tabs = [] + tabs.each do |dialog_tab| + if dialog_tab.key?('id') + DialogTab.find(self.class.uncompress_id(dialog_tab['id'])).tap do |tab| + tab.update_attributes(dialog_tab.except('id', 'href', 'dialog_id', 'dialog_groups')) + tab.update_dialog_groups(dialog_tab['dialog_groups']) + updated_tabs << tab + end + else + updated_tabs << DialogImportService.new.build_dialog_tabs('dialog_tabs' => [dialog_tab]).first end - else - updated_tabs << DialogImportService.new.build_dialog_tabs('dialog_tabs' => [dialog_tab]).first end + self.dialog_tabs = updated_tabs end - self.dialog_tabs = updated_tabs end def deep_copy(new_attributes = {}) diff --git a/app/models/dialog_group.rb b/app/models/dialog_group.rb index 55eb52148e3..d9e01203129 100644 --- a/app/models/dialog_group.rb +++ b/app/models/dialog_group.rb @@ -22,7 +22,7 @@ def update_dialog_fields(fields) DialogField.find(self.class.uncompress_id(field['id'])).tap do |dialog_field| resource_action_fields = field.delete('resource_action') || {} update_resource_fields(resource_action_fields, dialog_field) - dialog_field.update_attributes(field) + dialog_field.update_attributes(field.except('id', 'href', 'dialog_group_id')) updated_fields << dialog_field end else diff --git a/app/models/dialog_tab.rb b/app/models/dialog_tab.rb index 2b576995495..2ce076385cb 100644 --- a/app/models/dialog_tab.rb +++ b/app/models/dialog_tab.rb @@ -35,7 +35,7 @@ def update_dialog_groups(groups) groups.each do |group| if group.key?('id') DialogGroup.find(self.class.uncompress_id(group['id'])).tap do |dialog_group| - dialog_group.update_attributes(group.except('dialog_fields')) + dialog_group.update_attributes(group.except('id', 'href', 'dialog_tab_id', 'dialog_fields')) dialog_group.update_dialog_fields(group['dialog_fields']) updated_groups << dialog_group end diff --git a/spec/models/dialog_spec.rb b/spec/models/dialog_spec.rb index 9d8e0383f2c..be77a0741b8 100644 --- a/spec/models/dialog_spec.rb +++ b/spec/models/dialog_spec.rb @@ -284,13 +284,16 @@ let(:updated_content) do [ { - 'id' => dialog_tab.first.id, + 'id' => dialog_tab.first.compressed_id, 'label' => 'updated_label', 'dialog_groups' => [ - { 'id' => dialog_group.first.id, + { 'id' => dialog_group.first.compressed_id, + 'dialog_tab_id' => dialog_tab.first.compressed_id, 'dialog_fields' => [{ - 'id' => dialog_field.first.id}] }, + 'id' => dialog_field.first.id, + 'dialog_group_id' => dialog_group.first.compressed_id + }] }, { 'label' => 'group 2', 'dialog_fields' => [{