Patch #13468 » 0003-news-deleting-via-api.patch
| app/controllers/news_controller.rb | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
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
|
||
| test/integration/api_test/news_test.rb | ||
|---|---|---|
|
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
|
||