0
我正在测试在find语句中使用include的控制器操作。测试运行时会引发RecordNotFound。我错过了什么吗?我应该如何处理这些事情的测试?测试控制器 - 使用find查找时未找到记录
控制器:
def show
@forum_sub_topic = ForumSubTopic.includes(:forum_posts => [:post_replies]).find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @forum_sub_topic }
end
end
测试:
it 'renders show template' do
ForumSubTopic.stub(:find).with("37") { mock_forum_sub_topic }
get :show, :id => "37"
response.should render_template('show')
ebd
这就是我所需要的,谢谢:)链式方法更圆滑,我会用 – 2011-05-19 05:09:50