RoR 控制器:
def destroy
Page.find(params[:id]).destroy
@pagechildren = Page.where("parent_id = ?", params[:id])
@pagechildren.update_all({parent_id: -1}) if @pagechildren.count >
0
flash[:success] =
t('activerecord.errors.controllers.message.attributes.page.page_destroy_suc cess')
redirect_to pages_path
end
测试 RSpec
it "should remove parent_id from children" do
@page2 = Factory(:page)
@pagechild = Factory(:page)
@pagechild[:parent_id] = @page2.id
lambda do
delete :destroy, :id => @page2
end.should
change(@pagechild, :parent_id).from(@page2.id).to(-1)
end
代码工作正常(),但
Код все корректно обрабатывает(捕获 'id' 删除页面,并且所有子项的 parent_id 更改为 -1)。但是 rspec 测试失败了。
工厂:
Factory.define :page do |page|
page.name "Name example page"
page.title "Title example page"
page.content "Content example page"
page.metadescription "metadescription example page"
page.metakeywords "metakeywords example page"
page.head "head example page"
page.ismenu true
page.order_id -1
page.parent_id -1
end
测试是红色的=(怎么了?