2014-04-29 8 views
0

컨트롤러의 동작을 테스트하는 중입니다. 수동으로 테스트 할 때 코드가 예상대로 실행됩니다. 그러나 렌더링을 시도하고있는 템플릿을 찾을 수 없기 때문에 오류가 발생합니다.기능 테스트에서 템플릿을 찾을 수 없습니다.

response = {:success => true} 

response[:html] = {} 
response[:html][:list] = render_to_string :partial => "data_source", :locals => {:data_source => @data_source} 

respond_to do |format| 
    format.json {render :json => response} 
end 

내 시험 :

before do 
    @data_source = FactoryGirl.create :data_source, :facebook_fan_page, :account_id => @account.id, :user_id => @user.id 
    post :delete, :format => :json, :id => @data_source.id 
end 

it "should disable the data source" do 
    assert_equal false, @data_source.reload.enabled? 
end 

오류 메시지 :

ActionView :: MissingTemplate : 부분 data_sources/DATA_SOURCE 누락, 캡처 내 컨트롤러 코드에서

스 니펫/data_source, {: locale => [: en], : format을 사용하는 application/data_source s => [: json], : 핸들러 => [: erb, : 빌더, : haml]}. 검색 한 위치 :
* "/ Users/me/code/my_app/app/views"* "/Users/me/code/my_app/vendor/bundle/ruby/1.9.1/gems/konacha-3.0.0/app/전망 " /Users/me/code/my_app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.17/lib/action_view/path_set.rb:58:in 에서`

'발견

app/view/data_sources 디렉토리에 "_data_source.html.haml"부분이 분명히 있습니다.

왜 부분 테스트를 찾을 수 없습니까? 설치 문제가 의심됩니다.

미리 감사드립니다.

답변

1

json 요청을 할 때 render_to_string은 json 템플릿을 찾고 있습니다. 사용해보기 :

render_to_string :partial => "data_source", :formats => [:html], :locals => {:data_source => @data_source} 
+0

고마워요! 나는 지금 그 문제를 안다. 내 코드를 파고, 요청할 때 로컬에서 실행하는 것은 */* 형식이므로 부분적으로 올바르게 렌더링되지만 내 테스트는 요청하고 있습니다. json. – Destron

관련 문제