From e3cd76a6ab44f09b49b67e16a89bd8cfc3b12426 Mon Sep 17 00:00:00 2001 From: takenory Date: Thu, 4 Apr 2019 23:37:39 +0900 Subject: [PATCH 3/4] news deleting via api --- app/controllers/news_controller.rb | 7 +++++-- test/integration/api_test/news_test.rb | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 7bf828741..37c6e5b8d 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -26,7 +26,7 @@ class NewsController < ApplicationController before_action :authorize, :except => [:index] before_action :find_optional_project, :only => :index accept_rss_auth :index - accept_api_auth :index, :show, :create + accept_api_auth :index, :show, :create, :destroy helper :watchers helper :attachments @@ -106,6 +106,9 @@ class NewsController < ApplicationController def destroy @news.destroy - redirect_to project_news_index_path(@project) + respond_to do |format| + format.html { redirect_to project_news_index_path(@project) } + format.api { render_api_ok } + end end end diff --git a/test/integration/api_test/news_test.rb b/test/integration/api_test/news_test.rb index f3e6c76f1..32ea7bcbb 100644 --- a/test/integration/api_test/news_test.rb +++ b/test/integration/api_test/news_test.rb @@ -263,4 +263,24 @@ JSON news = News.find_by(:title => 'News JSON-API with attachments') assert_equal 2, news.attachments.count end + + test "DELETE /news/:id.xml" do + assert_difference('News.count', -1) do + delete '/news/1.xml', :headers => credentials('jsmith') + + assert_response :no_content + assert_equal '', response.body + end + assert_nil News.find_by_id(1) + end + + test "DELETE /news/:id.json" do + assert_difference('News.count', -1) do + delete '/news/1.json', :headers => credentials('jsmith') + + assert_response :no_content + assert_equal '', response.body + end + assert_nil News.find_by_id(6) + end end -- 2.14.2