[Git][noosfero/noosfero][master] 2 commits: Fix API return to return the model errors when password save fails

Victor Costa gitlab at mg.gitlab.com
Tue May 23 11:26:16 BRT 2017


Victor Costa pushed to branch master at Noosfero / noosfero


Commits:
539805cb by Josafá Souza Jr at 2017-05-23T10:29:46-03:00
Fix API return to return the model errors when password save fails

- - - - -
72067239 by Victor Costa at 2017-05-23T14:25:54+00:00
Merge branch 'fix-new-password-errors' into 'master'

Fix API return to return the model errors when password save fails

See merge request !1213
- - - - -


2 changed files:

- app/api/v1/session.rb
- test/api/session_test.rb


Changes:

=====================================
app/api/v1/session.rb
=====================================
--- a/app/api/v1/session.rb
+++ b/app/api/v1/session.rb
@@ -150,6 +150,8 @@ module Api
           change_password.update_attributes!(:password => params[:password], :password_confirmation => params[:password_confirmation])
           change_password.finish
           present change_password.requestor.user, :with => Entities::UserLogin, :current_person => current_person
+        rescue ActiveRecord::RecordInvalid => ex
+          render_model_errors!(change_password.errors)
         rescue Exception => ex
           render_api_error!(ex.message, Api::Status::BAD_REQUEST)
         end


=====================================
test/api/session_test.rb
=====================================
--- a/test/api/session_test.rb
+++ b/test/api/session_test.rb
@@ -179,9 +179,8 @@ class SessionTest < ActiveSupport::TestCase
     assert_equal Task::Status::ACTIVE, task.reload.status
     assert !user.reload.authenticated?('secret')
     json = JSON.parse(last_response.body)
-    assert_match /doesn't match/, json['message']
-
-    assert_equal 400, last_response.status
+    assert_match /doesn't match/, json['errors']['password_confirmation'].first['full_message']
+    assert_equal 422, last_response.status
   end
 
   should 'render not found when provide a wrong code on password change' do



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/d9a85f0303db178305eb07ae4f9b1d92db302b24...720672396aae9de83ff68ccf7a0e159f6d21a93c

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/d9a85f0303db178305eb07ae4f9b1d92db302b24...720672396aae9de83ff68ccf7a0e159f6d21a93c
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/20170523/6aa03a50/attachment-0001.html>


More information about the Noosfero-dev mailing list