Permalink
Browse files

make the unit tests work on rails 3.1

  • Loading branch information...
1 parent bba7003 commit af56e0b21db60e9f7b86d05402c49268a10ab238 @jonleighton committed Feb 20, 2012
View
@@ -1,3 +1,5 @@
+require 'bundler/setup'
+require 'appraisal'
require "bundler/gem_tasks"
require 'rake/testtask'
@@ -18,12 +18,13 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_dependency 'actionpack', '~> 3.2'
+ s.add_dependency 'actionpack', '~> 3.1'
s.add_development_dependency 'minitest', '~> 2.11.2'
s.add_development_dependency 'capybara', '~> 1.1.2'
s.add_development_dependency 'capybara_minitest_spec', '~> 0.2.1'
s.add_development_dependency 'poltergeist', '~> 0.4.0'
s.add_development_dependency 'rspec', '~> 2.8.0'
s.add_development_dependency 'rspec-rails', '~> 2.8.0'
+ s.add_development_dependency 'appraisal', '~> 0.4.1'
end
@@ -1,41 +1,56 @@
require 'action_dispatch'
module FocusedController
- class RouteMapper < ActionDispatch::Routing::Mapper
- def initialize(set, scope)
- @set, @scope = set, scope
+ # The monkey-patching in this file makes me sadface but I can't see
+ # another way ;(
+ class RouteMapper
+ def initialize(scope, options)
+ @scope, @options = scope, options
end
- def add_route(action, options)
- options = options.dup
+ def options
+ options = @options.dup
- if to = focused_controller_action(action, options)
+ if to = to_option
options[:to] = FocusedController::Route.new(to)
end
- super(action, options)
+ options
end
private
- def focused_controller_action(action, options)
- if options[:to] && !options[:to].respond_to?(:call)
- options[:to]
- elsif action && @scope[:controller]
+ def to_option
+ if @options[:to] && !@options[:to].respond_to?(:call)
+ @options[:to]
+ elsif @options[:action] && @scope[:controller]
name = ''
name << @scope[:module].camelize << '::' if @scope[:module]
name << @scope[:controller].camelize << 'Controller::'
- name << action.to_s.camelize
+ name << @options[:action].to_s.camelize
name
end
end
end
- module MapperExtension
+ class ActionDispatch::Routing::Mapper
def focused_controller_routes(&block)
- RouteMapper.new(@set, @scope).instance_eval(&block)
+ prev, @scope[:focused_controller_routes] = @scope[:focused_controller_routes], true
+ yield
+ ensure
+ @scope[:focused_controller_routes] = false
end
- end
- ActionDispatch::Routing::Mapper.send(:include, MapperExtension)
+ class Mapping
+ def initialize_with_focused_controller(set, scope, path, options)
+ if scope[:focused_controller_routes]
+ options = FocusedController::RouteMapper.new(scope, options).options
+ end
+
+ initialize_without_focused_controller(set, scope, path, options)
+ end
+
+ alias_method_chain :initialize, :focused_controller
+ end
+ end
end
@@ -102,7 +102,7 @@ def assert_response(type, message = nil)
end
def assert_redirected_to(location, message = nil)
- # This method is just defined for the docs
+ controller # make sure controller is initialized
super
end
@@ -13,7 +13,13 @@ def recognize(path, environment = {})
env = Rack::MockRequest.env_for(path, {:method => method})
req = route_set.request_class.new(env)
- route_set.router.recognize(req) do |route, matches, params|
+ if route_set.respond_to?(:router)
+ router = route_set.router # Rails 3.2+
+ else
+ router = route_set.set # Rails 3.0, 3.1
+ end
+
+ router.recognize(req) do |route, matches, params|
return route.app
end
end

0 comments on commit af56e0b

Please sign in to comment.