Class: Dupe::Network::PostMock

Inherits:
Mock
  • Object
show all
Defined in:
lib/superdupe/mock.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Mock

#response, #url_pattern

Instance Method Summary collapse

Methods inherited from Mock

#initialize, #match?, #mocked_response

Constructor Details

This class inherits a constructor from Dupe::Network::Mock

Instance Method Details

#process_response(resp, url) ⇒ Object

returns a tuple representing the xml of the processed entity, plus the url to the entity.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/superdupe/mock.rb', line 72

def process_response(resp, url)
  case resp
    
    when NilClass
      raise StandardError, "Failed with 500: the request '#{url}' returned nil." 
    
    when Dupe::Database::Record
      new_path = "/#{resp.__model__.name.to_s.pluralize}/#{resp.id}.xml"
      resp = resp.to_xml_safe(:root => resp.demodulize)
      Dupe.network.log.add_request :post, url, resp
      return resp, new_path
    
    else
      raise StandardError, "Unknown PostMock Response. Your Post intercept mocks must return a Duped resource object or nil"
  end
end