Note that there are some explanatory texts on larger screens.

plurals
  1. POActionController::RoutingError with rspec
    primarykey
    data
    text
    <p>I'm testing with rspec and my constant problem is with the routes this is my rspec</p> <pre><code>describe "POST 'create'" do describe "success" do before(:each) do @user = User.create!(:email =&gt; "foo@example.com", :password =&gt; "foobar", :password_confirmation =&gt; "foobar" ) @car = Car.create!(:brand =&gt; "example", :color =&gt; "foobar", :model =&gt; "foobar", :year =&gt;"2012") end it "should create a car" do lambda do post :create, :cars =&gt; @car, :user_id =&gt; @user.id end.should change(Car, :count).by(1) end it "should redirect to the user welcome page" do post :create, :cars =&gt; @car, :user_id =&gt; @user.id response.should redirect_to user_car_path end end end </code></pre> <p>my routes.rb ...</p> <pre><code>Estaciones::Application.routes.draw do root :to =&gt; "static_pages#home" match '/contact', :to=&gt;'static_pages#contact' match '/about', :to=&gt;'static_pages#about' devise_for :users resources :gas_stations resources :users do resources :cars do resources :tanking_logs end end .... </code></pre> <p><strong>UPDATE</strong></p> <p>when I run the test, got this error:</p> <pre><code>1) CarsController POST 'create' success should create a car Failure/Error: post :create, :cars =&gt; @car, :user =&gt; @user ActionController::RoutingError: No route matches {:cars=&gt;"12", :user=&gt;"74", :controller=&gt;"cars", :action=&gt;"create"} # ./spec/controllers/car_controller_spec.rb:22:in `block (5 levels) in &lt;top (required)&gt;' # ./spec/controllers/car_controller_spec.rb:21:in `block (4 levels) in &lt;top (required)&gt;' 2) CarsController POST 'create' success should redirect to the user welcome page Failure/Error: post :create, :cars =&gt; @car, :user =&gt; @user ActionController::RoutingError: No route matches {:cars=&gt;"13", :user=&gt;"75", :controller=&gt;"cars", :action=&gt;"create"} # ./spec/controllers/car_controller_spec.rb:27:in `block (4 levels) in &lt;top (required)&gt;' </code></pre> <p>here is my CarsController</p> <pre><code>class CarsController &lt; ApplicationController def new @user = User.find(params[:user_id]) @car = @user.cars.build end def create @user = User.find(params[:user_id]) @car = @user.cars.build(params[:car]) if @car.save redirect_to user_car_path(@user, @car), :flash =&gt; { :notice =&gt; " car created!" } else redirect_to new_user_car_path ,:flash =&gt; { :notice =&gt; " sorry try again :(" } end end </code></pre> <p>....</p> <p>I edited it with the solutions that you gave to me but still nothing</p> <p>here is my rake routes</p> <pre><code>user_cars GET /users/:user_id/cars(.:format) cars#index POST /users/:user_id/cars(.:format) cars#create new_user_car GET /users/:user_id/cars/new(.:format) cars#new edit_user_car GET /users/:user_id/cars/:id/edit(.:format) cars#edit user_car GET /users/:user_id/cars/:id(.:format) cars#show PUT /users/:user_id/cars/:id(.:format) cars#update DELETE /users/:user_id/cars/:id(.:format) cars#destroy </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload