<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.16.1">
</HEAD>
<BODY>
Hi everyone,<BR>
<BR>
I am relatively new to rspec and I am running into a wall in testing my views. I have a RESTful resource Contracts with a nested resource of Line_items.<BR>
<BR>
I am trying to figure out how to test the "edit" form of the Line_items. What complicates this is the nested routing and how to account for it, and that there is a partial form (_form.haml) that both the edit.haml and new.haml views use (app/views/line_items).<BR>
<BR>
My spec keeps failing and it seems to be from a routing issue. I'm pretty sure template.expect_render/template.stub_render should be in there somewhere, but that just generates more errors.<BR>
<BR>
I am running edge rails and edge rspec. My other spec's are working fine.<BR>
<BR>
See the output from running the spec and the associated files below (edit.haml_spec.rb, edit.haml, _form.haml)<BR>
<BR>
Thanks for your help,<BR>
Troy<BR>
<BR>
######## Output from running edit.haml_spec.r ########<BR>
<BR>
F<BR>
<BR>
1)<BR>
ActionView::TemplateError in '/line_items/edit.haml should render edit form'<BR>
contract_line_item_url failed to generate from {:contract_id=>"1", :action=>"show", :controller=>"line_items"}, expected: {:action=>"show", :controller=>"line_items"}, diff: {:contract_id=>"1"}<BR>
On line #6 of app/views/line_items/edit.haml<BR>
<BR>
3: <BR>
4: #section1<BR>
5: = error_messages_for :line_item<BR>
6: - form_for(:line_item, :url => contract_line_item_path(@contract.id), :html => { :method => :put }) do |f|<BR>
7: = render :partial => "form", :locals => { :f => f } <BR>
8: <BR>
9: %p<BR>
<BR>
app/views/line_items/edit.haml:6<BR>
vendor/rails/actionpack/lib/action_controller/routing.rb:1406:in `raise_named_route_error'<BR>
vendor/rails/actionpack/lib/action_controller/routing.rb:1370:in `generate'<BR>
vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:124:in `rewrite_path'<BR>
vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:103:in `rewrite_url'<BR>
vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:81:in `rewrite'<BR>
vendor/rails/actionpack/lib/action_controller/base.rb:605:in `url_for'<BR>
vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:71:in `send'<BR>
vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:71:in `url_for'<BR>
(eval):17:in `contract_line_item_path'<BR>
(eval):15:in `_render_haml_1'<BR>
vendor/plugins/stable/lib/haml/engine.rb:435:in `send'<BR>
vendor/plugins/stable/lib/haml/engine.rb:435:in `compile'<BR>
vendor/plugins/stable/lib/haml/engine.rb:186:in `to_html'<BR>
vendor/plugins/stable/lib/haml/template.rb:69:in `render'<BR>
vendor/rails/actionpack/lib/action_view/base.rb:529:in `delegate_render'<BR>
vendor/rails/actionpack/lib/action_view/base.rb:351:in `render_template_old'<BR>
vendor/plugins/stable/lib/haml/template.rb:96:in `render_template'<BR>
vendor/rails/actionpack/lib/action_view/base.rb:303:in `render_file'<BR>
vendor/rails/actionpack/lib/action_controller/base.rb:1079:in `render_for_file'<BR>
vendor/rails/actionpack/lib/action_controller/base.rb:831:in `render_with_no_layout'<BR>
vendor/rails/actionpack/lib/action_controller/layout.rb:269:in `render_without_benchmark'<BR>
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:51:in `render'<BR>
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'<BR>
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:51:in `render'<BR>
vendor/plugins/rspec_on_rails/lib/spec/rails/example/behaviour/view_example.rb:129:in `send'<BR>
vendor/plugins/rspec_on_rails/lib/spec/rails/example/behaviour/view_example.rb:129:in `render'<BR>
spec/views/line_items/edit.haml_spec.rb:57<BR>
vendor/plugins/rspec/lib/spec/example/example_methods.rb:14:in `instance_eval'<BR>
vendor/plugins/rspec/lib/spec/example/example_methods.rb:14:in `run'<BR>
vendor/plugins/rspec/lib/spec/example/example_runner.rb:57:in `run_example'<BR>
vendor/plugins/rspec/lib/spec/example/example_runner.rb:23:in `run'<BR>
/usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout'<BR>
vendor/plugins/rspec/lib/spec/example/example_runner.rb:21:in `run'<BR>
vendor/plugins/rspec/lib/spec/example/example_suite.rb:28:in `rspec_run'<BR>
vendor/plugins/rspec/lib/spec/example/example_suite.rb:24:in `each'<BR>
vendor/plugins/rspec/lib/spec/example/example_suite.rb:24:in `rspec_run'<BR>
vendor/plugins/rspec/lib/spec/extensions/test/unit/example_suite.rb:7:in `run'<BR>
vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:22:in `run'<BR>
vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in `each'<BR>
vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in `run'<BR>
vendor/plugins/rspec/lib/spec/runner/options.rb:77:in `run_examples'<BR>
vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run'<BR>
vendor/plugins/rspec/bin/spec:3<BR>
<BR>
Finished in 0.081986 seconds<BR>
<BR>
1 example, 1 failure<BR>
<BR>
<BR>
<BR>
######## edit.haml_spec.rb ########<BR>
require File.dirname(__FILE__) + '/../../spec_helper'<BR>
<BR>
describe "/line_items/edit.haml" do<BR>
include LineItemsHelper<BR>
<BR>
before do<BR>
@contract = mock_model(Contract)<BR>
@contract.stub!(:id).and_return("1")<BR>
@contract.stub!(:sdc_ref).and_return("MyString")<BR>
@contract.stub!(:description).and_return("MyString")<BR>
@contract.stub!(:sales_rep_id).and_return("1")<BR>
@contract.stub!(:office_id).and_return("1")<BR>
@contract.stub!(:account_id).and_return("MyString")<BR>
@contract.stub!(:cust_po_num).and_return("MyString")<BR>
@contract.stub!(:payment_terms).and_return("MyString")<BR>
@contract.stub!(:hp3000).and_return(false)<BR>
@contract.stub!(:revenue).and_return("MyString")<BR>
@contract.stub!(:annual_hw_rev).and_return("1.5")<BR>
@contract.stub!(:annual_sw_rev).and_return("1.5")<BR>
@contract.stub!(:annual_ce_rev).and_return("1.5")<BR>
@contract.stub!(:annual_sa_rev).and_return("1.5")<BR>
@contract.stub!(:annual_dr_rev).and_return("1.5")<BR>
@contract.stub!(:start_date).and_return(Date.today)<BR>
@contract.stub!(:end_date).and_return(Date.today)<BR>
@contract.stub!(:multiyr_end).and_return(Date.today)<BR>
@contract.stub!(:expired).and_return("MyString")<BR>
@contract.stub!(:hw_support_level_id).and_return("1")<BR>
@contract.stub!(:sw_support_level_id).and_return("1")<BR>
@contract.stub!(:updates).and_return("MyString")<BR>
@contract.stub!(:ce_days).and_return("1")<BR>
@contract.stub!(:sa_days).and_return("1")<BR>
@contract.stub!(:discount_pref_hw).and_return("1.5")<BR>
@contract.stub!(:discount_pref_sw).and_return("1.5")<BR>
@contract.stub!(:discount_prepay).and_return("1.5")<BR>
@contract.stub!(:discount_multiyear).and_return("1.5")<BR>
@contract.stub!(:discount_ce_day).and_return("1.5")<BR>
@contract.stub!(:discount_sa_day).and_return("1.5")<BR>
@contract.stub!(:primary_office).and_return("MyString")<BR>
@contract.stub!(:replacement_sdc_ref).and_return("MyString")<BR>
assigns[:contract] = @contract<BR>
<BR>
@line_item = mock_model(LineItem)<BR>
@line_item.stub!(:contract_id).and_return("1")<BR>
@line_item.stub!(:support_type).and_return("MyString")<BR>
@line_item.stub!(:product_num).and_return("MyString")<BR>
@line_item.stub!(:serial_num).and_return("MyString")<BR>
@line_item.stub!(:description).and_return("MyString")<BR>
@line_item.stub!(:begins).and_return(Date.today)<BR>
@line_item.stub!(:ends).and_return(Date.today)<BR>
@line_item.stub!(:qty).and_return("1")<BR>
@line_item.stub!(:list_price).and_return("1")<BR>
assigns[:line_item] = @line_item<BR>
end<BR>
<BR>
it "should render edit form" do<BR>
<BR>
render "line_items/edit.haml"<BR>
<BR>
response.should have_tag("form[action=#{contract_line_item_path(@contract.id,@line_item.id)}][method=post]") do<BR>
with_tag('input#line_item_support_type[name=?]', "line_item[support_type]")<BR>
with_tag('input#line_item_product_num[name=?]', "line_item[product_num]")<BR>
with_tag('input#line_item_serial_num[name=?]', "line_item[serial_num]")<BR>
with_tag('input#line_item_description[name=?]', "line_item[description]")<BR>
with_tag('input#line_item_qty[name=?]', "line_item[qty]")<BR>
with_tag('input#line_item_list_price[name=?]', "line_item[list_price]")<BR>
end<BR>
end<BR>
end<BR>
<BR>
<BR>
<BR>
######## edit.haml ########<BR>
- content_for :subtitle do<BR>
Edit Line Item<BR>
<BR>
#section1<BR>
= error_messages_for :line_item<BR>
- form_for(:line_item, :url => contract_line_item_path(@contract.id), :html => { :method => :put }) do |f|<BR>
= render :partial => "form", :locals => { :f => f } <BR>
<BR>
%p<BR>
= submit_tag "Update"<BR>
<BR>
#section2<BR>
= link_to('Show', contract_path(@contract)) + ' | ' + link_to('Back', contracts_path)<BR>
<BR>
<BR>
######## _form.haml ########<BR>
#section1<BR>
#results.boxed<BR>
%h2 Details<BR>
%p<BR>
%label{:for => "line_item_support_type"}<BR>
Type<BR>
= f.text_field :support_type<BR>
<BR>
%p<BR>
%label{:for => "line_item_product_num"}<BR>
Product num<BR>
= f.text_field :product_num<BR>
<BR>
%p<BR>
%label{:for => "line_item_serial_num"}<BR>
Serial num<BR>
= f.text_field :serial_num<BR>
<BR>
%p<BR>
%label{:for => "line_item_description"}<BR>
Description<BR>
= f.text_field :description<BR>
<BR>
%p<BR>
%label{:for => "line_item_begins"}<BR>
Begins<BR>
= f.text_field :begins<BR>
<BR>
%p<BR>
%label{:for => "line_item_ends"}<BR>
Ends<BR>
= f.text_field :ends<BR>
<BR>
%p<BR>
%label{:for => "line_item_qty"}<BR>
Qty<BR>
= f.text_field :qty<BR>
<BR>
%p<BR>
%label{:for => "line_list_price"}<BR>
List Price<BR>
= f.text_field :list_price<BR>
</BODY>
</HTML>