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