Does anybody have any idea why when I run my specs it says that this route does not exist, when it clearly does?
Here is the relevant code in the controller:
class JobsController < ApplicationController
before_filter :find_job, :only => [:show, :edit]
respond_to :html, :json
def show
respond_with @job
end
def find_job
@job = Job.find(params[:id])
end
end
And in routes.rb:
resources :jobs
And in the specs:
def valid_attributes
{}
end
describe "POST create" do
context "with valid params" do
it "redirects to the jobs path" do
post :create, :job => valid_attributes
response.should redirect_to job_path
end
end
end
The error:
1) JobsController when logged in as administrator POST create with valid params redirects to the jobs path
Failure/Error: response.should redirect_to job_path
ActionController::RoutingError:
No route matches {:action=>"show", :controller=>"jobs"}
When I run rake routes
I get:
jobs GET /jobs(.:format) {:action=>"index", :controller=>"jobs"}
POST /jobs(.:format) {:action=>"create", :controller=>"jobs"}
new_job GET /jobs/new(.:format) {:action=>"new", :controller=>"jobs"}
edit_job GET /jobs/:id/edit(.:format) {:action=>"edit", :controller=>"jobs"}
job GET /jobs/:id(.:format) {:action=>"show", :controller=>"jobs"}
PUT /jobs/:id(.:format) {:action=>"update", :controller=>"jobs"}
DELETE /jobs/:id(.:format) {:action=>"destroy", :controller=>"jobs"}
job_path
is not a valid route without an :id
parameter. This should work:
job = assigns(:job)
response.should redirect_to job_path(job)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With