Class AssertRequest::RequestRules
In: lib/request_rules.rb
Parent: Object

This is the class that is supplied as an argument to the block in an assert_request call. You use it to describe the request methods, parameters, and protocols that are permitted for this request.

Methods

method   params   protocol  

Public Instance methods

Used to describe the request methods that are permitted for this request. Takes a list of permitted request methods as symbols for its arguments. For example:

  assert_request do |r|
    r.method :put, :post
  end

This declaration says that the request method must be either PUT or POST.

If you don‘t include this call in your assert_request declaration, then assert_request will presume that only :get is allowed.

[Source]

    # File lib/request_rules.rb, line 32
32:     def method(*methods)
33:       @methods.allow(*methods)
34:     end

Used to describe the params hash for this request. Most commonly, the must_have, may_have, and must_not_have methods are chained on to this method to describe the params structure. For example:

  assert_request do |r|
    r.params.must_have :id
  end

For more details, see the methods that can be called on the result of this method:

[Source]

    # File lib/request_rules.rb, line 69
69:     def params
70:       @params
71:     end

Used to describe the protocols that are permitted for this request. Takes a list of permitted protocols as symbols for its arguments. For example:

  assert_request do |r|
    r.protocol :https
  end

This declaration says that the request protocol must be via HTTPS.

If you don‘t include this call in your assert_request declaration, then assert_request will presume that only :http is allowed.

[Source]

    # File lib/request_rules.rb, line 49
49:     def protocol(*protocols)
50:       @protocols.allow(*protocols)
51:     end

[Validate]