[Git][noosfero/noosfero][master] should return nil if there is no article in profile path

Leandro Nunes gitlab at mg.gitlab.com
Thu Jul 28 07:59:50 BRT 2016


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
775ee2a5 by Leandro Nunes dos Santos at 2016-07-28T07:58:32-03:00
should return nil if there is no article in profile path

- - - - -


2 changed files:

- app/api/v1/articles.rb
- test/api/articles_test.rb


Changes:

=====================================
app/api/v1/articles.rb
=====================================
--- a/app/api/v1/articles.rb
+++ b/app/api/v1/articles.rb
@@ -269,7 +269,7 @@ module Api
 
                 if params[:path].present?
                   article = profile.articles.find_by path: params[:path]
-                  if !article || !article.display_to?(current_person)
+                  if article && !article.display_to?(current_person)
                     article = forbidden!
                   end
 


=====================================
test/api/articles_test.rb
=====================================
--- a/test/api/articles_test.rb
+++ b/test/api/articles_test.rb
@@ -390,6 +390,17 @@ class ArticlesTest < ActiveSupport::TestCase
       assert_equal article.id, json["article"]["id"]
     end
 
+    should "return an empty array if theres id no article in path of #{kind}" do
+      profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
+      parent_article = Folder.create!(:profile => profile, :name => "Parent Folder")
+      article = Article.create!(:profile => profile, :name => "Some thing", :parent => parent_article)
+
+      params[:path] = 'no-path'
+      get "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
+      json = JSON.parse(last_response.body)
+      assert_nil json["article"]
+    end
+
     should "not return article by #{kind} and path if user has no permission to view it" do
       profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
       parent_article = Folder.create!(:profile => profile, :name => "Parent Folder")



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/775ee2a5e0f537e73dcf08fa86ce53cdb3d829f2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160728/5087c321/attachment-0001.html>


More information about the Noosfero-dev mailing list