I am trying to write test cases for a nested resource and I am seeing the following error:
Error:
test_should_get_single_budget_link(BudgetlinkControllerTest):
ActionController::RoutingError: No route matches {:budget_id=>980190962, :action=>"show", :controller=>"budgetlink"}
test/functional/budgetlink_controller_test.rb:5:in `test_should_get_single_budget_link'
My routes.rb looks like:
Simplebudget::Application.routes.draw do
root :to => "home#index"
resources :budgets do
resources :transactions
resources :budgets, :controller => :budgetlink
end
resources :classifications
resources :periodicities
end
My test looks like the following:
test "should get single budget link" do
get :show, 'budget_id' => budgets(:one).id
assert_response :success
assert_equal assigns(:budgetlink).primary, "Budget1"
assert_equal assigns(:budgetlink).secondary, "Budget2"
end
I believe it is the fact that I have configured the routes to use the resource name “budgets” instead of budgetlinks and Rails has no way in my current test to recognize the budget route. How can I configure my test to recognize my remapped route?
Not sure if it is necessary but figured it couldn’t hurt. Here is the controller code:
class BudgetlinkController < ApplicationController
skip_before_filter :verify_authenticity_token
def show
@budgetlink = Budgetlink.find(params[:primary], params[:secondary])
respond_to do |format|
format.html #index.html.erb
format.json { render :json => @budgetlink}
end
end
end
I determined the issue. I was on the correct track, I was not writing the test in such a way that it would generate a GET to the correct resource/route.