2010-04-29 4 views
0

RSpec보기 테스트에 문제가 있습니다. 중첩 된 리소스와 belongs_to 연관이있는 모델을 사용하고 있습니다.RSpec : 중첩 된 리소스를 사용할 때 이미지를 문자열로 변환 할 수 없습니다.

describe "/images/edit.html.erb" do 
    include ImagesHelper 

    before(:each) do 
    @image_pool = stub_model(ImagePool, :new_record => false, 
          :base_path => '/') 
    assigns[:image] = @image = 
     stub_model(Image, 
       :new_record? => false, 
       :source_name => "value for source_name", 
       :image_pool => @image_pool) 
    end 

    it "renders the edit image form" do 
    render 

    response.should have_tag("form[action=#{image_path(@image)}][method=post]") do 
     with_tag('input#image_source_name[name=?]', "image[source_name]") 
    end 
    end 
end 

오류 내가받은 해요 : :

ActionView::TemplateError in '/images/edit.html.erb renders the edit image form' 
can't convert Image into String 
On line #3 of app/views/images/edit.html.erb 

    1: <h1>Editing image</h1> 
    2: 
    3: <% form_for(@image) do |f| %> 
    4: <%= f.error_messages %> 
    5: 
    6: <p> 

    app/views/images/edit.html.erb:3 
    /opt/dtcm/railstest/lib/ruby/gems/1.9.1/gems/rspec-rails-1.3.2/lib/spec/rails/extensions/action_view/base.rb:27:in `render_with_mock_proxy' 
    /opt/dtcm/railstest/lib/ruby/gems/1.9.1/gems/rspec-rails-1.3.2/lib/spec/rails/example/view_example_group.rb:170:in `render' 

예외가 발생 레일 코드를 찾고 깨달음없는

는 여기에 지금까지 무슨이다. 내가 여기서 벌어지는 일을 어떻게 좁힐 수 있을지에 대한 아이디어는?

예제에서 form_for를 직접 호출 해 보았습니다. 그리고 Spec :: Rails :: Example :: ViewExampleGroup :: Subclass_4 : 0xblah에 정의 된 'polymorphic_path'부족에 대해 다른 오류가 발생했습니다. 그것이 실제로 어떤 것을 의미하는지 확실하지 않습니다.

답변

0

확인. 이것은 Rspec 및 중첩 된 리소스와 레일 도우미의 올바른 사용과 관련된 모든 것과 관련이 없습니다. 뷰에서 중첩 된 자원을 처리 할 수 ​​

분명히 올바른 방법은 다음과 같습니다

<% form_for [@image_pool, @image] do |f| %> 

이 오류 메시지가 도움이되지 않습니다 단지입니다.