Skip to content

Commit

Permalink
Ensure route_matcher works in RoutingExampleGroup [remarkable-rb#26 s…
Browse files Browse the repository at this point in the history
…tatus:resolved]
  • Loading branch information
josevalim committed Mar 30, 2009
1 parent 4ac0abb commit 190ddb1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
9 changes: 9 additions & 0 deletions lib/remarkable/controller/controller.rb
Expand Up @@ -15,6 +15,15 @@ class ControllerExampleGroup
private
include Remarkable::Private
end

class RoutingExampleGroup
include Remarkable::Assertions
include Remarkable::Controller::Matchers
extend Remarkable::Controller::Macros

private
include Remarkable::Private
end
end
end
end
27 changes: 15 additions & 12 deletions lib/remarkable/controller/macros/route_matcher.rb
Expand Up @@ -11,13 +11,10 @@ def initialize(method, path, options)
def matches?(subject)
@subject = subject

initialize_with_spec!
@options[:controller] ||= controller_name

unless @options[:controller]
@options[:controller] = @controller.class.name.gsub(/Controller$/, '').tableize
end
@options[:controller] = @options[:controller].to_s
@options[:action] = @options[:action].to_s
@options[:action] = @options[:action].to_s

@populated_path = @path.dup
@options.each do |key, value|
Expand All @@ -38,12 +35,18 @@ def description

private

def initialize_with_spec!
# In Rspec 1.1.12 we can actually do:
#
# @controller = @subject
#
@controller = @spec.instance_eval { controller }
def controller_name
controller = if @spec.class.respond_to?(:controller_class)
@spec.class.controller_class
elsif @spec.class.respond_to?(:described_class)
@spec.class.described_class
end

if controller.ancestors.include?(ActionController::Base)
controller.name.gsub(/Controller$/, '').tableize
else
raise ArgumentError, "I cannot guess the controller name in route_for. Please supply :controller as option"
end
end

def map_to_path?
Expand All @@ -68,7 +71,7 @@ def expectation
end

def route(method, path, options)
Route.new(method, path, options)
Route.new(method, path, options).spec(self)
end
end
end
Expand Down

0 comments on commit 190ddb1

Please sign in to comment.