我有Admin
模型可以管理Organization
。
我有AdminController
一个简单的index
操作和一个我正在尝试测试的子Admin::OrganizationsController
控制器。
对此子控制器上的规范show
操作的测试没有错误地传递:
describe "GET show" do
it "assigns the requested organization as @organization" do
org = FactoryGirl.create(:organization)
get :show, id: org.id # <---- this works
expect(assigns(:organization)).to eq(org)
end
end
但是当我尝试测试destroy
操作时,我收到一个我无法理解的错误(因此解决了):
describe "DELETE destroy" do
it "destroys the requested organization" do
org = FactoryGirl.create(:organization)
delete :destroy, id: org.id # <---- (I tried to use org.id.to_param, unsuccessfully)
# ...rest of the test
end
end
有错误:
Failure/Error: expect { delete :destroy, id: org.id }.to change(Organization, :count).by(-1)
NameError:
undefined local variable or method `organizations_url' for #<Admin::OrganizationsController:0x007fefe1622248>
我怀疑这与我的控制器“嵌套”有关(我猜需要admin_organizations_url
)。
任何帮助?
(附加信息:Rails 4.0.1,rspec 3.0.0.beta1)
答案 0 :(得分:1)
destroy
中的Admin::OrganizationController
行为,看起来像这样:
def destroy
@organization.destroy
respond_to do |format|
format.html { redirect_to organizations_url } # <--- has to be admin_organizaions_url
format.json { head :no_content }
end
end
我没有注意respond_to
阻止 。