Commit ce08b7cceaf76a1d3b57c4994a37ef43e9f07da2
1 parent
c27458d0
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
should filter person fieldws return by fields parameters
Showing
4 changed files
with
25 additions
and
40 deletions
Show diff stats
Gemfile.lock
... | ... | @@ -40,11 +40,8 @@ GEM |
40 | 40 | multi_json (~> 1.0) |
41 | 41 | acts-as-taggable-on (3.4.4) |
42 | 42 | activerecord (>= 3.2, < 5) |
43 | - addressable (2.3.8) | |
43 | + ambry (0.3.1) | |
44 | 44 | api-pagination (4.1.1) |
45 | - api_smith (1.3.0) | |
46 | - hashie (>= 1.0, < 3.0) | |
47 | - httparty | |
48 | 45 | arel (3.0.3) |
49 | 46 | axiom-types (0.1.1) |
50 | 47 | descendants_tracker (~> 0.0.4) |
... | ... | @@ -62,8 +59,6 @@ GEM |
62 | 59 | chronic (0.10.2) |
63 | 60 | coercible (1.0.0) |
64 | 61 | descendants_tracker (~> 0.0.1) |
65 | - css_parser (1.3.7) | |
66 | - addressable | |
67 | 62 | cucumber (1.0.6) |
68 | 63 | builder (>= 2.1.2) |
69 | 64 | diff-lcs (>= 1.1.2) |
... | ... | @@ -89,10 +84,6 @@ GEM |
89 | 84 | actionmailer (>= 3.0.4) |
90 | 85 | activesupport (>= 3.0.4) |
91 | 86 | execjs (2.6.0) |
92 | - faraday (0.9.2) | |
93 | - multipart-post (>= 1.2, < 3) | |
94 | - faraday_middleware (0.10.0) | |
95 | - faraday (>= 0.7.4, < 0.10) | |
96 | 87 | fast_gettext (0.6.12) |
97 | 88 | ffi (1.9.10) |
98 | 89 | gettext (2.2.1) |
... | ... | @@ -116,11 +107,8 @@ GEM |
116 | 107 | grape-swagger (0.10.2) |
117 | 108 | grape (>= 0.8.0) |
118 | 109 | grape-entity |
119 | - hashie (2.1.2) | |
110 | + hashie (3.4.2) | |
120 | 111 | hike (1.2.3) |
121 | - httparty (0.12.0) | |
122 | - json (~> 1.8) | |
123 | - multi_xml (>= 0.5.2) | |
124 | 112 | i18n (0.7.0) |
125 | 113 | ice_nine (0.11.1) |
126 | 114 | journey (1.0.4) |
... | ... | @@ -128,7 +116,6 @@ GEM |
128 | 116 | kgio (2.10.0) |
129 | 117 | kramdown (1.9.0) |
130 | 118 | libv8 (3.16.14.11) |
131 | - link_header (0.0.8) | |
132 | 119 | liquid (3.0.6) |
133 | 120 | locale (2.0.9) |
134 | 121 | magic (0.2.9) |
... | ... | @@ -136,6 +123,8 @@ GEM |
136 | 123 | mail (2.5.4) |
137 | 124 | mime-types (~> 1.16) |
138 | 125 | treetop (~> 1.4.8) |
126 | + merit (2.3.2) | |
127 | + ambry (~> 0.3.0) | |
139 | 128 | metaclass (0.0.4) |
140 | 129 | mime-types (1.25.1) |
141 | 130 | mini_portile (0.6.2) |
... | ... | @@ -144,13 +133,8 @@ GEM |
144 | 133 | metaclass (~> 0.0.1) |
145 | 134 | multi_json (1.11.2) |
146 | 135 | multi_xml (0.5.5) |
147 | - multipart-post (2.0.0) | |
148 | 136 | nokogiri (1.6.6.2) |
149 | 137 | mini_portile (~> 0.6.0) |
150 | - oai (0.3.1) | |
151 | - builder (>= 2.0.0) | |
152 | - faraday | |
153 | - faraday_middleware | |
154 | 138 | pg (0.13.2) |
155 | 139 | polyglot (0.3.5) |
156 | 140 | rack (1.4.7) |
... | ... | @@ -187,24 +171,12 @@ GEM |
187 | 171 | thor (>= 0.14.6, < 2.0) |
188 | 172 | raindrops (0.15.0) |
189 | 173 | rake (10.4.2) |
190 | - rdf (1.1.17.1) | |
191 | - link_header (~> 0.0, >= 0.0.8) | |
192 | - rdf-virtuoso (0.1.6) | |
193 | - api_smith (~> 1.3.0) | |
194 | - httparty (~> 0.12.0) | |
195 | - rdf (~> 1.1.0) | |
196 | 174 | rdoc (3.12.2) |
197 | 175 | json (~> 1.4) |
198 | 176 | ref (2.0.0) |
199 | 177 | rest-client (1.6.9) |
200 | 178 | mime-types (~> 1.16) |
201 | 179 | rmagick (2.13.4) |
202 | - roadie (3.0.5) | |
203 | - css_parser (~> 1.3.4) | |
204 | - nokogiri (~> 1.6.0) | |
205 | - roadie-rails (1.0.6) | |
206 | - railties (>= 3.0, < 4.3) | |
207 | - roadie (~> 3.0) | |
208 | 180 | rspec (2.14.1) |
209 | 181 | rspec-core (~> 2.14.0) |
210 | 182 | rspec-expectations (~> 2.14.0) |
... | ... | @@ -297,22 +269,18 @@ DEPENDENCIES |
297 | 269 | kramdown |
298 | 270 | liquid (~> 3.0.3) |
299 | 271 | locale (~> 2.0.5) |
272 | + merit (~> 2.3.1) | |
300 | 273 | minitest (~> 3.2.0) |
301 | 274 | mocha (~> 1.1.0) |
302 | 275 | nokogiri (~> 1.6.0) |
303 | - oai (= 0.3.1) | |
304 | 276 | pg (~> 0.13.2) |
305 | 277 | rack-contrib |
306 | 278 | rack-cors |
307 | 279 | rails (~> 3.2.22) |
308 | 280 | rails_autolink (~> 1.1.5) |
309 | 281 | rake |
310 | - rdf | |
311 | - rdf-virtuoso | |
312 | 282 | rest-client (~> 1.6.7) |
313 | 283 | rmagick (~> 2.13.1) |
314 | - roadie (= 3.0.5) | |
315 | - roadie-rails | |
316 | 284 | rspec (~> 2.14.0) |
317 | 285 | rspec-rails (~> 2.14.1) |
318 | 286 | ruby-feedparser (~> 0.7) | ... | ... |
lib/noosfero/api/entities.rb
... | ... | @@ -52,7 +52,9 @@ module Noosfero |
52 | 52 | end |
53 | 53 | |
54 | 54 | class Profile < Entity |
55 | - expose :identifier, :name, :id | |
55 | + expose :id | |
56 | + expose :identifier | |
57 | + expose :name | |
56 | 58 | expose :created_at, :format_with => :timestamp |
57 | 59 | expose :updated_at, :format_with => :timestamp |
58 | 60 | expose :image, :using => Image | ... | ... |
lib/noosfero/api/v1/people.rb
... | ... | @@ -33,12 +33,12 @@ module Noosfero |
33 | 33 | get do |
34 | 34 | people = select_filtered_collection_of(environment, 'people', params) |
35 | 35 | people = people.visible_for_person(current_person) |
36 | - present people, :with => Entities::Person | |
36 | + present people, :with => Entities::Person, :fields => params[:fields] | |
37 | 37 | end |
38 | 38 | |
39 | 39 | desc "Return the logged user information" |
40 | 40 | get "/me" do |
41 | - present current_person, :with => Entities::Person | |
41 | + present current_person, :with => Entities::Person, :fields => params[:fields] | |
42 | 42 | end |
43 | 43 | |
44 | 44 | desc "Return the person information" | ... | ... |
test/unit/api/people_test.rb
... | ... | @@ -47,12 +47,27 @@ class PeopleTest < ActiveSupport::TestCase |
47 | 47 | assert_equal some_person.id, json['person']['id'] |
48 | 48 | end |
49 | 49 | |
50 | + should 'people endpoint filter by fields parameter' do | |
51 | + get "/api/v1/people?#{params.to_query}&fields=name" | |
52 | + json = JSON.parse(last_response.body) | |
53 | + expected = {'people' => [{'name' => person.name}]} | |
54 | + assert_equal expected, json | |
55 | + end | |
56 | + | |
57 | + | |
50 | 58 | should 'get logged person' do |
51 | 59 | get "/api/v1/people/me?#{params.to_query}" |
52 | 60 | json = JSON.parse(last_response.body) |
53 | 61 | assert_equal person.id, json['person']['id'] |
54 | 62 | end |
55 | 63 | |
64 | + should 'me endpoint filter by fields parameter' do | |
65 | + get "/api/v1/people/me?#{params.to_query}&fields=name" | |
66 | + json = JSON.parse(last_response.body) | |
67 | + expected = {'person' => {'name' => person.name}} | |
68 | + assert_equal expected, json | |
69 | + end | |
70 | + | |
56 | 71 | should 'not get invisible person' do |
57 | 72 | person = fast_create(Person, :visible => false) |
58 | 73 | ... | ... |