Commit 0c3f76902bc01c24ba9a31684be38a32cd4ab1c7
1 parent
f56d5e71
Exists in
theme-brasil-digital-from-staging
and in
7 other branches
api: filter archived articles
Showing
3 changed files
with
15 additions
and
1 deletions
Show diff stats
lib/noosfero/api/helpers.rb
@@ -5,7 +5,7 @@ require 'grape' | @@ -5,7 +5,7 @@ require 'grape' | ||
5 | module API | 5 | module API |
6 | module APIHelpers | 6 | module APIHelpers |
7 | PRIVATE_TOKEN_PARAM = :private_token | 7 | PRIVATE_TOKEN_PARAM = :private_token |
8 | - DEFAULT_ALLOWED_PARAMETERS = [:parent_id, :from, :until, :content_type, :author_id] | 8 | + DEFAULT_ALLOWED_PARAMETERS = [:parent_id, :from, :until, :content_type, :author_id, :archived] |
9 | 9 | ||
10 | include SanitizeParams | 10 | include SanitizeParams |
11 | include Noosfero::Plugin::HotSpot | 11 | include Noosfero::Plugin::HotSpot |
test/unit/api/articles_test.rb
@@ -625,6 +625,16 @@ class ArticlesTest < ActiveSupport::TestCase | @@ -625,6 +625,16 @@ class ArticlesTest < ActiveSupport::TestCase | ||
625 | assert_equal json['articles'].count, 2 | 625 | assert_equal json['articles'].count, 2 |
626 | end | 626 | end |
627 | 627 | ||
628 | + should 'find archived articles' do | ||
629 | + article1 = fast_create(Article, :profile_id => user.person.id, :name => "Some thing") | ||
630 | + article2 = fast_create(Article, :profile_id => user.person.id, :name => "Some thing", :archived => true) | ||
631 | + params[:archived] = true | ||
632 | + get "/api/v1/articles/?#{params.to_query}" | ||
633 | + json = JSON.parse(last_response.body) | ||
634 | + assert_not_includes json["articles"].map { |a| a["id"] }, article1.id | ||
635 | + assert_includes json["articles"].map { |a| a["id"] }, article2.id | ||
636 | + end | ||
637 | + | ||
628 | ARTICLE_ATTRIBUTES = %w(followers_count votes_count comments_count) | 638 | ARTICLE_ATTRIBUTES = %w(followers_count votes_count comments_count) |
629 | 639 | ||
630 | ARTICLE_ATTRIBUTES.map do |attribute| | 640 | ARTICLE_ATTRIBUTES.map do |attribute| |
test/unit/api/helpers_test.rb
@@ -138,6 +138,10 @@ class APIHelpersTest < ActiveSupport::TestCase | @@ -138,6 +138,10 @@ class APIHelpersTest < ActiveSupport::TestCase | ||
138 | assert_not_nil make_conditions_with_parameter('until' => '2010-10-10')[:created_at] | 138 | assert_not_nil make_conditions_with_parameter('until' => '2010-10-10')[:created_at] |
139 | end | 139 | end |
140 | 140 | ||
141 | + should 'make_conditions_with_parameter return archived parameter if archived was defined' do | ||
142 | + assert_not_nil make_conditions_with_parameter('archived' => true)[:archived] | ||
143 | + end | ||
144 | + | ||
141 | should 'make_conditions_with_parameter return created_at as the first existent date as parameter if only until is defined' do | 145 | should 'make_conditions_with_parameter return created_at as the first existent date as parameter if only until is defined' do |
142 | assert_equal Time.at(0).to_datetime, make_conditions_with_parameter(:until => '2010-10-10')[:created_at].min | 146 | assert_equal Time.at(0).to_datetime, make_conditions_with_parameter(:until => '2010-10-10')[:created_at].min |
143 | end | 147 | end |