Skip to content

Commit

Permalink
Merge pull request #15619 from jntullo/update_dialogs_with_compressed_id
Browse files Browse the repository at this point in the history
Allow compressed ids when updating a service dialog
  • Loading branch information
gtanzillo authored Jul 21, 2017
2 parents b04065e + a83b583 commit bc49aa0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/dialog_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/models/dialog_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions spec/models/dialog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/requests/api/service_dialogs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]
}
]
Expand Down

0 comments on commit bc49aa0

Please sign in to comment.