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

Send back full dialog on create and edit #32

Merged
merged 1 commit into from
Sep 11, 2017
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
5 changes: 3 additions & 2 deletions app/controllers/api/service_dialogs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def fetch_service_dialogs_content(resource)
end

def create_resource(_type, _id, data)
DialogImportService.new.import(data)
dialog = DialogImportService.new.import(data)
fetch_service_dialogs_content(dialog).first
rescue => e
raise BadRequestError, "Failed to create a new dialog - #{e}"
end
Expand All @@ -31,7 +32,7 @@ def edit_resource(type, id, data)
rescue => err
raise BadRequestError, "Failed to update service dialog - #{err}"
end
service_dialog
fetch_service_dialogs_content(service_dialog).first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a .first here and not above on line 22 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abellotti it returns an array, and it needs to return the first element which is both the service dialog and the content

end

def copy_resource(type, id, data)
Expand Down
12 changes: 8 additions & 4 deletions spec/requests/service_dialogs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@
}

expected = {
'href' => a_string_including(api_service_dialog_url(nil, dialog.compressed_id)),
'id' => dialog.compressed_id,
'label' => 'updated label'
'href' => a_string_including(api_service_dialog_url(nil, dialog.compressed_id)),
'id' => dialog.compressed_id,
'label' => 'updated label',
'dialog_tabs' => a_collection_including(
a_hash_including('label' => 'updated tab label')
)
}

expect do
Expand Down Expand Up @@ -402,7 +405,8 @@ def init_dialog
"results" => [
a_hash_including(
"description" => "Dialog",
"label" => "dialog_label"
"label" => "dialog_label",
"dialog_tabs" => a_collection_including(a_hash_including("description" => "Dialog tab"))
)
]
}
Expand Down