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,7 +57,9 @@ require_relative '../../find_by_contents' | ||
| 57 | options.merge!(fields.symbolize_keys.slice(:only, :except)) | 57 | options.merge!(fields.symbolize_keys.slice(:only, :except)) |
| 58 | end | 58 | end |
| 59 | rescue | 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 | end | 63 | end |
| 62 | end | 64 | end |
| 63 | present model, options | 65 | present model, options |
test/unit/api/helpers_test.rb
| @@ -226,11 +226,18 @@ class APIHelpersTest < ActiveSupport::TestCase | @@ -226,11 +226,18 @@ class APIHelpersTest < ActiveSupport::TestCase | ||
| 226 | 226 | ||
| 227 | should 'fallback to array when fields parameter is not a json when calling present partial' do | 227 | should 'fallback to array when fields parameter is not a json when calling present partial' do |
| 228 | model = mock | 228 | model = mock |
| 229 | - params[:fields] = 'name' | 229 | + params[:fields] = ['name'] |
| 230 | expects(:present).with(model, {:only => ['name']}) | 230 | expects(:present).with(model, {:only => ['name']}) |
| 231 | present_partial(model, {}) | 231 | present_partial(model, {}) |
| 232 | end | 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 | should 'accept json as fields parameter when calling present partial' do | 241 | should 'accept json as fields parameter when calling present partial' do |
| 235 | model = mock | 242 | model = mock |
| 236 | params[:fields] = {only: [:name, {user: [:login]}]}.to_json | 243 | params[:fields] = {only: [:name, {user: [:login]}]}.to_json |