0003-news-deleting-via-api.patch

Takenori TAKAKI, 2019-04-04 17:07

Download (2.08 KB)

View differences:

app/controllers/news_controller.rb
26 26
  before_action :authorize, :except => [:index]
27 27
  before_action :find_optional_project, :only => :index
28 28
  accept_rss_auth :index
29
  accept_api_auth :index, :show, :create
29
  accept_api_auth :index, :show, :create, :destroy
30 30

  
31 31
  helper :watchers
32 32
  helper :attachments
......
106 106

  
107 107
  def destroy
108 108
    @news.destroy
109
    redirect_to project_news_index_path(@project)
109
    respond_to do |format|
110
      format.html { redirect_to project_news_index_path(@project) }
111
      format.api  { render_api_ok }
112
    end
110 113
  end
111 114
end
test/integration/api_test/news_test.rb
263 263
    news = News.find_by(:title => 'News JSON-API with attachments')
264 264
    assert_equal 2, news.attachments.count
265 265
  end
266

  
267
  test "DELETE /news/:id.xml" do
268
    assert_difference('News.count', -1) do
269
      delete '/news/1.xml', :headers => credentials('jsmith')
270

  
271
      assert_response :no_content
272
      assert_equal '', response.body
273
    end
274
    assert_nil News.find_by_id(1)
275
  end
276

  
277
  test "DELETE /news/:id.json" do
278
    assert_difference('News.count', -1) do
279
      delete '/news/1.json', :headers => credentials('jsmith')
280

  
281
      assert_response :no_content
282
      assert_equal '', response.body
283
    end
284
    assert_nil News.find_by_id(6)
285
  end
266 286
end
267
-