diff --git a/app/models/dialog.rb b/app/models/dialog.rb index 2924e036840..1d2de89cacb 100644 --- a/app/models/dialog.rb +++ b/app/models/dialog.rb @@ -126,7 +126,7 @@ def update_tabs(tabs) updated_tabs = [] tabs.each do |dialog_tab| if dialog_tab.key?('id') - DialogTab.find(dialog_tab['id']).tap do |tab| + 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 diff --git a/app/models/dialog_group.rb b/app/models/dialog_group.rb index 93a182b7215..55eb52148e3 100644 --- a/app/models/dialog_group.rb +++ b/app/models/dialog_group.rb @@ -19,7 +19,7 @@ def update_dialog_fields(fields) fields.each do |field| field['options'].try(:symbolize_keys!) if field.key?('id') - DialogField.find(field['id']).tap do |dialog_field| + 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) diff --git a/app/models/dialog_tab.rb b/app/models/dialog_tab.rb index b350dd1e1df..2b576995495 100644 --- a/app/models/dialog_tab.rb +++ b/app/models/dialog_tab.rb @@ -34,7 +34,7 @@ def update_dialog_groups(groups) updated_groups = [] groups.each do |group| if group.key?('id') - DialogGroup.find(group['id']).tap do |dialog_group| + DialogGroup.find(self.class.uncompress_id(group['id'])).tap do |dialog_group| dialog_group.update_attributes(group.except('dialog_fields')) dialog_group.update_dialog_fields(group['dialog_fields']) updated_groups << dialog_group diff --git a/spec/models/dialog_spec.rb b/spec/models/dialog_spec.rb index f08cce389ba..9d8e0383f2c 100644 --- a/spec/models/dialog_spec.rb +++ b/spec/models/dialog_spec.rb @@ -346,6 +346,37 @@ end.to change(dialog.reload.dialog_tabs, :count).by(-1) end end + + context 'compresssed ids' do + let(:updated_content) do + [ + { + 'id' => dialog_tab.first.id, + 'label' => 'updated_label_foo', + 'dialog_groups' => [ + { 'id' => dialog_group.first.compressed_id, + 'label' => 'updated_label_bar', + 'dialog_fields' => + [{'id' => dialog_field.first.compressed_id, 'label' => 'updated_label_baz'}]} + ] + } + ] + end + + before do + dialog.dialog_tabs << FactoryGirl.create(:dialog_tab) + end + + it 'updates the content' do + dialog.update_tabs(updated_content) + + tab = dialog.dialog_tabs.first + group = tab.dialog_groups.first + expect(tab.label).to eq('updated_label_foo') + expect(group.label).to eq('updated_label_bar') + expect(group.dialog_fields.first.label).to eq('updated_label_baz') + end + end end context "#dialog_fields" do diff --git a/spec/requests/api/service_dialogs_spec.rb b/spec/requests/api/service_dialogs_spec.rb index 55f4e7acb16..ce403c4605a 100644 --- a/spec/requests/api/service_dialogs_spec.rb +++ b/spec/requests/api/service_dialogs_spec.rb @@ -122,13 +122,13 @@ 'label' => 'updated label', 'content' => { 'dialog_tabs' => [ - 'id' => dialog_tab.id, + 'id' => dialog_tab.compressed_id, 'label' => 'updated tab label', 'dialog_groups' => [ { - 'id' => dialog_group.id, + 'id' => dialog_group.compressed_id, 'dialog_fields' => [ - { 'id' => dialog_field.id } + { 'id' => dialog_field.compressed_id } ] } ]