0
votes

I have seen some examples of this error, and tried a lot of things but none of them work for me.

Test in Rspec:

 it "should load data of invoices" do
     post :Invoices , taxiNo: "T2"                     
     expect(response.status).to eq(201) 
 end

Routes:

 post "/Invoices",   :to => "taxidriver#getInvoices"

Controller:

class TaxidriverController < ApplicationController

    def getInvoices
        render :text => {:message => "A new Taxi created"}.to_json, :status => :created 
    end
end

I am not sure about the line post :Invoices , taxiNo: "T2" Should I hit the url ? or should I hit the method?

I also tried post :getInvoices, taxiNo: "T2" but still the same error:

ActionController::UrlGenerationError:
     No route matches {:action=>"Invoices", :controller=>"bookings", :taxiNo=>"T2"}
     # ./spec/controllers/bookings_spec.rb:50:in `block (3 levels) in <top (required)>'
1
I assume you should be able to get an error message like ActionController::UrlGenerationError: No route matches {:action=>"someaction", :controller=>"yourcontroller"} could you post the whole error message?Norly Canarias
@NorlyCanarias i have updated my questionJimmy
You should be passing the action name getInvoices and not the route see github.com/rails/rails/blob/… , how about the complete error when you tried the other one? post :getInvoices, taxiNo: "T2".Norly Canarias
I was checking wrong controller, thxJimmy
FYI, in Ruby world, people prefer snake_case rather than camelCase. So you should rename your method to get_invoices and do post :get_invoices, taxiNo: 'T2'vutran

1 Answers

3
votes

The specific error your currently getting about "no route matches" is because you wrote your spec like this ...

post :Invoices , taxiNo: "T2"

When according to your routes and controller you named the method "getInvoices"

So you need to change your spec to this

post :getInvoices , taxiNo: "T2"