Skip to content

Commit

Permalink
Mutate less.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Mar 30, 2012
1 parent 4ff1344 commit 36006d8
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions lib/shoulda/matchers/action_controller/route_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ def route(method, path)
end

class RouteMatcher # :nodoc:

def initialize(method, path, context)
@method = method
@path = path
@context = context
end

attr_reader :failure_message, :negative_failure_message

def to(params)
@params = params
stringify_params!
@params = stringify_params(params)
self
end

Expand All @@ -46,26 +46,31 @@ def in_context(context)
end

def matches?(controller)
@controller = controller
guess_controller!
guess_controller!(controller)
route_recognized?
end

attr_reader :failure_message, :negative_failure_message

def description
"route #{@method.to_s.upcase} #{@path} to/from #{@params.inspect}"
end

private

def guess_controller!
@params[:controller] ||= @controller.controller_path
def guess_controller!(controller)
@params[:controller] ||= controller.controller_path
end

def stringify_params!
@params.each do |key, value|
@params[key] = value.is_a?(Array) ? value.collect {|v| v.to_param } : value.to_param
def stringify_params(params)
params.each do |key, value|
params[key] = stringify(value)
end
end

def stringify(value)
if value.is_a?(Array)
value.map(&:to_param)
else
value.to_param
end
end

Expand All @@ -85,9 +90,7 @@ def route_recognized?
false
end
end

end

end
end
end

0 comments on commit 36006d8

Please sign in to comment.