Class: CheckAuth::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_check_auth/check_auth/request.rb

Overview

Represents a single request spec

Format and Method should be a single symbol

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, format, opts) ⇒ Request

Returns a new instance of Request.



8
9
10
11
12
13
# File 'lib/rspec_check_auth/check_auth/request.rb', line 8

def initialize action, format, opts
  @action = action
  @format = format
  @method = opts[:method] || default_method
  self.params = opts.except(:method)
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



6
7
8
# File 'lib/rspec_check_auth/check_auth/request.rb', line 6

def action
  @action
end

#formatObject (readonly)

Returns the value of attribute format.



6
7
8
# File 'lib/rspec_check_auth/check_auth/request.rb', line 6

def format
  @format
end

#methodObject (readonly)

Returns the value of attribute method.



6
7
8
# File 'lib/rspec_check_auth/check_auth/request.rb', line 6

def method
  @method
end

#paramsObject

Returns the value of attribute params.



6
7
8
# File 'lib/rspec_check_auth/check_auth/request.rb', line 6

def params
  @params
end

Instance Method Details

#default_methodObject

Works out the default method for certain controller actions



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rspec_check_auth/check_auth/request.rb', line 32

def default_method
  case @action.to_s
  when /create/
    :post
  when /update/
    :put
  when /destroy/
    :delete
  else# and when /(index|show|new|edit)/
    :get
  end
end

#default_paramsObject

Adds an id for actions that require it



46
47
48
49
50
51
52
53
# File 'lib/rspec_check_auth/check_auth/request.rb', line 46

def default_params
  case @action.to_s
  when /(show|edit|update|destroy)/
    {:id => "some_id"}
  else
    {}
  end
end