From 0c3f76902bc01c24ba9a31684be38a32cd4ab1c7 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 1 Dec 2015 17:01:58 -0300 Subject: [PATCH] api: filter archived articles --- lib/noosfero/api/helpers.rb | 2 +- test/unit/api/articles_test.rb | 10 ++++++++++ test/unit/api/helpers_test.rb | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/noosfero/api/helpers.rb b/lib/noosfero/api/helpers.rb index 2d29ca8..8583132 100644 --- a/lib/noosfero/api/helpers.rb +++ b/lib/noosfero/api/helpers.rb @@ -5,7 +5,7 @@ require 'grape' module API module APIHelpers PRIVATE_TOKEN_PARAM = :private_token - DEFAULT_ALLOWED_PARAMETERS = [:parent_id, :from, :until, :content_type, :author_id] + DEFAULT_ALLOWED_PARAMETERS = [:parent_id, :from, :until, :content_type, :author_id, :archived] include SanitizeParams include Noosfero::Plugin::HotSpot diff --git a/test/unit/api/articles_test.rb b/test/unit/api/articles_test.rb index 0b18af8..90cb63e 100644 --- a/test/unit/api/articles_test.rb +++ b/test/unit/api/articles_test.rb @@ -625,6 +625,16 @@ class ArticlesTest < ActiveSupport::TestCase assert_equal json['articles'].count, 2 end + should 'find archived articles' do + article1 = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") + article2 = fast_create(Article, :profile_id => user.person.id, :name => "Some thing", :archived => true) + params[:archived] = true + get "/api/v1/articles/?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_not_includes json["articles"].map { |a| a["id"] }, article1.id + assert_includes json["articles"].map { |a| a["id"] }, article2.id + end + ARTICLE_ATTRIBUTES = %w(followers_count votes_count comments_count) ARTICLE_ATTRIBUTES.map do |attribute| diff --git a/test/unit/api/helpers_test.rb b/test/unit/api/helpers_test.rb index 7761666..50c4861 100644 --- a/test/unit/api/helpers_test.rb +++ b/test/unit/api/helpers_test.rb @@ -138,6 +138,10 @@ class APIHelpersTest < ActiveSupport::TestCase assert_not_nil make_conditions_with_parameter('until' => '2010-10-10')[:created_at] end + should 'make_conditions_with_parameter return archived parameter if archived was defined' do + assert_not_nil make_conditions_with_parameter('archived' => true)[:archived] + end + should 'make_conditions_with_parameter return created_at as the first existent date as parameter if only until is defined' do assert_equal Time.at(0).to_datetime, make_conditions_with_parameter(:until => '2010-10-10')[:created_at].min end -- libgit2 0.21.2