Class: Shoulda::Matchers::ActionController::PermitMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/action_controller/permit_matcher.rb

Defined Under Namespace

Classes: ActionNotDefinedError, CompositeParametersDoubleRegistry, ParametersDoubleRegistry, VerbNotDefinedError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected_permitted_parameter_names) ⇒ PermitMatcher

Returns a new instance of PermitMatcher.



211
212
213
214
215
216
217
218
219
# 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

Instance Attribute Details

#stubbed_params=(value) ⇒ Object (writeonly)

Sets the attribute stubbed_params

Parameters:

  • value

    the value to set the attribute stubbed_params to.



209
210
211
# File 'lib/shoulda/matchers/action_controller/permit_matcher.rb', line 209

def stubbed_params=(value)
  @stubbed_params = value
end

Instance Method Details

#add_params(params) ⇒ Object



228
229
230
231
# File 'lib/shoulda/matchers/action_controller/permit_matcher.rb', line 228

def add_params(params)
  request_params.merge!(params)
  self
end

#descriptionObject



243
244
245
# File 'lib/shoulda/matchers/action_controller/permit_matcher.rb', line 243

def description
  "(for #{verb.upcase} ##{action}) " + expectation
end

#failure_messageObject



262
263
264
265
# File 'lib/shoulda/matchers/action_controller/permit_matcher.rb', line 262

def failure_message
  "Expected #{verb.upcase} ##{action} to #{expectation},"\
  "\nbut #{reality}."
end

#failure_message_when_negatedObject



267
268
269
270
# 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

#for(action, options = {}) ⇒ Object



221
222
223
224
225
226
# 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

#in_context(context) ⇒ Object



238
239
240
241
# File 'lib/shoulda/matchers/action_controller/permit_matcher.rb', line 238

def in_context(context)
  @context = context
  self
end

#matches?(controller) ⇒ Boolean

Returns:

  • (Boolean)


247
248
249
250
251
252
253
254
255
256
257
258
259
260
# 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

#on(subparameter_name) ⇒ Object



233
234
235
236
# File 'lib/shoulda/matchers/action_controller/permit_matcher.rb', line 233

def on(subparameter_name)
  @subparameter_name = subparameter_name
  self
end