Commit 775ee2a5e0f537e73dcf08fa86ce53cdb3d829f2
1 parent
8b7475ad
Exists in
staging
and in
4 other branches
should return nil if there is no article in profile path
Showing
2 changed files
with
12 additions
and
1 deletions
Show diff stats
app/api/v1/articles.rb
@@ -269,7 +269,7 @@ module Api | @@ -269,7 +269,7 @@ module Api | ||
269 | 269 | ||
270 | if params[:path].present? | 270 | if params[:path].present? |
271 | article = profile.articles.find_by path: params[:path] | 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 | article = forbidden! | 273 | article = forbidden! |
274 | end | 274 | end |
275 | 275 |
test/api/articles_test.rb
@@ -390,6 +390,17 @@ class ArticlesTest < ActiveSupport::TestCase | @@ -390,6 +390,17 @@ class ArticlesTest < ActiveSupport::TestCase | ||
390 | assert_equal article.id, json["article"]["id"] | 390 | assert_equal article.id, json["article"]["id"] |
391 | end | 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 | should "not return article by #{kind} and path if user has no permission to view it" do | 404 | should "not return article by #{kind} and path if user has no permission to view it" do |
394 | profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | 405 | profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) |
395 | parent_article = Folder.create!(:profile => profile, :name => "Parent Folder") | 406 | parent_article = Folder.create!(:profile => profile, :name => "Parent Folder") |