Class: OperationResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/angus/rspec/support/operation_response.rb

Overview

Wraps the response return from an operation invocation

Instance Method Summary collapse

Constructor Details

#initialize(rack_response) ⇒ OperationResponse

Returns a new instance of OperationResponse.



8
9
10
11
# File 'lib/angus/rspec/support/operation_response.rb', line 8

def initialize(rack_response)
  @rack_response = rack_response
  @parsed_response = JSON(rack_response.body)
end

Instance Method Details

#bodyObject



13
14
15
# File 'lib/angus/rspec/support/operation_response.rb', line 13

def body
  @parsed_response
end

#conflict?Boolean

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/angus/rspec/support/operation_response.rb', line 45

def conflict?
  @parsed_response['status'] == 'error' &&
    http_status_code == Angus::Responses::HTTP_STATUS_CODE_CONFLICT
end

#forbidden?Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/angus/rspec/support/operation_response.rb', line 35

def forbidden?
  @parsed_response['status'] == 'error' &&
    http_status_code == Angus::Responses::HTTP_STATUS_CODE_FORBIDDEN
end

#http_status_codeObject



55
56
57
# File 'lib/angus/rspec/support/operation_response.rb', line 55

def http_status_code
  @rack_response.status
end

#messagesObject



17
18
19
# File 'lib/angus/rspec/support/operation_response.rb', line 17

def messages
  @parsed_response['messages'] || []
end

#not_found?Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/angus/rspec/support/operation_response.rb', line 40

def not_found?
  @parsed_response['status'] == 'error' &&
    http_status_code == Angus::Responses::HTTP_STATUS_CODE_NOT_FOUND
end

#statusObject



59
60
61
# File 'lib/angus/rspec/support/operation_response.rb', line 59

def status
  @parsed_response['status']
end

#success?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/angus/rspec/support/operation_response.rb', line 25

def success?
  @parsed_response['status'] == 'success' &&
    http_status_code == Angus::Responses::HTTP_STATUS_CODE_OK
end

#unauthorized?Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/angus/rspec/support/operation_response.rb', line 30

def unauthorized?
  @parsed_response['status'] == 'error' &&
    http_status_code == Angus::Responses::HTTP_STATUS_CODE_UNAUTHORIZED
end

#unprocessable_entity?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/angus/rspec/support/operation_response.rb', line 50

def unprocessable_entity?
  @parsed_response['status'] == 'error' &&
    http_status_code == Angus::Responses::HTTP_STATUS_CODE_UNPROCESSABLE_ENTITY
end

#wraps?(rack_response) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/angus/rspec/support/operation_response.rb', line 21

def wraps?(rack_response)
  @rack_response == rack_response
end