diff --git a/app/services/article_api_index_service.rb b/app/services/article_api_index_service.rb index 66f9c1a03..a1a26ef1e 100644 --- a/app/services/article_api_index_service.rb +++ b/app/services/article_api_index_service.rb @@ -29,7 +29,7 @@ class ArticleApiIndexService base_articles end - articles.decorate + articles&.decorate end private diff --git a/spec/requests/api/v0/articles_spec.rb b/spec/requests/api/v0/articles_spec.rb index 8edb825f8..d09887f8d 100644 --- a/spec/requests/api/v0/articles_spec.rb +++ b/spec/requests/api/v0/articles_spec.rb @@ -15,6 +15,11 @@ RSpec.describe "Api::V0::Articles", type: :request do expect(response.content_type).to eq("application/json") end + it "returns nothing if params state=all is not found" do + get api_articles_path(state: "all") + expect(json_response.size).to eq(0) + end + it "returns featured articles if no param is given" do article.update_column(:featured, true) get api_articles_path