Rspec route question

Hello

I’m having some trouble getting rspec to recognize a route.

This works

describe “routes” do
it “should have a route” do
{ :get => “/accounts/3/jobs/3/
applications/1/edit” }.should route_to(:controller => ‘applications’,
:action => ‘edit’, :id => “1”, :account_id => “3”, :job_id => “3” )
end
end

This fails

describe "#edit" do
  it "should respond to application/edit" do
     get "#{edit_account_job_application_path(@account.id, @job.id, 

@
application.id)}"
response.should be_success
end
end

Here is the stack trace
1)
ActionController::RoutingError in ‘ApplicationsController#edit should
respond to application/edit’
No route matches {:action=>"/accounts/23/jobs/
99/applications/299/edit", :controller=>“applications”}
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/routing/route_set.rb:419:in
generate' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/routing/route_set.rb:352:ingenerate_extras’
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/routing/route_set.rb:348:in
extra_keys' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/test_process.rb:96:inassign_parameters’
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/test_process.rb:440:in
process' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/test_process.rb:398:inget’
./spec/controllers/applications_controller_spec.rb:26:

Note that this route works fine at runtime in the browser. Also rails
is
able to resolve the route “edit_account_job_application_path”.

I’m running rspec 1.3.0 and rspec-rails 1.3.2

Thanks in advance!

Matt

On Jul 15, 2010, at 6:24 PM, Matt Kolenda wrote:

end

This fails

describe "#edit" do
  it "should respond to application/edit" do 
     get "#{edit_account_job_application_path(@account.id, @job.id, @application.id)}"
    response.should be_success
  end

end

Controller specs include behavior from ActionController::TestCase, which
is designed to handle requests using a hash representing the action and
params rather than a URL (or route). The proper way to do this is:

get :edit, :id => @application.id, :job_id => @job.id, :account_id =>
@account_id

If you want to, you can use urls in request specs in rspec-rails-2
(integration specs in rspec-rails-1). But I wouldn’t recommend that
unless you feel you’ll benefit from going through routing and rendering
views.

HTH,
David

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs