class Shoulda::Matchers::ActionController::StrongParametersMatcher
@private
Attributes
action[R]
context[R]
controller[R]
double_collection[R]
expected_permitted_params[R]
request_params[R]
stubbed_params[W]
verb[R]
Public Class Methods
new(expected_permitted_params)
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 164 def initialize(expected_permitted_params) @action = nil @verb = nil @request_params = {} @expected_permitted_params = expected_permitted_params set_double_collection end
Public Instance Methods
description()
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 184 def description "permit #{verb.upcase} ##{action} to receive parameters #{param_names_as_sentence}" end
failure_message()
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 199 def failure_message "Expected controller to permit #{unpermitted_params.to_sentence}, but it did not." end
Also aliased as: failure_message_for_should
failure_message_when_negated()
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 204 def failure_message_when_negated "Expected controller not to permit #{verified_permitted_params.to_sentence}, but it did." end
Also aliased as: failure_message_for_should_not
for(action, options = {})
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 172 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/strong_parameters_matcher.rb, line 179 def in_context(context) @context = context self end
matches?(controller)
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 188 def matches?(controller) @controller = controller ensure_action_and_verb_present! Doublespeak.with_doubles_activated do context.__send__(verb, action, request_params) end unpermitted_params.empty? end
Protected Instance Methods
actual_permitted_params()
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 222 def actual_permitted_params double_collection.calls_to(:permit).inject([]) do |all_param_names, call| all_param_names + call.args end.flatten end
default_verb()
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 250 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/strong_parameters_matcher.rb, line 240 def ensure_action_and_verb_present! if action.blank? raise ActionNotDefinedError end if verb.blank? raise VerbNotDefinedError end end
param_names_as_sentence()
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 257 def param_names_as_sentence expected_permitted_params.map(&:inspect).to_sentence end
permit_called?()
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 228 def permit_called? actual_permitted_params.any? end
set_double_collection()
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 214 def set_double_collection @double_collection = Doublespeak.double_collection_for(::ActionController::Parameters) @double_collection.register_stub(:require).to_return { |params| params } @double_collection.register_proxy(:permit) end
unpermitted_params()
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 232 def unpermitted_params expected_permitted_params - actual_permitted_params end
verified_permitted_params()
click to toggle source
# File lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb, line 236 def verified_permitted_params expected_permitted_params & actual_permitted_params end