[Git][noosfero/noosfero][master] 2 commits: api: should content type return all text articles
Victor Costa
gitlab at mg.gitlab.com
Wed May 25 11:33:19 BRT 2016
Victor Costa pushed to branch master at Noosfero / noosfero
Commits:
e27807ad by Leandro Nunes dos Santos at 2016-05-25T11:08:39-03:00
api: should content type return all text articles
- - - - -
688cc083 by Victor Costa at 2016-05-25T14:30:46+00:00
Merge branch 'return_text_articles' into 'master'
should content type api parameter return all text articles
See merge request !944
- - - - -
3 changed files:
- app/api/helpers.rb
- test/api/articles_test.rb
- test/api/helpers_test.rb
Changes:
=====================================
app/api/helpers.rb
=====================================
--- a/app/api/helpers.rb
+++ b/app/api/helpers.rb
@@ -407,9 +407,11 @@ module Api
def parse_content_type(content_type)
return nil if content_type.blank?
- content_type.split(',').map do |content_type|
- content_type.camelcase
+ content_types = content_type.split(',').map do |content_type|
+ content_type = content_type.camelcase
+ content_type == 'TextArticle' ? Article.text_article_types : content_type
end
+ content_types.flatten.uniq
end
def period(from_date, until_date)
=====================================
test/api/articles_test.rb
=====================================
--- a/test/api/articles_test.rb
+++ b/test/api/articles_test.rb
@@ -34,6 +34,17 @@ class ArticlesTest < ActiveSupport::TestCase
assert_includes json["articles"].map { |a| a["id"] }, article.id
end
+ should 'list all text articles' do
+ profile = Community.create(identifier: 'my-community', name: 'name-my-community')
+ a1 = fast_create(TextArticle, :profile_id => profile.id)
+ a2 = fast_create(TextileArticle, :profile_id => profile.id)
+ a3 = fast_create(TinyMceArticle, :profile_id => profile.id)
+ params['content_type']='TextArticle'
+ get "api/v1/communities/#{profile.id}/articles?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equal 3, json['articles'].count
+ end
+
should 'get profile homepage' do
article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
person.home_page=article
@@ -124,6 +135,17 @@ class ArticlesTest < ActiveSupport::TestCase
assert_equivalent [child1.id, child2.id], json["articles"].map { |a| a["id"] }
end
+ should 'list all text articles of children' do
+ article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
+ child1 = fast_create(TextArticle, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing 1")
+ child2 = fast_create(TextileArticle, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing 2")
+ child3 = fast_create(TinyMceArticle, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing 3")
+ get "/api/v1/articles/#{article.id}/children?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equivalent [child1.id, child2.id, child3.id], json["articles"].map { |a| a["id"] }
+ end
+
+
should 'list public article children for not logged in access' do
article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing")
=====================================
test/api/helpers_test.rb
=====================================
--- a/test/api/helpers_test.rb
+++ b/test/api/helpers_test.rb
@@ -99,7 +99,7 @@ class Api::HelpersTest < ActiveSupport::TestCase
end
should 'parse_content_type return all content types as an array' do
- assert_equivalent ['TextArticle','TinyMceArticle'], parse_content_type("TextArticle,TinyMceArticle")
+ assert_equivalent ['TextileArticle','TinyMceArticle'], parse_content_type("TextileArticle,TinyMceArticle")
end
should 'find_article return article by id in list passed for user with permission' do
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/44cc52bc85929c7821a0e9a74331e33b6e30ccde...688cc083c709345b523021b37231041592204700
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160525/fffd029f/attachment-0001.html>
More information about the Noosfero-dev
mailing list