作者有多部作品。作品归作者所有
resources :authors do
resources :works
end
和RSpec:
it "should redirect to :show" do
work = FactoryGirl.create(:work)
controller.stub(:resource) { work }
work.should_receive(:update_attributes) { true }
put :update, id: work.id, author_id: work.author.id, work: {}
response.should redirect_to(admin_author_work_path(work.author, work))
end
和错误:
Expected response to be a redirect to <http://test.host/admin/authors/353/works/166>
but was a redirect to <http://test.host/admin/authors/353/works>
为什么它不重定向到works_controller的:show动作?我错过什么了吗?
我使用继承资源,因此controller.stub(:resource)。
我也注意到assign(:work, work) throws undefined method 'assign'
?它适用于视图,不应该也适用于控制器吗?
就是这样的。
it "should also redirect to :show" do
author = mock_model(Author)
work = mock_model(Work)
Author.stub(:find) { author }
author.stub_chain(:works, :find) { work }
work.should_receive(:update_attributes) { true }
put :update, id: author.id, author_id: work.id, work: {}
response.should redirect_to(admin_author_work_path(author, work))
end
所以看起来我不能只存根(:resource),看起来需要别的东西。尝试使用stub(:parent)也没有运气。看来我不太懂inherited_resources
欢迎评论