2011-08-29 3 views
2

작성자가 많습니다. 저작물은 저작자에게 속합니다. RSpecing : 중첩 리소스에 대한 작업 업데이트

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 액션을? 내가 놓친 게 있니?

저는 inherit-resources와 controller.stub (: resource)를 사용하고 있습니다.
나는 또한 assign(:work, work) throws undefined method 'assign'에 주목했습니다. 뷰에서 작동합니다. 컨트롤러에서도 작동하지 않아야합니까?

답변

1

이것은 트릭을 수행 한 것입니다.

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 

그래서 나는 그저 스텁이 될 수없는 것 같습니다 (: 리소스). 스텁 (: 부모)과 행운이 함께 시도. inherited_resources가 잘 이해가 안되는 것 같습니다.

의견을 환영합니다.