【发布时间】:2016-01-18 18:50:19
【问题描述】:
我正在开发 JSON API 并尝试为 show 方法编写集成测试。问题是我不知道如何测试响应。下面我有assert_response :success,但这条线似乎总是通过,即使它不应该通过(例如,将@author1而不是@article1发布到show_articles_path,这应该不起作用)。
我应该使用什么断言行来测试它是否成功显示?
路线:
show_articles POST /articles/show/:id(.:format) articles#show
测试:
test "should get show" do
post show_articles_path(@article1, article: {author_id: @author1.id })
assert_response :success
end
方法:
def show
@author = Author.find(params[:article][:author_id])
article = Article.find(params[:id])
render json: article
end
【问题讨论】:
标签: ruby-on-rails json ruby-on-rails-4 testing integration-testing