Commit 64577e79450ddeb7674bec87a10decf445b414d4

Authored by Leandro Santos
1 parent e9a85337

changing api parameter categories_ids by category_ids

lib/noosfero/api/helpers.rb
... ... @@ -143,9 +143,6 @@ require 'grape'
143 143 else
144 144 articles = articles.published
145 145 end
146   - if params[:categories_ids]
147   - articles = articles.joins(:categories).where('category_id in (?)', params[:categories_ids])
148   - end
149 146 articles
150 147 end
151 148  
... ... @@ -248,6 +245,15 @@ require 'grape'
248 245 end
249 246 end
250 247  
  248 + def by_categories(scope, params)
  249 + category_ids = params[:category_ids]
  250 + if category_ids.nil?
  251 + scope
  252 + else
  253 + scope.joins(:categories).where(:categories => {:id => category_ids})
  254 + end
  255 + end
  256 +
251 257 def select_filtered_collection_of(object, method, params)
252 258 conditions = make_conditions_with_parameter(params)
253 259 order = make_order_with_parameters(object,method,params)
... ... @@ -257,6 +263,7 @@ require 'grape'
257 263  
258 264 objects = object.send(method)
259 265 objects = by_reference(objects, params)
  266 + objects = by_categories(objects, params)
260 267  
261 268 objects = objects.where(conditions).where(timestamp).page(page_number).per_page(per_page).reorder(order)
262 269  
... ...
test/unit/api/articles_test.rb
... ... @@ -546,7 +546,7 @@ class ArticlesTest < ActiveSupport::TestCase
546 546 e2.categories << c2
547 547 e1.save!
548 548 e2.save!
549   - params['categories_ids[]']=c1.id
  549 + params['category_ids[]']=c1.id
550 550 params['content_type']='Event'
551 551 get "api/v1/communities/#{co.id}/articles?#{params.to_query}"
552 552 json = JSON.parse(last_response.body)
... ...