diff --git a/lib/noosfero/api/helpers.rb b/lib/noosfero/api/helpers.rb index 7910091..aa7e3cf 100644 --- a/lib/noosfero/api/helpers.rb +++ b/lib/noosfero/api/helpers.rb @@ -108,7 +108,7 @@ require_relative '../../find_by_contents' def post_article(asset, params) return forbidden! unless current_person.can_post_content?(asset) - klass_type= params[:content_type].nil? ? TinyMceArticle.name : params[:content_type] + klass_type = params[:content_type] || params[:article].delete(:type) || TinyMceArticle.name return forbidden! unless ARTICLE_TYPES.include?(klass_type) article = klass_type.constantize.new(params[:article]) diff --git a/lib/noosfero/api/v1/articles.rb b/lib/noosfero/api/v1/articles.rb index 309059d..cce7dd6 100644 --- a/lib/noosfero/api/v1/articles.rb +++ b/lib/noosfero/api/v1/articles.rb @@ -230,7 +230,7 @@ module Noosfero parent_article = environment.articles.find(params[:id]) return forbidden! unless parent_article.allow_create?(current_person) - klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type] + klass_type = params[:content_type] || params[:article].delete(:type) || 'TinyMceArticle' #FIXME see how to check the article types #return forbidden! unless ARTICLE_TYPES.include?(klass_type) diff --git a/test/api/articles_test.rb b/test/api/articles_test.rb index e4cd5ba..be0f754 100644 --- a/test/api/articles_test.rb +++ b/test/api/articles_test.rb @@ -408,6 +408,18 @@ class ArticlesTest < ActiveSupport::TestCase assert_kind_of TextArticle, Article.last end + should "#{kind} create article with type passed as parameter" do + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true) + + Article.delete_all + params[:article] = {:name => "Title", :type => 'TextArticle'} + post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" + json = JSON.parse(last_response.body) + + assert_kind_of TextArticle, Article.last + end + should "#{kind}: create article of TinyMceArticle type if no content type is passed as parameter" do profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) Person.any_instance.stubs(:can_post_content?).with(profile).returns(true) -- libgit2 0.21.2