Commit 775ee2a5e0f537e73dcf08fa86ce53cdb3d829f2

Authored by Leandro Santos
1 parent 8b7475ad

should return nil if there is no article in profile path

app/api/v1/articles.rb
... ... @@ -269,7 +269,7 @@ module Api
269 269  
270 270 if params[:path].present?
271 271 article = profile.articles.find_by path: params[:path]
272   - if !article || !article.display_to?(current_person)
  272 + if article && !article.display_to?(current_person)
273 273 article = forbidden!
274 274 end
275 275  
... ...
test/api/articles_test.rb
... ... @@ -390,6 +390,17 @@ class ArticlesTest < ActiveSupport::TestCase
390 390 assert_equal article.id, json["article"]["id"]
391 391 end
392 392  
  393 + should "return an empty array if theres id no article in path of #{kind}" do
  394 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  395 + parent_article = Folder.create!(:profile => profile, :name => "Parent Folder")
  396 + article = Article.create!(:profile => profile, :name => "Some thing", :parent => parent_article)
  397 +
  398 + params[:path] = 'no-path'
  399 + get "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
  400 + json = JSON.parse(last_response.body)
  401 + assert_nil json["article"]
  402 + end
  403 +
393 404 should "not return article by #{kind} and path if user has no permission to view it" do
394 405 profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
395 406 parent_article = Folder.create!(:profile => profile, :name => "Parent Folder")
... ...