Class: Pact::MockService::RequestHandlers::PactPost
- Inherits:
-
BaseAdministrationRequestHandler
- Object
- BaseRequestHandler
- BaseAdministrationRequestHandler
- Pact::MockService::RequestHandlers::PactPost
- Defined in:
- lib/pact/mock_service/request_handlers/pact_post.rb
Constant Summary
Constants inherited from BaseRequestHandler
BaseRequestHandler::NOT_FOUND_RESPONSE
Constants included from Consumer::RackRequestHelper
Consumer::RackRequestHelper::REQUEST_KEYS
Instance Attribute Summary collapse
-
#consumer_contract ⇒ Object
Returns the value of attribute consumer_contract.
-
#default_options ⇒ Object
Returns the value of attribute default_options.
-
#session ⇒ Object
Returns the value of attribute session.
-
#verified_interactions ⇒ Object
Returns the value of attribute verified_interactions.
Attributes inherited from BaseAdministrationRequestHandler
Instance Method Summary collapse
-
#initialize(name, logger, session) ⇒ PactPost
constructor
A new instance of PactPost.
- #request_method ⇒ Object
- #request_path ⇒ Object
- #respond(env) ⇒ Object
Methods inherited from BaseAdministrationRequestHandler
#has_mock_service_header?, #match?, #method_matches?, #path_matches?
Methods inherited from BaseRequestHandler
#call, #json_response, #match?, #text_response
Methods included from Consumer::RackRequestHelper
#params_hash, #request_as_hash_from
Constructor Details
#initialize(name, logger, session) ⇒ PactPost
Returns a new instance of PactPost.
11 12 13 14 15 16 17 |
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 11 def initialize name, logger, session super name, logger @verified_interactions = session.verified_interactions @default_options = {} @default_options.merge!(session.consumer_contract_details) @session = session end |
Instance Attribute Details
#consumer_contract ⇒ Object
Returns the value of attribute consumer_contract.
9 10 11 |
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 9 def consumer_contract @consumer_contract end |
#default_options ⇒ Object
Returns the value of attribute default_options.
9 10 11 |
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 9 def @default_options end |
#session ⇒ Object
Returns the value of attribute session.
9 10 11 |
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 9 def session @session end |
#verified_interactions ⇒ Object
Returns the value of attribute verified_interactions.
9 10 11 |
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 9 def verified_interactions @verified_interactions end |
Instance Method Details
#request_method ⇒ Object
23 24 25 |
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 23 def request_method 'POST' end |
#request_path ⇒ Object
19 20 21 |
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 19 def request_path '/pact' end |
#respond(env) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/pact/mock_service/request_handlers/pact_post.rb', line 27 def respond env body = env['rack.input'].string consumer_contract_details = body.size > 0 ? JSON.parse(body, symbolize_names: true) : {} consumer_contract_params = .merge(consumer_contract_details.merge(interactions: verified_interactions)) consumer_contract_writer = ConsumerContractWriter.new(consumer_contract_params, logger) session.record_pact_written json_response(consumer_contract_writer.write) end |