Commit b7f8d123cb462e128d93e8c66a4fa4e52b633dac
Exists in
production-vendorized
and in
1 other branch
Merge branch 'staging' into production
Showing
2 changed files
with
11 additions
and
2 deletions
Show diff stats
lib/noosfero/api/helpers.rb
| ... | ... | @@ -57,7 +57,9 @@ require_relative '../../find_by_contents' |
| 57 | 57 | options.merge!(fields.symbolize_keys.slice(:only, :except)) |
| 58 | 58 | end |
| 59 | 59 | rescue |
| 60 | - options[:only] = Array.wrap(params[:fields]) | |
| 60 | + fields = params[:fields] | |
| 61 | + fields = fields.split(',') if fields.kind_of?(String) | |
| 62 | + options[:only] = Array.wrap(fields) | |
| 61 | 63 | end |
| 62 | 64 | end |
| 63 | 65 | present model, options | ... | ... |
test/unit/api/helpers_test.rb
| ... | ... | @@ -226,11 +226,18 @@ class APIHelpersTest < ActiveSupport::TestCase |
| 226 | 226 | |
| 227 | 227 | should 'fallback to array when fields parameter is not a json when calling present partial' do |
| 228 | 228 | model = mock |
| 229 | - params[:fields] = 'name' | |
| 229 | + params[:fields] = ['name'] | |
| 230 | 230 | expects(:present).with(model, {:only => ['name']}) |
| 231 | 231 | present_partial(model, {}) |
| 232 | 232 | end |
| 233 | 233 | |
| 234 | + should 'fallback to comma separated string when fields parameter is not an array when calling present partial' do | |
| 235 | + model = mock | |
| 236 | + params[:fields] = 'name,description' | |
| 237 | + expects(:present).with(model, {:only => ['name', 'description']}) | |
| 238 | + present_partial(model, {}) | |
| 239 | + end | |
| 240 | + | |
| 234 | 241 | should 'accept json as fields parameter when calling present partial' do |
| 235 | 242 | model = mock |
| 236 | 243 | params[:fields] = {only: [:name, {user: [:login]}]}.to_json | ... | ... |