Skip to content

Commit

Permalink
test helper for all rails versions
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Jun 24, 2011
1 parent 0c52427 commit cc4adfd
Showing 1 changed file with 41 additions and 25 deletions.
66 changes: 41 additions & 25 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,61 @@
require 'active_support/all'
require 'action_pack'
require 'action_controller'
require 'action_dispatch/testing/test_process'
require 'test/unit'
require 'redgreen'
$LOAD_PATH << 'lib'
require 'init'

if ActionPack::VERSION::MAJOR > 2
require 'action_dispatch/testing/test_process'

# fake checks
require 'ostruct'
module ActionController::UrlFor
def _routes
helpers = OpenStruct.new
helpers.url_helpers = Module.new
helpers
require 'ostruct'
module ActionController::UrlFor
def _routes
helpers = OpenStruct.new
helpers.url_helpers = Module.new
helpers
end
end
end

ROUTES = ActionDispatch::Routing::RouteSet.new
ROUTES.draw do
match ':controller(/:action(/:id(.:format)))'
end
ROUTES.finalize!
ROUTES = ActionDispatch::Routing::RouteSet.new
ROUTES.draw do
match ':controller(/:action(/:id(.:format)))'
end
ROUTES.finalize!

# funky patch to get @routes working, in 'setup' did not work
module ActionController::TestCase::Behavior
def process_with_routes(*args)
@routes = ROUTES
process_without_routes(*args)
module ActionController::TestCase::Behavior
def process_with_routes(*args)
@routes = ROUTES
process_without_routes(*args)
end
alias_method_chain :process, :routes
end
alias_method_chain :process, :routes
end

class ActionController::Base
self.view_paths = 'test/views'
class ActionController::Base
self.view_paths = 'test/views'

def self._routes
ROUTES
end

def self._routes
ROUTES
def url_for(*args)
'xxx'
end
end
else
require 'action_controller/test_process'

ActionController::Routing::Routes.reload rescue nil
ActionController::Base.cache_store = :memory_store

class ActionController::Base
before_filter :set_view_paths

def url_for(*args)
'xxx'
def set_view_paths
@template.view_paths = 'test/views'
end
end
end

0 comments on commit cc4adfd

Please sign in to comment.