[Git][noosfero/noosfero][master] 2 commits: Fix problem rendering Enviroment update errors in API
Leandro Nunes
gitlab at mg.gitlab.com
Mon Jul 24 07:49:47 BRT 2017
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
7d7914cb by Evandro Jr at 2017-07-24T10:49:16+00:00
Fix problem rendering Enviroment update errors in API
- - - - -
82337b58 by Leandro Nunes at 2017-07-24T10:49:16+00:00
Merge branch 'render_environment_model_errors' into 'master'
Fix problem rendering Enviroment update errors in API
See merge request !1279
- - - - -
2 changed files:
- app/api/v1/environments.rb
- test/api/environment_test.rb
Changes:
=====================================
app/api/v1/environments.rb
=====================================
--- a/app/api/v1/environments.rb
+++ b/app/api/v1/environments.rb
@@ -29,9 +29,13 @@ module Api
authenticate!
environment = Environment.find_by(id: params[:id])
return forbidden! unless is_admin?(environment)
- environment.update_attributes!(params[:environment])
- status Api::Status::DEPRECATED if path == 'environment'
- present_partial environment, with: Entities::Environment, is_admin: is_admin?(environment), current_person: current_person
+ begin
+ environment.update_attributes!(params[:environment])
+ status Api::Status::DEPRECATED if path == 'environment'
+ present_partial environment, with: Entities::Environment, is_admin: is_admin?(environment), current_person: current_person
+ rescue ActiveRecord::RecordInvalid
+ render_model_errors!(environment.errors)
+ end
end
end
=====================================
test/api/environment_test.rb
=====================================
--- a/test/api/environment_test.rb
+++ b/test/api/environment_test.rb
@@ -249,4 +249,15 @@ class EnvironmentTest < ActiveSupport::TestCase
assert_includes environment.available_blocks(person), CommunitiesBlock
end
+ should 'get detailed error message from environment' do
+ login_api
+ environment = Environment.default
+ environment.add_admin(person)
+
+ params[:environment] = {name: ''}
+ post "/api/v1/environments/#{environment.id}?#{params.to_query}"
+ assert_equal last_response.status, 422
+ assert_equal last_response.body, '{"errors":{"name":[{"error":"blank","full_message":"Name can\'t be blank"}]}}'
+ end
+
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/43b34a84179105cc8d046432e056d665926f98f3...82337b585b9d472ec3faa3d67a22629c7fdffdf4
---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/43b34a84179105cc8d046432e056d665926f98f3...82337b585b9d472ec3faa3d67a22629c7fdffdf4
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170724/f62409bc/attachment-0001.html>
More information about the Noosfero-dev
mailing list