RSpec: Can't convert Image to String when using Nested Resource.
Posted
by darrint
on Stack Overflow
See other posts from Stack Overflow
or by darrint
Published on 2010-04-29T12:41:58Z
Indexed on
2010/04/29
12:47 UTC
Read the original article
Hit count: 263
I'm having trouble with and RSpec view test. I'm using nested resources and the model with a belongs_to association.
Here's what I have so far:
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
The error I'm receiving:
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'
Looking at the rails code where the exception occurs is not very revealing. Any ideas on how I can narrow down what is going on here?
One thing I tried was calling form_for directly from the example and I got a different error griping about lack of 'polymorphic_path' defined on Spec::Rails::Example::ViewExampleGroup::Subclass_4:0xblah. Not sure if that actually means anything.
© Stack Overflow or respective owner