class Shoulda::Matchers::ActionController::RouteParams

@private

Constants

PARAMS_TO_SYMBOLIZE

Attributes

args[R]

Public Class Methods

new(args) click to toggle source
# File lib/shoulda/matchers/action_controller/route_params.rb, line 8
def initialize(args)
  @args = args
end

Public Instance Methods

normalize() click to toggle source
# File lib/shoulda/matchers/action_controller/route_params.rb, line 12
def normalize
  if controller_and_action_given_as_string?
    extract_params_from_string
  else
    stringify_params
  end
end

Protected Instance Methods

controller_and_action_given_as_string?() click to toggle source
# File lib/shoulda/matchers/action_controller/route_params.rb, line 24
def controller_and_action_given_as_string?
  args[0].is_a?(String)
end
extract_params_from_string() click to toggle source
# File lib/shoulda/matchers/action_controller/route_params.rb, line 28
def extract_params_from_string
  controller, action = args[0].split('#')
  params = (args[1] || {}).merge(controller: controller, action: action)
  normalize_values(params)
end
normalize_values(hash) click to toggle source
# File lib/shoulda/matchers/action_controller/route_params.rb, line 38
def normalize_values(hash)
  hash.each_with_object({}) do |(key, value), hash_copy|
    hash_copy[key] = symbolize_or_stringify(key, value)
  end
end
stringify(value) click to toggle source
# File lib/shoulda/matchers/action_controller/route_params.rb, line 52
def stringify(value)
  if value.is_a?(Array)
    value.map(&:to_param)
  else
    value.to_param
  end
end
stringify_params() click to toggle source
# File lib/shoulda/matchers/action_controller/route_params.rb, line 34
def stringify_params
  normalize_values(args[0])
end
symbolize_or_stringify(key, value) click to toggle source
# File lib/shoulda/matchers/action_controller/route_params.rb, line 44
def symbolize_or_stringify(key, value)
  if PARAMS_TO_SYMBOLIZE.include?(key)
    value.to_sym
  else
    stringify(value)
  end
end