class Shoulda::Matchers::ActionController::PermitMatcher
@private
Attributes
Public Class Methods
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
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 228 def add_params(params) request_params.merge!(params) self end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 243 def description "(for #{verb.upcase} ##{action}) " + expectation end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 262 def failure_message "Expected #{verb.upcase} ##{action} to #{expectation},"\ "\nbut #{reality}." end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 267 def failure_message_when_negated "Expected #{verb.upcase} ##{action} not to #{expectation},"\ "\nbut it did." end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 221 def for(action, options = {}) @action = action @verb = options.fetch(:verb, default_verb) @request_params = options.fetch(:params, {}) self end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 238 def in_context(context) @context = context self end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 247 def matches?(controller) @controller = controller ensure_action_and_verb_present! parameters_double_registry.register Doublespeak.with_doubles_activated do params = { params: request_params } context.__send__(verb, action, **params) end unpermitted_parameter_names.empty? end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 233 def on(subparameter_name) @subparameter_name = subparameter_name self end
Protected Instance Methods
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 305 def actual_permitted_parameter_names @_actual_permitted_parameter_names ||= begin options = if subparameter_name { for: subparameter_name } else {} end parameters_double_registry.permitted_parameter_names(options) end end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 331 def default_verb case action when :create then :post when :update then RailsShim.verb_for_update end end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 321 def ensure_action_and_verb_present! if action.blank? raise ActionNotDefinedError end if verb.blank? raise VerbNotDefinedError end end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 278 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
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 301 def format_parameter_names(parameter_names) parameter_names.map(&:inspect).to_sentence end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 338 def parameter_names_as_sentence expected_permitted_parameter_names.map(&:inspect).to_sentence end
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 291 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
Source
# File lib/shoulda/matchers/action_controller/permit_matcher.rb, line 317 def unpermitted_parameter_names expected_permitted_parameter_names - actual_permitted_parameter_names end