diff --git a/app/api/helpers.rb b/app/api/helpers.rb index 04acdc3..e306bea 100644 --- 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) diff --git a/test/api/articles_test.rb b/test/api/articles_test.rb index bf378d8..622532d 100644 --- 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") diff --git a/test/api/helpers_test.rb b/test/api/helpers_test.rb index 1507527..191b95f 100644 --- 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 -- libgit2 0.21.2