Thanks very much. I feel like a bit of a fool, now, for the odd error.<br><br>Changing from:<br> <%= link_to(<a href="http://a.name">a.name</a>,actor_path(@customer,@project),{:class=>"show",:title=>"Show actor details"}) -%>
<br>To<br> <%= link_to(<a href="http://a.name">a.name</a>,actor_path(@customer,@project,a),{:class=>"show",:title=>"Show actor details"}) -%><br><br>Caused everything to work like a champ. And uncovered an interesting bug. When not specifying the actor 'a', the link is generated (in the page), but with id=1. No idea if/when I would have caught that.
<br><br>Thanks again David, and all the RSpec'ers out there.<br><br>Also, thanks for the multi-nesting pointer.<br><br>Scott<br><br><br><div><span class="gmail_quote">On 9/10/07, <b class="gmail_sendername">David Chelimsky
</b> <<a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On 9/10/07, Scott Sehlhorst <
<a href="mailto:scott@tynerblain.com">scott@tynerblain.com</a>> wrote:<br>> Thanks, first, to everyone who's asked and answered questions on this list,<br>> and to the creators of RSpec - it is all very helpful. I've searched the
<br>> mailing list, and had a couple 2hr googling sessions that didn't help me<br>> find an answer.<br>><br>> I've run into a problem getting my first non-trivial view spec to run. I<br>> get an error when trying to generate a link_to() to another resource. Here
<br>> is an overview of the situation, then the code:<br>><br>><br>> I'm using a restful design<br>> I'm using nested (multiply nested) resources<br>> I am trying to test a show.rhtml view, that includes links (link_to) to
<br>> resources managed by another controller<br>> The use_case model has a many-to-may through relationship with actors, and<br>> I'm displaying links to the associated actors on the use_case page<br>> I can't get the links to generate when running rspec (but it works great in
<br>> the app)<br>> I am in the early stages of the project, and want to move forward BDD, but I<br>> have some existing code that I need to test before I can start moving<br>> forward again.<br>> My theories: I need to stub the controller (for the other resource), or I
<br>> need to stub something else.<br>><br>> Here's the command I'm running to drive RSpec<br>><br>> ruby script/spec -f s spec/views<br>><br>> Here's the error that I get<br>><br>> 1)
<br>> ActionView::TemplateError in 'UseCase showing a use case should display the<br>> use case identifier'<br>> actor_url failed to generate from {:customer_id=>"1",<br>> :controller=>"actors", :action=>"show", :project_id=>"1"}, expecte
<br>> d: {:controller=>"actors", :action=>"show"}, diff: {:customer_id=>"1",<br>> :project_id=>"1"}<br>> On line #22 of app/views/use_cases/show.rhtml<br>><br>
> 19: <ul><br>> 20: <% @primary_actors.each do |a| %><br>> 21: <li><br>> 22: <%=<br>> link_to(<a href="http://a.name">a.name</a>,actor_path(@customer,@project),{:class=>"show",:title=>"Show
<br>> actor details"}) -%><br>> 23: <%= link_to("Remove<br>> assignment",participation_path(@customer,@project,@use_case.participations.find_by<br>> _actor_id(a)),{:class=>"delete",:title=>"Remove the
<br>> assignment of this actor to this use case", :confirm => 'Are you sur<br>> e you want to remove this assignment?', :method => :delete})-%><br>> 24: </li><br>> 25: <% end %>
<br>><br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/routing.rb:1273:in<br>> `raise_named_route_error'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/routing.rb:1245:in
<br>> `generate'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:104:in<br>> `rewrite_path'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:69:in
<br>> `rewrite'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:522:in<br>> `url_for'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:27:in
<br>> `url_for'<br>> (eval):19:in `actor_path'<br>> #{RAILS_ROOT}/app/views/use_cases/show.rhtml:22:in<br>> `_run_rhtml_47app47views47use_cases47show46rhtml'<br>> #{RAILS_ROOT}/app/views/use_cases/show.rhtml:20:in
<br>> `_run_rhtml_47app47views47use_cases47show46rhtml'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:326:in<br>> `compile_and_render_template'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:301:in
<br>> `render_template'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:260:in<br>> `render_file'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:806:in
<br>> `render_file'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:741:in<br>> `render_with_no_layout'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/layout.rb:256:in
<br>> `render_without_benchmark'<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in<br>> `render'<br>> c:/dev/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
<br>><br>> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in<br>> `render'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in
<br>> `render'<br>> spec/views/use_cases/show_view_spec.rb:40<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/composite_proc_builder.rb:17:in<br>> `proc'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/composite_proc_builder.rb:12:in
<br>> `proc'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/example.rb:71:in<br>> `before_example'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/example.rb:25:in<br>
> `run'<br>> c:/dev/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/example.rb:24:in<br>> `run'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:81:in
<br>> `run'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:75:in<br>> `run'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:58:in<br>
> `run_behaviours'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in<br>> `run_behaviours'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in
<br>> `run'<br>><br>> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in<br>> `run'<br>> script/spec:4<br>><br>> Here's part of my routes.rb, showing the nested resources
<br>><br>> map.resources :customers do |customers|<br>> customers.resources :projects do |projects|<br>> projects.resources :actors<br>> projects.resources :use_cases<br>><br>><br>> Here's some of the stubbing that I am using to set up the spec
<br>><br>> @customer = mock_model(Customer,<br>> :id => 1,<br>> :to_param => "1"<br>> )<br>><br>> @project = mock_model(Project,<br>> :id => 1,
<br>> :customer_id => 1,<br>> :to_param => "1"<br>> )<br>><br>> I've also stubbed objects to create the following :assigns<br>><br>> assigns[:customer] = @customer
<br>> assigns[:project] = @project<br>> assigns[:use_case] = @use_case<br>> assigns[:primary_actors] = @primary_actors<br>><br>> I suspect that there is something else that needs to be stubbed - actors
<br>> controller, maybe? I really don't know. If anyone can point me in the<br>> right direction, or tell me where in the error message to dig deeper, that<br>> would be awesome.<br>><br>> If I left out any important information, please let me know! And a huge
<br>> thanks in advance to anyone who can help me out, or explain why this isn't<br>> supported, or point me towards any docs or articles that address this issue<br>> (because I will have it a zillion times, as almost all views in my app
<br>> display content and links from more than one model).<br><br>I don't think it's related to rspec. Note that the top of the error stack says:<br><br> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/routing.rb:1273:in
<br>`raise_named_route_error'<br><br>So the error is likely related to this bit:<br><br> actor_path(@customer,@project)<br><br>Given the nesting that you're doing multi-level nesting (which is not<br>recommended btw - read
<br><a href="http://weblog.jamisbuck.org/2007/2/5/nesting-resources">http://weblog.jamisbuck.org/2007/2/5/nesting-resources</a>), I believe<br>that the path should be either:<br><br>customer_project_actor_path(@customer, @project, @actor)
<br><br>or<br><br>customer_project_actors_path(@customer, @project)<br><br>HTH,<br>David<br>_______________________________________________<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org
</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></div><br><br clear="all"><br>-- <br>Scott Sehlhorst, President Tyner Blain LLC<br>
<a href="http://tynerblain.com/blog">http://tynerblain.com/blog</a><br><a href="http://tynerblain.com/nexus">http://tynerblain.com/nexus</a>