[Git][noosfero/noosfero][master] 3 commits: should not throw exception if there is no friends on /profile/:id/friends enpoint

Victor Costa gitlab at mg.gitlab.com
Thu Jul 6 13:26:55 BRT 2017


Victor Costa pushed to branch master at Noosfero / noosfero


Commits:
57215ffb by Leandro Nunes dos Santos at 2017-07-06T11:43:33-03:00
should not throw exception if there is no friends on /profile/:id/friends enpoint

- - - - -
c2820f76 by Leandro Nunes dos Santos at 2017-07-06T12:15:28-03:00
pass parameters correctly to request

- - - - -
f43d2a88 by Victor Costa at 2017-07-06T16:25:57+00:00
Merge branch 'avoid-exception-in-friends-enpoint' into 'master'

should not throw exception if there is no friends on /profile/:id/friends enpoint

See merge request !1280
- - - - -


2 changed files:

- app/api/helpers.rb
- test/api/people_test.rb


Changes:

=====================================
app/api/helpers.rb
=====================================
--- a/app/api/helpers.rb
+++ b/app/api/helpers.rb
@@ -267,7 +267,7 @@ module Api
           field_name, direction = params[:order].split(' ')
           assoc_class = extract_associated_classname(object, method_or_relation)
           if !field_name.blank? and assoc_class
-            if assoc_class.attribute_names.include? field_name
+            if assoc_class.respond_to?(:attribute_names) && (assoc_class.attribute_names.include? field_name)
               if direction.present? and ['ASC','DESC'].include? direction.upcase
                 order = "#{field_name} #{direction.upcase}"
               end


=====================================
test/api/people_test.rb
=====================================
--- a/test/api/people_test.rb
+++ b/test/api/people_test.rb
@@ -219,6 +219,30 @@ class PeopleTest < ActiveSupport::TestCase
     assert_not_includes friends, invisible_friend.id
   end
 
+  should 'list person friends ordered' do
+    login_api
+    p2 = fast_create(Person, :name => 'Person 2')
+    p4 = fast_create(Person, :name => 'Person 1')
+    p1 = fast_create(Person, :name => 'Person 4')
+    p3 = fast_create(Person, :name => 'Person 3')
+    person.add_friend(p1)
+    person.add_friend(p2)
+    person.add_friend(p3)
+    person.add_friend(p4)
+    params[:order] = 'name ASC'
+    get "/api/v1/people/#{person.id}/friends?#{params.to_query}"
+    expected_response = [p4.id, p2.id, p3.id, p1.id]
+    assert_equal json_response_ids, expected_response
+  end
+
+  should 'list person friends ordered for person without friends' do
+    login_api
+    params[:order] = 'name ASC'
+    get "/api/v1/people/#{person.id}/friends?#{params.to_query}"
+    expected_response = []
+    assert_equal json_response_ids, expected_response
+  end
+
   should 'create a person' do
     login_api
     login = 'some'



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/253a0b2e5780caf2f8eaddd23c93ca078f79b751...f43d2a8878f8d4bd98e5f302c60d0fa633ca9892

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/253a0b2e5780caf2f8eaddd23c93ca078f79b751...f43d2a8878f8d4bd98e5f302c60d0fa633ca9892
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/20170706/4f6c9800/attachment-0001.html>


More information about the Noosfero-dev mailing list