Skip to content

Commit

Permalink
Update change log with Lawrence Pit commits [#88 status:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jul 5, 2009
1 parent 98b6900 commit 0bbf0f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
2 changes: 2 additions & 0 deletions remarkable_rails/CHANGELOG
@@ -1,3 +1,5 @@
* Allow should_route to use environment configuration [#88] (thanks to Lawrence Pit)

* Allow mock model class to be set using :as option.

* [DEPRECATION] By default all matchers perform expectations, use with_stubs => true
Expand Down
Expand Up @@ -9,7 +9,6 @@ class RouteMatcher < Remarkable::Base #:nodoc:

before_assert do
@options[:controller] ||= controller_name

@populated_path = @path.dup

@options.each do |key, value|
Expand All @@ -20,6 +19,14 @@ class RouteMatcher < Remarkable::Base #:nodoc:
::ActionController::Routing::Routes.reload if ::ActionController::Routing::Routes.empty?
end

def controller
@controller ||= @spec.controller if @spec.respond_to?(:controller)
end

def request
controller.request if controller
end

private

def map_to_path?
Expand All @@ -28,14 +35,11 @@ def map_to_path?
end

def generate_params?
controller = @spec.send(:controller)
env = ::ActionController::Routing::Routes.extract_request_environment(controller.request) if controller

env ||= {}
env[:method] = @method.to_sym
params_from = begin
::ActionController::Routing::Routes.recognize_path(@populated_path, env)
rescue
end
params_from = ::ActionController::Routing::Routes.recognize_path(@populated_path, env) rescue nil
return params_from == @options, :actual => params_from.inspect
end

Expand All @@ -47,23 +51,27 @@ def generate_params?
# subject or the controller class in the RoutingExampleGroup.
#
def controller_name
spec_class = @spec.class unless @spec.class == Class

controller = if @subject && @subject.class.ancestors.include?(::ActionController::Base)
@subject.class
elsif spec_class.respond_to?(:controller_class)
spec_class.controller_class
elsif spec_class.respond_to?(:described_class)
spec_class.described_class
end

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

def controller_class
@controller_class ||= begin
spec_class = @spec.class unless @spec.class == Class

attempts = []
attempts << controller.class if controller
attempts << @subject.class if @subject
attempts << spec_class.controller_class if spec_class.respond_to?(:controller_class)
attempts << spec_class.described_class if spec_class.respond_to?(:described_class)

attempts.find{ |controller| ::ActionController::Base >= controller }
end
end

def interpolation_options
{ :options => @options.inspect, :method => @method.to_s.upcase, :path => @path.inspect }
end
Expand Down

0 comments on commit 0bbf0f4

Please sign in to comment.