class Shoulda::Matchers::ActionController::PermitMatcher
@private
Attributes
action[R]
context[R]
controller[R]
double_collections_by_parameter_name[R]
expected_permitted_parameter_names[R]
parameters_double_registry[R]
request_params[R]
stubbed_params[W]
subparameter_name[R]
verb[R]
Public Class Methods
new(expected_permitted_parameter_names)
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 211 def initialize(expected_permitted_parameter_names) @expected_permitted_parameter_names = expected_permitted_parameter_names @action = nil @verb = nil @request_params = {} @subparameter_name = nil @parameters_double_registry = CompositeParametersDoubleRegistry.new end
Public Instance Methods
add_params(params)
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 227 def add_params(params) request_params.merge!(params) self end
description()
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 242 def description "(for #{verb.upcase} ##{action}) " + expectation end
failure_message()
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 259 def failure_message "Expected #{verb.upcase} ##{action} to #{expectation},\nbut #{reality}." end
failure_message_when_negated()
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 263 def failure_message_when_negated "Expected #{verb.upcase} ##{action} not to #{expectation},\nbut it did." end
for(action, options = {})
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 220 def for(action, options = {}) @action = action @verb = options.fetch(:verb, default_verb) @request_params = options.fetch(:params, {}) self end
in_context(context)
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 237 def in_context(context) @context = context self end
matches?(controller)
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 246 def matches?(controller) @controller = controller ensure_action_and_verb_present! parameters_double_registry.register Doublespeak.with_doubles_activated do context.__send__(verb, action, request_params) end unpermitted_parameter_names.empty? end
on(subparameter_name)
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 232 def on(subparameter_name) @subparameter_name = subparameter_name self end
Protected Instance Methods
actual_permitted_parameter_names()
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 299 def actual_permitted_parameter_names @_actual_permitted_parameter_names ||= begin if subparameter_name options = { for: subparameter_name } else options = {} end parameters_double_registry.permitted_parameter_names(options) end end
default_verb()
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 325 def default_verb case action when :create then :post when :update then RailsShim.verb_for_update end end
ensure_action_and_verb_present!()
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 315 def ensure_action_and_verb_present! if action.blank? raise ActionNotDefinedError end if verb.blank? raise VerbNotDefinedError end end
expectation()
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 273 def expectation message = 'restrict parameters ' if subparameter_name message << "on #{subparameter_name.inspect} " end message << 'to ' + format_parameter_names(expected_permitted_parameter_names) message end
format_parameter_names(parameter_names)
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 295 def format_parameter_names(parameter_names) parameter_names.map(&:inspect).to_sentence end
parameter_names_as_sentence()
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 332 def parameter_names_as_sentence expected_permitted_parameter_names.map(&:inspect).to_sentence end
reality()
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 285 def reality if actual_permitted_parameter_names.empty? 'it did not restrict any parameters' else 'the restricted parameters were ' + format_parameter_names(actual_permitted_parameter_names) + ' instead' end end
unpermitted_parameter_names()
click to toggle source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 311 def unpermitted_parameter_names expected_permitted_parameter_names - actual_permitted_parameter_names end