Some help with functional testing of nested routes

I have the following functional test in test/functional for testing my
products_controller:

require File.dirname(FILE) + ‘/…/test_helper’
require ‘products_controller’

Re-raise errors caught by the controller.

class ProductsController
def rescue_action(e)
raise e
end
end

class ProductsControllerTest < Test::Unit::TestCase

fixtures :products, :categories

def setup
@controller = ProductsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@first_id = products(:first).id
@category_id = categories(:first).id
end

def test_index
# HTTP GET
get :index
assert_response :success
assert assigns(:products)
assert_template ‘index’
end

def test_new
# HTTP GET
get :new
assert_response :success
assert_template ‘new’
assert_not_nil assigns(:product)
end

def test_create
num_records = Product.count

# HTTP POST
post :create, :product => {:name => 'New Test Product'}
assert_response :redirect
assert_redirected_to :action => 'index'
assert_equal num_records + 1, Product.count

end

.
.
.

I have the following in my routes file:

map.resources :categories, :classifications

map.resources :categories do |m|
m.resources :products
end

Using the routes navigator i have the following:

named_route > products
[:category_id, :action, :controller]
{:action=>“index”, :controller=>“products”} {:method=>:get}
/categories/:category_id/products/

product
[:category_id, :id, :action, :controller]
{:action=>“show”, :controller=>“products”} {:method=>:get}
/categories/:category_id/products/:id/

Im not sure how to adjust the tests to ensure that they are supplying
the category infirmation needed. The extent on my testing knowledge was
to add the nam to the product post to ensure that the name requqired
validation succeeded.

Im just trying to start testing so if you have a description of why, for
my understanding, that would be fantastic !

thanks in advance.

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