ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting fixtures :all # # Test for routes generated by map.resource (singular). # def assert_routing_for_resource(controller, skip=[], nesting=[]) # routes = [ # ["new",'/new',{},:get], # ["create",'',{},:post], # ["index",'/index',{},:get], # ["show",'',{},:get], # ["edit",'/edit',{},:get], # ["update",'',{},:put], # ["destroy",'',{},:delete] # ] # check_resource_routing(controller, routes, skip, nesting) # end # # # Test for routes generated by map.resources (plural). # def assert_routing_for_resources(controller, skip=[], nesting=[]) # routes = [ # ["index",'',{},:get], # ["new",'/new',{},:get], # ["create",'',{},:post], # ["show",'/1',{:id=>'1'},:get], # ["edit",'/1/edit',{:id=>'1'},:get], # ["update",'/1',{:id=>'1'},:put], # ["destroy",'/1',{:id=>'1'},:delete] # ] # check_resource_routing(controller, routes, skip, nesting) # end # # # # Check that the expected paths will be generated by a resource, and that # # the expected params will be generated by paths defined by a resource. # # routes is array of [action, url string after controller, extra params]. # def check_resource_routing(controller, routes, skip=[], nesting=[]) # # set a prefix for nested resources # prefix = nesting.join('s/1/') # unless prefix.blank? # prefix += "s/1/" # end # # Add params for nested resources. # # For each 'nest', include a ":nest_id=>'1'" param. # params = {} # nesting.each do |param| # params["#{param}_id".to_sym] = '1' # end # # Test each of the standard resource routes. # routes.each do |pair| # unless skip.include? pair[0] # assert_generates("/#{prefix}#{controller}#{pair[1]}", # {:controller=>controller, # :action=>pair[0]}.merge(pair[2]).merge(params), {}, {}, # "Failed generation of resource route for action #{pair[0]} /#{prefix}#{controller}#{pair[1]}") # assert_recognizes( # {:controller=>controller, # :action=>pair[0]}.merge(pair[2]).merge(params), # {:path=>"/#{prefix}#{controller}#{pair[1]}", :method=>pair[3]}, # {}, "Failed to recognize resource route for path #{pair[3]}:/#{prefix}#{controller}#{pair[1]}") # end # end # end end